Add new event pluginsInitialized and use it in converse-notifications

By listening for this event before registering event handlers, other plugins
can first get their overrides of those handlers applied.
This commit is contained in:
JC Brand 2016-06-16 17:21:11 +02:00
parent 73bf2f88ea
commit e12c165454
3 changed files with 24 additions and 5 deletions

View File

@ -912,6 +912,8 @@ Once converse.js has been initialized.
``converse.listen.on('initialized', function (event) { ... });``
See also `pluginsInitialized`_.
messageSend
~~~~~~~~~~~
@ -926,6 +928,17 @@ When keepalive=true but there aren't any stored prebind tokens.
``converse.listen.on('noResumeableSession', function (event) { ... });``
pluginsInitialized
~~~~~~~~~~~~~~~~~~
Once all plugins have been initialized. This is a useful event if you want to
register event handlers but would like your own handlers to be overridable by
plugins. In that case, you need to first wait until all plugins have been
initialized, so that their overrides are active. One example where this is used
is in [converse-notifications.js](https://github.com/jcbrand/converse.js/blob/master/src/converse-notification.js).
``converse.listen.on('pluginsInitialized', function (event) { ... });``
reconnected
~~~~~~~~~~~

View File

@ -1786,6 +1786,7 @@
'updateSettings': updateSettings,
'converse': converse
});
converse.emit('pluginsInitialized');
converse._initialize();
converse.registerGlobalEventHandlers();
return init_deferred.promise();

View File

@ -243,11 +243,16 @@
}
};
converse.on('contactRequest', converse.handleContactRequestNotification);
converse.on('contactStatusChanged', converse.handleChatStateNotification);
converse.on('message', converse.handleMessageNotification);
converse.on('feedback', converse.handleFeedback);
converse.on('connected', converse.requestPermission);
converse.on('pluginsInitialized', function () {
// We only register event handlers after all plugins are
// registered, because other plugins might override some of our
// handlers.
converse.on('contactRequest', converse.handleContactRequestNotification);
converse.on('contactStatusChanged', converse.handleChatStateNotification);
converse.on('message', converse.handleMessageNotification);
converse.on('feedback', converse.handleFeedback);
converse.on('connected', converse.requestPermission);
});
}
});
}));