added a comment - - edited
After more looking at this, there's some more basic stuff we need to do, sorry.
1) We need to support more types of messages, more than one per module. So I think we need to change the message_providers table to have:
id, name, component, capability
The capability lets us restrict display of certain message types to certain people (eg some will be for admins only), it'll be checked at system level. We can derive the proper string name from these the same way capabilities do (see get_capability_string), by looking in the component language file for a string derived from the name. eg look in forum.php for "message:posts" and "message:digests"
2) The use of events to register/unregister the providers has turned out to be a bad idea, since they are not really events. Also in the lib/db/install.php there is a hardcoded insert into the database which there should not be. So we need to remove those forum_install() type functions and the hardcoded data in lib/db, and instead we should move to using db/messages.php files, which look very similar to lib/db/access.php and lib/db/events.php files and work the same way. This way it'll be easy to add/remove message types at any time.
eg in lib/db/messages.php
$messages = array (
'moodle:system' => array (
'capability' => 'moodle/site:config'
),
'moodle:errors' => array (
'capability' => 'moodle/site:config'
)
);
and mod/forum/db/messages.php
$messages = array (
'mod/forum:posts' => array (),
'mod/forum:digests' => array()
);
This is the first version of changes I've made to create the new message system.