Commit 63a0c639 authored by JC Brand's avatar JC Brand

Fix bugs with moving events

parent f8977035
This diff is collapsed.
......@@ -32,11 +32,11 @@
it("is populated once we have registered a presence handler",
mock.initConverse(
{'_converse': ['emit']}, null, {},
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
spyOn(_converse.api, "trigger").and.callThrough();
const IQs = _converse.connection.IQ_stanzas;
await test_utils.waitUntil(() => _converse.api.trigger.calls.all().map(c => c.args[0]).includes('rosterGroupsFetched'));
const node = await test_utils.waitUntil(
() => _.filter(IQs, iq => iq.nodeTree.querySelector('iq query[xmlns="jabber:iq:roster"]')).pop());
expect(_converse.api.trigger.calls.all().map(c => c.args[0]).includes('rosterContactsFetched')).toBeFalsy();
......
......@@ -400,12 +400,6 @@ converse.plugins.add('converse-minimize', {
this.model.on("destroy", this.removeChat, this);
this.model.on("change:minimized", this.onChanged, this);
this.model.on('change:num_unread', this.updateUnreadMessagesCounter, this);
/**
* Triggered once the _converse.MinimizedChats instance has been * initialized
* @event _converse#minimizedChatsInitialized
* @example _converse.api.listen.on('minimizedChatsInitialized', () => { ... });
*/
_converse.api.trigger('minimizedChatsInitialized');
},
render () {
......@@ -533,6 +527,12 @@ converse.plugins.add('converse-minimize', {
_converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes
});
/**
* Triggered once the _converse.MinimizedChats instance has been * initialized
* @event _converse#minimizedChatsInitialized
* @example _converse.api.listen.on('minimizedChatsInitialized', () => { ... });
*/
_converse.api.trigger('minimizedChatsInitialized');
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
......
......@@ -177,12 +177,6 @@ converse.plugins.add('converse-roomslist', {
this.list_model.fetch();
this.render();
this.sortAndPositionAllItems();
/**
* Triggered once the _converse.RoomsListView has been created and initialized.
* @event _converse#roomsListInitialized
* @example _converse.api.listen.on('roomsListInitialized', status => { ... });
*/
_converse.api.trigger('roomsListInitialized');
},
render () {
......@@ -276,6 +270,12 @@ converse.plugins.add('converse-roomslist', {
model.browserStorage = new Backbone.BrowserStorage[storage](id);
_converse.rooms_list_view = new _converse.RoomsListView({'model': model});
/**
* Triggered once the _converse.RoomsListView has been created and initialized.
* @event _converse#roomsListInitialized
* @example _converse.api.listen.on('roomsListInitialized', status => { ... });
*/
_converse.api.trigger('roomsListInitialized');
};
_converse.api.listen.on('connected', async () => {
......
......@@ -824,14 +824,6 @@ converse.plugins.add('converse-rosterview', {
this.trigger('rosterContactsFetchedAndProcessed');
});
this.createRosterFilter();
_converse.rosterview.render();
/**
* Triggered once the _converse.RosterView instance has been created and initialized.
* @event _converse#rosterViewInitialized
* @example _converse.api.listen.on('rosterViewInitialized', () => { ... });
*/
_converse.api.trigger('rosterViewInitialized');
},
render () {
......@@ -1039,6 +1031,13 @@ converse.plugins.add('converse-rosterview', {
_converse.rosterview = new _converse.RosterView({
'model': _converse.rostergroups
});
_converse.rosterview.render();
/**
* Triggered once the _converse.RosterView instance has been created and initialized.
* @event _converse#rosterViewInitialized
* @example _converse.api.listen.on('rosterViewInitialized', () => { ... });
*/
_converse.api.trigger('rosterViewInitialized');
}
_converse.api.listen.on('rosterInitialized', initRoster);
_converse.api.listen.on('rosterReadyAfterReconnection', initRoster);
......
......@@ -761,16 +761,6 @@ converse.plugins.add('converse-chatboxes', {
return new _converse.ChatBox(attrs, options);
},
initialize () {
/**
* Triggered once the _converse.ChatBoxes collection has been initialized.
* @event _converse#chatBoxesInitialized
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.trigger('chatBoxesInitialized');
},
registerMessageHandler () {
_converse.connection.addHandler(stanza => {
this.onMessage(stanza);
......@@ -1048,7 +1038,16 @@ converse.plugins.add('converse-chatboxes', {
_converse.api.disco.own.features.add(Strophe.NS.OUTOFBAND);
});
_converse.api.listen.on('pluginsInitialized', () => (_converse.chatboxes = new _converse.ChatBoxes()));
_converse.api.listen.on('pluginsInitialized', () => {
_converse.chatboxes = new _converse.ChatBoxes();
/**
* Triggered once the _converse.ChatBoxes collection has been initialized.
* @event _converse#chatBoxesInitialized
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.trigger('chatBoxesInitialized');
});
_converse.api.listen.on('presencesInitialized', () => _converse.chatboxes.onConnected());
/************************ END Event Handlers ************************/
......
......@@ -359,6 +359,7 @@ function initPlugins() {
},
'_converse': _converse
}, whitelist, _converse.blacklisted_plugins);
/**
* Triggered 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
......@@ -1404,9 +1405,9 @@ _converse.api = {
*
* @method _converse.api.trigger
*/
'trigger' () {
'trigger' (name) {
/* Event emitter and promise resolver */
_converse.trigger.apply(this, arguments);
_converse.trigger.apply(_converse, arguments);
const promise = _converse.promises[name];
if (!_.isUndefined(promise)) {
promise.resolve();
......
......@@ -109,6 +109,7 @@ converse.plugins.add('converse-roster', {
* position roster groups.
* @event _converse#rosterGroupsFetched
* @example _converse.api.listen.on('rosterGroupsFetched', () => { ... });
* @example _converse.api.waitUntil('rosterGroupsFetched').then(() => { ... });
*/
_converse.api.trigger('rosterGroupsFetched');
await _converse.roster.fetchRosterContacts();
......
......@@ -41038,16 +41038,6 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
return new _converse.ChatBox(attrs, options);
},
initialize() {
/**
* Triggered once the _converse.ChatBoxes collection has been initialized.
* @event _converse#chatBoxesInitialized
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.trigger('chatBoxesInitialized');
},
registerMessageHandler() {
_converse.connection.addHandler(stanza => {
this.onMessage(stanza);
......@@ -41352,7 +41342,20 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
_converse.api.disco.own.features.add(Strophe.NS.OUTOFBAND);
});
_converse.api.listen.on('pluginsInitialized', () => _converse.chatboxes = new _converse.ChatBoxes());
_converse.api.listen.on('pluginsInitialized', () => {
_converse.chatboxes = new _converse.ChatBoxes();
_converse.emit('chatBoxesInitialized');
/**
* Triggered once the _converse.ChatBoxes collection has been initialized.
* @event _converse#chatBoxesInitialized
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.trigger('chatBoxesInitialized');
});
_converse.api.listen.on('presencesInitialized', () => _converse.chatboxes.onConnected());
/************************ END Event Handlers ************************/
......@@ -239,13 +239,11 @@
promise_names = null
settings = null;
}
return done => {
initConverse(settings, spies).then(_converse => {
const promises = _.map(promise_names, _converse.api.waitUntil);
Promise.all(promises)
.then(_.partial(func, done, _converse))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
});
return async done => {
const _converse = await initConverse(settings, spies);
const promises = _.map(promise_names, _converse.api.waitUntil);
await Promise.all(promises);
func(done, _converse);
}
};
return mock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment