Rename emit to trigger for consistency with Backbone.Events

This commit is contained in:
JC Brand 2019-03-29 21:10:45 +01:00
parent f6335dcabe
commit f897703565
36 changed files with 320 additions and 294 deletions

View File

@ -141,7 +141,7 @@ For example:
.. code-block:: javascript
_converse.api.emit('foo-completed');
_converse.api.trigger('foo-completed');
Additionally, if a promise has been registered under the same name
(via ``_converse.api.promises.add``), then that promise will also be resolved
@ -1152,7 +1152,7 @@ For example:
.. code-block:: javascript
_converse.api.emit('foo-completed');
_converse.api.trigger('foo-completed');
The **settings** grouping

View File

@ -446,7 +446,7 @@ generated by `generator-conversejs <https://github.com/jcbrand/generator-convers
* emit an event with the same name as the promise.
* For example:
*
* _converse.api.emit('operationCompleted');
* _converse.api.trigger('operationCompleted');
*
* Other plugins can then either listen for the event
* `operationCompleted` like so:

View File

@ -330,7 +330,7 @@
);
await test_utils.waitUntil(() => _converse.bookmarks);
// Emit here instead of mocking fetching of bookmarks.
_converse.emit('bookmarksInitialized');
_converse.api.trigger('bookmarksInitialized');
/* The stored data is automatically pushed to all of the user's
* connected resources.
@ -638,7 +638,7 @@
_converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks}
);
_converse.emit('bookmarksInitialized');
_converse.api.trigger('bookmarksInitialized');
// Check that it's there
_converse.bookmarks.create({

View File

@ -142,7 +142,7 @@
null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true},
async function (done, _converse) {
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
const stanza = u.toStanza(`
<message from="${sender_jid}"
@ -269,11 +269,11 @@
const view = await test_utils.openChatBoxFor(_converse, contact_jid);
const el = sizzle('a.open-chat:contains("'+view.model.getDisplayName()+'")', _converse.rosterview.el).pop();
const jid = el.textContent.replace(/ /g,'.').toLowerCase() + '@localhost';
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
el.click();
await test_utils.waitUntil(() => _converse.emit.calls.count(), 500);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count(), 500);
expect(_converse.chatboxes.length).toEqual(2);
expect(_converse.emit).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
done();
}));
@ -285,7 +285,7 @@
await test_utils.waitForRoster(_converse, 'current');
test_utils.openControlBox();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
spyOn(_converse.chatboxviews, 'trimChats');
test_utils.openControlBox();
@ -329,7 +329,7 @@
spyOn(chatview, 'close').and.callThrough();
spyOn(controlview, 'close').and.callThrough();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
// We need to rebind all events otherwise our spy won't be called
controlview.delegateEvents();
@ -338,13 +338,13 @@
controlview.el.querySelector('.close-chatbox-button').click();
expect(controlview.close).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.emit.calls.count(), 1);
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.api.trigger.calls.count(), 1);
chatview.el.querySelector('.close-chatbox-button').click();
expect(chatview.close).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.emit.calls.count(), 2);
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.api.trigger.calls.count(), 2);
done();
}));
@ -362,15 +362,15 @@
const trimmed_chatboxes = _converse.minimized_chats;
const chatview = _converse.chatboxviews.get(contact_jid);
spyOn(chatview, 'minimize').and.callThrough();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
// We need to rebind all events otherwise our spy won't be called
chatview.delegateEvents();
chatview.el.querySelector('.toggle-chatbox-button').click();
expect(chatview.minimize).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
expect(_converse.emit.calls.count(), 2);
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
expect(_converse.api.trigger.calls.count(), 2);
expect(u.isVisible(chatview.el)).toBeFalsy();
expect(chatview.model.get('minimized')).toBeTruthy();
chatview.el.querySelector('.toggle-chatbox-button').click();
@ -380,7 +380,7 @@
trimmedview.el.querySelector("a.restore-chat").click();
expect(trimmedview.restore).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
await test_utils.waitUntil(() => u.isVisible(chatview.el.querySelector('.chat-body')), 500);
const toggle_el = sizzle('.toggle-chatbox-button', chatview.el).pop();
expect(u.hasClass('fa-minus', toggle_el)).toBeTruthy();
@ -397,25 +397,25 @@
await test_utils.waitForRoster(_converse, 'current');
test_utils.openControlBox();
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
spyOn(_converse.chatboxviews, 'trimChats');
_converse.chatboxes.browserStorage._clear();
test_utils.closeControlBox();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.chatboxes.length).toEqual(1);
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
test_utils.openChatBoxes(_converse, 6);
await test_utils.waitUntil(() => _converse.chatboxes.length == 7)
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
expect(_converse.chatboxes.length).toEqual(7);
expect(_converse.emit).toHaveBeenCalledWith('chatBoxOpened', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxOpened', jasmine.any(Object));
test_utils.closeAllChatBoxes(_converse);
expect(_converse.chatboxes.length).toEqual(1);
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
var newchatboxes = new _converse.ChatBoxes();
expect(newchatboxes.length).toEqual(0);
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
@ -489,7 +489,7 @@
let toolbar, call_button;
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
// First check that the button doesn't show if it's not enabled
// via "visible_toolbar_buttons"
_converse.visible_toolbar_buttons.call = false;
@ -507,7 +507,7 @@
toolbar = view.el.querySelector('ul.chat-toolbar');
call_button = toolbar.querySelector('.toggle-call');
call_button.click();
expect(_converse.emit).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
done();
}));
});
@ -554,7 +554,7 @@
await test_utils.waitForRoster(_converse, 'current');
test_utils.openControlBox();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
// <composing> state
const msg = $msg({
@ -564,7 +564,7 @@
'id': (new Date()).getTime()
}).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
await _converse.chatboxes.onMessage(msg);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.chats.get().length).toBe(1);
done();
}));
@ -641,7 +641,7 @@
var view = _converse.chatboxviews.get(contact_jid);
expect(view.model.get('chat_state')).toBe('active');
spyOn(_converse.connection, 'send');
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
view.keyPressed({
target: view.el.querySelector('textarea.chat-textarea'),
keyCode: 1
@ -662,7 +662,7 @@
keyCode: 1
});
expect(view.model.get('chat_state')).toBe('composing');
expect(_converse.emit.calls.count(), 1);
expect(_converse.api.trigger.calls.count(), 1);
done();
}));
@ -675,7 +675,7 @@
test_utils.openControlBox();
// See XEP-0085 https://xmpp.org/extensions/xep-0085.html#definitions
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
await test_utils.openChatBoxFor(_converse, sender_jid);
@ -688,7 +688,7 @@
id: (new Date()).getTime()
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
await _converse.chatboxes.onMessage(msg);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
var view = _converse.chatboxviews.get(sender_jid);
expect(view).toBeDefined();
@ -821,7 +821,7 @@
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
// TODO: only show paused state if the previous state was composing
// See XEP-0085 https://xmpp.org/extensions/xep-0085.html#definitions
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
const view = await test_utils.openChatBoxFor(_converse, sender_jid);
// <paused> state
@ -832,7 +832,7 @@
id: (new Date()).getTime()
}).c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
await _converse.chatboxes.onMessage(msg);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
await test_utils.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1])
var event = view.el.querySelector('.chat-info.chat-state-notification');
expect(event.textContent).toEqual(mock.cur_names[1] + ' has stopped typing');
@ -990,7 +990,7 @@
test_utils.openControlBox();
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
// See XEP-0085 https://xmpp.org/extensions/xep-0085.html#definitions
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
await test_utils.openChatBoxFor(_converse, sender_jid);
const view = _converse.chatboxviews.get(sender_jid);
expect(view.el.querySelectorAll('.chat-event').length).toBe(0);
@ -1015,7 +1015,7 @@
}).c('body').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
await _converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => (view.model.messages.length > 1));
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(0);
done();
}));
@ -1031,7 +1031,7 @@
await test_utils.waitForRoster(_converse, 'current', 3);
test_utils.openControlBox();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
// <paused> state
const msg = $msg({
@ -1041,7 +1041,7 @@
id: (new Date()).getTime()
}).c('body').c('gone', {'xmlns': Strophe.NS.CHATSTATES}).tree();
await _converse.chatboxes.onMessage(msg);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
const view = _converse.chatboxviews.get(sender_jid);
await test_utils.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1]);
const event = view.el.querySelector('.chat-state-notification');
@ -1063,7 +1063,7 @@
test_utils.openControlBox();
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
await test_utils.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
let message = 'This message is another sent from this chatbox';
@ -1088,8 +1088,8 @@
expect(window.confirm).toHaveBeenCalled();
expect(view.model.messages.length, 0); // The messages must be removed from the chatbox
expect(view.model.messages.browserStorage.records.length, 0); // And also from browserStorage
expect(_converse.emit.calls.count(), 1);
expect(_converse.emit.calls.mostRecent().args, ['messageSend', message]);
expect(_converse.api.trigger.calls.count(), 1);
expect(_converse.api.trigger.calls.mostRecent().args, ['messageSend', message]);
done();
}));
});
@ -1121,7 +1121,7 @@
.c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
_converse.windowState = 'hidden';
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
spyOn(_converse, 'incrementMsgCounter').and.callThrough();
spyOn(_converse, 'clearMsgCounter').and.callThrough();
@ -1130,7 +1130,7 @@
expect(_converse.incrementMsgCounter).toHaveBeenCalled();
expect(_converse.clearMsgCounter).not.toHaveBeenCalled();
expect(_converse.msg_counter).toBe(1);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
_converse.windowSate = previous_state;
done();
}));

View File

@ -23,13 +23,13 @@
expect(u.isVisible(el)).toBe(false);
spyOn(_converse.controlboxtoggle, 'onClick').and.callThrough();
spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
_converse.controlboxtoggle.delegateEvents();
document.querySelector('.toggle-controlbox').click();
expect(_converse.controlboxtoggle.onClick).toHaveBeenCalled();
expect(_converse.controlboxtoggle.showControlBox).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
el = document.querySelector("div#controlbox");
expect(u.isVisible(el)).toBe(true);
done();
@ -42,7 +42,7 @@
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
spyOn(_converse.rosterview, 'update').and.callThrough();
test_utils.openControlBox();
// Adding two contacts one with Capital initials and one with small initials of same JID (Case sensitive check)
@ -71,7 +71,7 @@
async function (done, _converse) {
test_utils.createContacts(_converse, 'all').openControlBox();
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, sender_jid);
@ -140,11 +140,11 @@
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
const view = _converse.xmppstatusview;
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
modal.el.querySelector('[type="submit"]').click();
expect(_converse.emit).toHaveBeenCalledWith('statusChanged', 'dnd');
expect(_converse.api.trigger).toHaveBeenCalledWith('statusChanged', 'dnd');
const first_child = view.el.querySelector('.xmpp-status span:first-child');
expect(u.hasClass('online', first_child)).toBe(false);
expect(u.hasClass('dnd', first_child)).toBe(true);
@ -165,13 +165,13 @@
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
const view = _converse.xmppstatusview;
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const msg = 'I am happy';
modal.el.querySelector('input[name="status_message"]').value = msg;
modal.el.querySelector('[type="submit"]').click();
expect(_converse.emit).toHaveBeenCalledWith('statusMessageChanged', msg);
expect(_converse.api.trigger).toHaveBeenCalledWith('statusMessageChanged', msg);
const first_child = view.el.querySelector('.xmpp-status span:first-child');
expect(u.hasClass('online', first_child)).toBe(true);
expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe(msg);

View File

@ -288,7 +288,7 @@
test_utils.openControlBox();
test_utils.createContacts(_converse, 'current', 2);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
// Test on chat that doesn't exist.
expect(_converse.api.chats.get('non-existing@jabber.org')).toBeFalsy();
@ -325,7 +325,7 @@
test_utils.openControlBox();
test_utils.createContacts(_converse, 'current', 2);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
const jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';

View File

@ -187,11 +187,11 @@
null, ['discoInitialized'], {},
function (done, _converse) {
sinon.spy(_converse, 'emit');
sinon.spy(_converse.api, "trigger");
_converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM});
expect(_converse.emit.called).toBe(true);
expect(_converse.emit.args[0][0]).toBe('serviceDiscovered');
expect(_converse.emit.args[0][1].get('var')).toBe(Strophe.NS.MAM);
expect(_converse.api.trigger.called).toBe(true);
expect(_converse.api.trigger.args[0][0]).toBe('serviceDiscovered');
expect(_converse.api.trigger.args[0][1].get('var')).toBe(Strophe.NS.MAM);
done();
}));
});

View File

@ -8,11 +8,11 @@
this.callback = function () {};
spyOn(this, 'callback');
_converse.on('connected', this.callback);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback).toHaveBeenCalled();
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback.calls.count(), 2);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback.calls.count(), 3);
done();
}));
@ -21,11 +21,11 @@
this.callback = function () {};
spyOn(this, 'callback');
_converse.once('connected', this.callback);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback).toHaveBeenCalled();
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback.calls.count(), 1);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback.calls.count(), 1);
done();
}));
@ -41,20 +41,20 @@
_converse.on('connected', this.callback);
_converse.on('connected', this.anotherCallback);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback).toHaveBeenCalled();
expect(this.anotherCallback).toHaveBeenCalled();
_converse.off('connected', this.callback);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback.calls.count(), 1);
expect(this.anotherCallback.calls.count(), 2);
_converse.once('connected', this.neverCalled);
_converse.off('connected', this.neverCalled);
_converse.emit('connected');
_converse.api.trigger('connected');
expect(this.callback.calls.count(), 1);
expect(this.anotherCallback.calls.count(), 3);
expect(this.neverCalled).not.toHaveBeenCalled();

View File

@ -221,7 +221,7 @@
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.localhost'], 'items')
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.localhost', [], [Strophe.NS.HTTPUPLOAD], []);
test_utils.createContacts(_converse, 'current', 3);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
@ -263,7 +263,7 @@
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.tld'], 'items');
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.tld', [], [Strophe.NS.HTTPUPLOAD], []);
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
@ -555,7 +555,7 @@
expect(entities.get('localhost').items.get('upload.localhost').identities.where({'category': 'store'}).length).toBe(1);
const result = await _converse.api.disco.supports(Strophe.NS.HTTPUPLOAD, _converse.domain);
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid);
@ -594,7 +594,7 @@
await test_utils.waitUntilDiscoConfirmed(_converse, _converse.domain, [], [], ['upload.montague.tld'], 'items');
await test_utils.waitUntilDiscoConfirmed(_converse, 'upload.montague.tld', [], [Strophe.NS.HTTPUPLOAD], []);
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);

View File

@ -654,7 +654,7 @@
const contact_name = mock.cur_names[0];
const contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openControlBox();
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
await test_utils.openChatBoxFor(_converse, contact_jid);
@ -675,7 +675,7 @@
await _converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => chatview.model.messages.length);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
const trimmed_chatboxes = _converse.minimized_chats;
const trimmedview = trimmed_chatboxes.get(contact_jid);
let count = trimmedview.el.querySelector('.message-count');
@ -712,7 +712,7 @@
const include_nick = false;
await test_utils.waitForRoster(_converse, 'current', 2, include_nick);
test_utils.openControlBox();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const contact_name = mock.cur_names[1];
const contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
@ -736,7 +736,7 @@
await _converse.chatboxes.onMessage(msg);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(chatbox.messages.length).toEqual(1);
let msg_obj = chatbox.messages.models[0];
expect(msg_obj.get('message')).toEqual(message);
@ -769,7 +769,7 @@
await _converse.chatboxes.onMessage(msg);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
// Check that there is a <time> element, with the required
// props.
expect(chat_content.querySelectorAll('time.separator-text').length).toEqual(2); // There are now two time elements
@ -806,17 +806,17 @@
await test_utils.waitForRoster(_converse, 'current');
test_utils.openControlBox();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid)
expect(_converse.emit).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
const view = _converse.chatboxviews.get(contact_jid);
const message = 'This message is sent from this chatbox';
spyOn(view.model, 'sendMessage').and.callThrough();
await test_utils.sendMessage(view, message);
expect(view.model.sendMessage).toHaveBeenCalled();
expect(view.model.messages.length, 2);
expect(_converse.emit.calls.mostRecent().args, ['messageSend', message]);
expect(_converse.api.trigger.calls.mostRecent().args, ['messageSend', message]);
expect(sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop().textContent).toEqual(message);
done();
}));
@ -1383,7 +1383,7 @@
await test_utils.waitForRoster(_converse, 'current', 1, include_nick);
test_utils.openControlBox();
await test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 300);
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
const message = 'This is a received message';
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
// We don't already have an open chatbox for this user
@ -1403,7 +1403,7 @@
const view = _converse.api.chatviews.get(sender_jid);
expect(view).toBeDefined();
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
// Check that the message was received and check the message parameters
expect(chatbox.messages.length).toEqual(1);
const msg_obj = chatbox.messages.models[0];
@ -1487,9 +1487,9 @@
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
_converse.allow_non_roster_messaging = true;
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
var vcard_fetched = false;
@ -1515,7 +1515,7 @@
await _converse.chatboxes.onMessage(msg);
await test_utils.waitUntil(() => _converse.api.chats.get().length);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
// Check that the chatbox and its view now exist
const chatbox = _converse.chatboxes.get(sender_jid);
@ -1547,9 +1547,9 @@
async function (done, _converse) {
_converse.allow_non_roster_messaging = false;
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const message = 'This is a received message from someone not on the roster';
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
const msg = $msg({
@ -1576,7 +1576,7 @@
await _converse.chatboxes.onMessage(msg);
view = _converse.chatboxviews.get(sender_jid);
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
// Check that the chatbox and its view now exist
chatbox = _converse.chatboxes.get(sender_jid);
expect(chatbox).toBeDefined();
@ -2096,7 +2096,7 @@
null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true},
async function (done, _converse) {
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = 'someone@localhost';
const msgid = u.getUniqueId();
const stanza = u.toStanza(`
@ -2167,9 +2167,9 @@
</forwarded>
</sent>
</message>`);
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 1);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count() === 1);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.model.messages.length).toBe(1);
done();
@ -2563,12 +2563,12 @@
<received xmlns="urn:xmpp:receipts" id="${msg_obj.get('msgid')}"/>
<origin-id xmlns="urn:xmpp:sid:0" id="CE08D448-5ED8-4B6A-BB5B-07ED9DFE4FF0"/>
</message>`);
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 1);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count() === 1);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
done();
}));
@ -2596,12 +2596,12 @@
from="lounge@localhost/some1" type="groupchat" xmlns="jabber:client">
<received xmlns="urn:xmpp:chat-markers:0" id="${msg_obj.get('msgid')}"/>
</message>`);
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 1);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count() === 1);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
@ -2609,10 +2609,10 @@
<displayed xmlns="urn:xmpp:chat-markers:0" id="${msg_obj.get('msgid')}"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 2);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count() === 2);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
@ -2620,10 +2620,10 @@
<acknowledged xmlns="urn:xmpp:chat-markers:0" id="${msg_obj.get('msgid')}"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 3);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count() === 3);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
stanza = u.toStanza(`
<message xml:lang="en" to="dummy@localhost/resource"
@ -2632,10 +2632,10 @@
<markable xmlns="urn:xmpp:chat-markers:0"/>
</message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => _converse.emit.calls.count() === 5);
await test_utils.waitUntil(() => _converse.api.trigger.calls.count() === 5);
expect(view.el.querySelectorAll('.chat-msg').length).toBe(2);
expect(view.el.querySelectorAll('.chat-msg__receipt').length).toBe(0);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
done();
}));

View File

@ -14,7 +14,7 @@
function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
test_utils.openControlBox();
_converse.minimized_chats.toggleview.model.browserStorage._clear();
@ -53,7 +53,7 @@
function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
test_utils.openControlBox();
_converse.minimized_chats.toggleview.model.browserStorage._clear();
@ -84,7 +84,7 @@
function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
test_utils.openControlBox();
_converse.minimized_chats.toggleview.model.browserStorage._clear();

View File

@ -1718,7 +1718,7 @@
test_utils.createContacts(_converse, 'current'); // We need roster contacts, so that we have someone to invite
// Since we don't actually fetch roster contacts, we need to
// cheat here and emit the event.
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const features = [
'http://jabber.org/protocol/muc',
@ -1731,7 +1731,7 @@
'muc_anonymous'
]
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy', features);
spyOn(_converse, 'emit').and.callThrough();
spyOn(_converse.api, "trigger").and.callThrough();
spyOn(window, 'prompt').and.callFake(() => "Please join!");
const view = _converse.chatboxviews.get('lounge@localhost');
const chat_area = view.el.querySelector('.chat-area');
@ -1819,7 +1819,7 @@
const text = 'This is a received message';
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const view = _converse.chatboxviews.get('lounge@localhost');
if (!view.el.querySelectorAll('.chat-area').length) {
view.renderChatArea();
@ -1841,7 +1841,7 @@
const chat_content = view.el.querySelector('.chat-content');
expect(chat_content.querySelectorAll('.chat-msg').length).toBe(1);
expect(chat_content.querySelector('.chat-msg__text').textContent).toBe(text);
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
done();
}));
@ -1851,7 +1851,7 @@
async function (done, _converse) {
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
const view = _converse.chatboxviews.get('lounge@localhost');
if (!view.el.querySelectorAll('.chat-area').length) {
view.renderChatArea();
@ -1866,7 +1866,7 @@
});
await new Promise((resolve, reject) => view.once('messageInserted', resolve));
expect(_converse.emit).toHaveBeenCalledWith('messageSend', text);
expect(_converse.api.trigger).toHaveBeenCalledWith('messageSend', text);
const chat_content = view.el.querySelector('.chat-content');
expect(chat_content.querySelectorAll('.chat-msg').length).toBe(1);
@ -1888,7 +1888,7 @@
expect(sizzle('.chat-msg__text:last').pop().textContent).toBe(text);
expect(view.model.messages.length).toBe(1);
// We don't emit an event if it's our own message
expect(_converse.emit.calls.count(), 1);
expect(_converse.api.trigger.calls.count(), 1);
done();
}));
@ -2505,12 +2505,12 @@
spyOn(view, 'minimize').and.callThrough();
spyOn(view, 'maximize').and.callThrough();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
view.el.querySelector('.toggle-chatbox-button').click();
expect(view.minimize).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
expect(u.isVisible(view.el)).toBeFalsy();
expect(view.model.get('minimized')).toBeTruthy();
expect(view.minimize).toHaveBeenCalled();
@ -2518,9 +2518,9 @@
const trimmedview = trimmed_chatboxes.get(view.model.get('id'));
trimmedview.el.querySelector("a.restore-chat").click();
expect(view.maximize).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
expect(view.model.get('minimized')).toBeFalsy();
expect(_converse.emit.calls.count(), 3);
expect(_converse.api.trigger.calls.count(), 3);
done();
}));
@ -2533,13 +2533,13 @@
await test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
const view = _converse.chatboxviews.get('lounge@localhost');
spyOn(view, 'close').and.callThrough();
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
spyOn(view.model, 'leave');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
view.el.querySelector('.close-chatbox-button').click();
expect(view.close).toHaveBeenCalled();
expect(view.model.leave).toHaveBeenCalled();
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
done();
}));
});
@ -3422,12 +3422,12 @@
'from': view.model.get('jid'),
'to': _converse.connection.jid
});
spyOn(_converse, 'emit');
spyOn(_converse.api, "trigger");
expect(_converse.chatboxes.length).toBe(2);
_converse.connection._dataRecv(test_utils.createRequest(result_stanza));
await test_utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.DISCONNECTED));
expect(_converse.chatboxes.length).toBe(1);
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
done();
}));
});

View File

@ -156,7 +156,7 @@
it("an HTML5 Notification is received", mock.initConverse((done, _converse) => {
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'showContactRequestNotification');
_converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
_converse.api.trigger('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showContactRequestNotification).toHaveBeenCalled();
done();

View File

@ -82,7 +82,7 @@
const message = 'This message will be encrypted'
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
const view = await test_utils.openChatBoxFor(_converse, contact_jid);
const payload = await view.model.encryptMessage(message);
@ -99,7 +99,7 @@
let sent_stanza;
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.waitUntil(() => initializedOMEMO(_converse));
await test_utils.openChatBoxFor(_converse, contact_jid);
@ -513,7 +513,7 @@
_converse.NUM_PREKEYS = 5; // Restrict to 5, otherwise the resulting stanza is too large to easily test
let view, sent_stanza;
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.waitUntil(() => initializedOMEMO(_converse));
@ -934,7 +934,7 @@
_converse.NUM_PREKEYS = 2; // Restrict to 2, otherwise the resulting stanza is too large to easily test
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
let stanza = $iq({
@ -1011,7 +1011,7 @@
);
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
@ -1358,11 +1358,11 @@
);
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid)
// We simply emit, to avoid doing all the setup work
_converse.emit('OMEMOInitialized');
_converse.api.trigger('OMEMOInitialized');
const view = _converse.chatboxviews.get(contact_jid);
const show_modal_button = view.el.querySelector('.show-user-details-modal');

View File

@ -13,7 +13,7 @@
spyOn(_converse, 'registerPingHandler').and.callThrough();
spyOn(_converse, 'registerPongHandler').and.callThrough();
_converse.emit('connected');
_converse.api.trigger('connected');
expect(_converse.registerPingHandler).toHaveBeenCalled();
expect(_converse.registerPongHandler).toHaveBeenCalled();
done();
@ -26,7 +26,7 @@
spyOn(_converse, 'registerPingHandler').and.callThrough();
spyOn(_converse, 'registerPongHandler').and.callThrough();
_converse.emit('reconnected');
_converse.api.trigger('reconnected');
expect(_converse.registerPingHandler).toHaveBeenCalled();
expect(_converse.registerPongHandler).toHaveBeenCalled();
done();

View File

@ -517,7 +517,7 @@
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
spyOn(_converse, "emit");
spyOn(_converse.api, "trigger");
test_utils.openControlBox(_converse);
test_utils.createContacts(_converse, 'current'); // Create some contacts so that we can test positioning
/* <presence
@ -538,7 +538,7 @@
var $contacts = $header.parent().find('li:visible');
return $contacts.length;
}, 600).then(function () {
expect(_converse.emit).toHaveBeenCalledWith('contactRequest', jasmine.any(Object));
expect(_converse.api.trigger).toHaveBeenCalledWith('contactRequest', jasmine.any(Object));
var $header = $('a:contains("Contact requests")');
expect($header.length).toBe(1);
expect($header.is(":visible")).toBeTruthy();

View File

@ -36,10 +36,10 @@
async function (done, _converse) {
const IQs = _converse.connection.IQ_stanzas;
await test_utils.waitUntil(() => _converse.emit.calls.all().map(c => c.args[0]).includes('rosterGroupsFetched'));
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.emit.calls.all().map(c => c.args[0]).includes('rosterContactsFetched')).toBeFalsy();
expect(_converse.api.trigger.calls.all().map(c => c.args[0]).includes('rosterContactsFetched')).toBeFalsy();
expect(node.toLocaleString()).toBe(
`<iq id="${node.nodeTree.getAttribute('id')}" type="get" xmlns="jabber:client">`+
@ -54,7 +54,7 @@
}).c('item', {'jid': 'nurse@example.com'}).up()
.c('item', {'jid': 'romeo@example.com'})
_converse.connection._dataRecv(test_utils.createRequest(result));
await test_utils.waitUntil(() => _converse.emit.calls.all().map(c => c.args[0]).includes('rosterContactsFetched'));
await test_utils.waitUntil(() => _converse.api.trigger.calls.all().map(c => c.args[0]).includes('rosterContactsFetched'));
done();
}));

View File

@ -20,7 +20,7 @@
async function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid);
@ -54,7 +54,7 @@
async function (done, _converse) {
test_utils.createContacts(_converse, 'current');
_converse.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.openChatBoxFor(_converse, contact_jid)

View File

@ -555,7 +555,7 @@ converse.plugins.add('converse-bookmarks', {
* @event _converse#bookmarksInitialized
* @example _converse.api.listen.on('bookmarksInitialized', () => { ... });
*/
_converse.api.emit('bookmarksInitialized');
_converse.api.trigger('bookmarksInitialized');
}
_converse.api.listen.on('clearSession', () => {

View File

@ -173,7 +173,7 @@ converse.plugins.add('converse-chatboxviews', {
* @event _converse#chatBoxViewsInitialized
* @example _converse.api.listen.on('chatBoxViewsInitialized', () => { ... });
*/
_converse.api.emit('chatBoxViewsInitialized');
_converse.api.trigger('chatBoxViewsInitialized');
});
_converse.api.listen.on('clearSession', () => _converse.chatboxviews.closeAllChatBoxes());

View File

@ -188,7 +188,7 @@ converse.plugins.add('converse-chatview', {
* @property { string } message - The message text
* @example _converse.api.listen.on('contactStatusMessageChanged', obj => { ... });
*/
_converse.api.emit('contactStatusMessageChanged', {
_converse.api.trigger('contactStatusMessageChanged', {
'contact': item.attributes,
'message': item.get('status')
});
@ -215,7 +215,7 @@ converse.plugins.add('converse-chatview', {
* @type { _converse.ChatBox }
* @example _converse.api.listen.on('userDetailsModalInitialized', chatbox => { ... });
*/
_converse.api.emit('userDetailsModalInitialized', this.model);
_converse.api.trigger('userDetailsModalInitialized', this.model);
},
toHTML () {
@ -336,14 +336,14 @@ converse.plugins.add('converse-chatview', {
this.render();
this.fetchMessages();
_converse.api.emit('chatBoxOpened', this); // TODO: remove
_converse.api.trigger('chatBoxOpened', this); // TODO: remove
/**
* Triggered once the _converse.ChatBoxView has been initialized
* @event _converse#chatBoxInitialized
* @type { _converse.ChatBoxView | _converse.HeadlinesBoxView }
* @example _converse.api.listen.on('chatBoxInitialized', view => { ... });
*/
_converse.api.emit('chatBoxInitialized', this);
_converse.api.trigger('chatBoxInitialized', this);
},
initDebounced () {
@ -384,7 +384,7 @@ converse.plugins.add('converse-chatview', {
* @type { _converse.ChatBoxView }
* @example _converse.api.listen.on('renderToolbar', view => { ... });
*/
_converse.api.emit('renderToolbar', this);
_converse.api.trigger('renderToolbar', this);
return this;
},
@ -525,7 +525,7 @@ converse.plugins.add('converse-chatview', {
* @type {_converse.ChatBoxView | _converse.ChatRoomView}
* @example _converse.api.listen.on('afterMessagesFetched', view => { ... });
*/
_converse.api.emit('afterMessagesFetched', this);
_converse.api.trigger('afterMessagesFetched', this);
},
fetchMessages () {
@ -840,7 +840,7 @@ converse.plugins.add('converse-chatview', {
* @property { _converse.ChatBox | _converse.ChatRoom } chatbox - The chat model
* @example _converse.api.listen.on('messageAdded', data => { ... });
*/
_converse.api.emit('messageAdded', {
_converse.api.trigger('messageAdded', {
'message': message,
'chatbox': this.model
});
@ -932,7 +932,7 @@ converse.plugins.add('converse-chatview', {
* @type { _converse.Message }
* @example _converse.api.listen.on('messageSend', data => { ... });
*/
_converse.api.emit('messageSend', message);
_converse.api.trigger('messageSend', message);
}
textarea.removeAttribute('disabled');
u.removeClass('disabled', textarea);
@ -1143,7 +1143,7 @@ converse.plugins.add('converse-chatview', {
* @property { _converse.ChatBox | _converse.ChatRoom } _converse.connection - The XMPP Connection object
* @example _converse.api.listen.on('callButtonClicked', (connection, model) => { ... });
*/
_converse.api.emit('callButtonClicked', {
_converse.api.trigger('callButtonClicked', {
connection: _converse.connection,
model: this.model
});
@ -1230,7 +1230,7 @@ converse.plugins.add('converse-chatview', {
* @type { _converse.ChatBoxView | _converse.ChatRoomView }
* @example _converse.api.listen.on('chatBoxClosed', view => { ... });
*/
_converse.api.emit('chatBoxClosed', this);
_converse.api.trigger('chatBoxClosed', this);
return this;
},
@ -1256,7 +1256,7 @@ converse.plugins.add('converse-chatview', {
* @type { _converse.ChatBoxView | _converse.ChatRoomView }
* @example _converse.api.listen.on('chatBoxFocused', view => { ... });
*/
_converse.api.emit('chatBoxFocused', this);
_converse.api.trigger('chatBoxFocused', this);
}
return this;
},
@ -1346,7 +1346,7 @@ converse.plugins.add('converse-chatview', {
* @property { _converse.ChatBox | _converse.ChatRoom } chatbox - The chat model
* @example _converse.api.listen.on('chatBoxScrolledDown', obj => { ... });
*/
_converse.api.emit('chatBoxScrolledDown', {'chatbox': this.model}); // TODO: clean up
_converse.api.trigger('chatBoxScrolledDown', {'chatbox': this.model}); // TODO: clean up
},
onWindowStateChanged (state) {

View File

@ -232,7 +232,7 @@ converse.plugins.add('converse-controlbox', {
* @type { _converse.ControlBoxView }
* @example _converse.api.listen.on('controlboxInitialized', view => { ... });
*/
_converse.api.emit('controlboxInitialized', this);
_converse.api.trigger('controlboxInitialized', this);
},
render () {
@ -339,7 +339,7 @@ converse.plugins.add('converse-controlbox', {
} else {
this.model.trigger('hide');
}
_converse.api.emit('controlBoxClosed', this);
_converse.api.trigger('controlBoxClosed', this);
return this;
},
@ -356,7 +356,7 @@ converse.plugins.add('converse-controlbox', {
return;
}
u.addClass('hidden', this.el);
_converse.api.emit('chatBoxClosed', this);
_converse.api.trigger('chatBoxClosed', this);
if (!_converse.connection.connected) {
_converse.controlboxtoggle.render();
}
@ -367,7 +367,7 @@ converse.plugins.add('converse-controlbox', {
onControlBoxToggleHidden () {
this.model.set('closed', false);
this.el.classList.remove('hidden');
_converse.api.emit('controlBoxOpened', this);
_converse.api.trigger('controlBoxOpened', this);
},
show () {

View File

@ -81,8 +81,8 @@ converse.plugins.add('converse-headline', {
this.model.on('change:minimized', this.onMinimizedChanged, this);
this.render().insertHeading().fetchMessages().insertIntoDOM().hide();
_converse.api.emit('chatBoxOpened', this); // TODO: remove
_converse.api.emit('chatBoxInitialized', this);
_converse.api.trigger('chatBoxOpened', this); // TODO: remove
_converse.api.trigger('chatBoxInitialized', this);
},
render () {
@ -127,7 +127,7 @@ converse.plugins.add('converse-headline', {
});
const attrs = await chatbox.getMessageAttributesFromStanza(message, message);
await chatbox.messages.create(attrs);
_converse.api.emit('message', {'chatbox': chatbox, 'stanza': message});
_converse.api.trigger('message', {'chatbox': chatbox, 'stanza': message});
}
}

View File

@ -137,7 +137,7 @@ converse.plugins.add('converse-minimize', {
* @type { _converse.ChatBoxView }
* @example _converse.api.listen.on('chatBoxMaximized', view => { ... });
*/
_converse.api.emit('chatBoxMaximized', this);
_converse.api.trigger('chatBoxMaximized', this);
return this;
},
@ -158,7 +158,7 @@ converse.plugins.add('converse-minimize', {
* @type { _converse.ChatBoxView }
* @example _converse.api.listen.on('chatBoxMinimized', view => { ... });
*/
_converse.api.emit('chatBoxMinimized', this);
_converse.api.trigger('chatBoxMinimized', this);
},
},
@ -370,7 +370,7 @@ converse.plugins.add('converse-minimize', {
view.close();
} else {
this.model.destroy();
_converse.api.emit('chatBoxClosed', this);
_converse.api.trigger('chatBoxClosed', this);
}
return this;
},
@ -405,7 +405,7 @@ converse.plugins.add('converse-minimize', {
* @event _converse#minimizedChatsInitialized
* @example _converse.api.listen.on('minimizedChatsInitialized', () => { ... });
*/
_converse.api.emit('minimizedChatsInitialized');
_converse.api.trigger('minimizedChatsInitialized');
},
render () {

View File

@ -82,7 +82,7 @@ converse.plugins.add('converse-muc-views', {
* @event _converse#roomsPanelRendered
* @example _converse.api.listen.on('roomsPanelRendered', () => { ... });
*/
_converse.api.emit('roomsPanelRendered');
_converse.api.trigger('roomsPanelRendered');
},
renderControlBoxPane () {
@ -580,7 +580,7 @@ converse.plugins.add('converse-muc-views', {
* @type { _converse.ChatRoomView }
* @example _converse.api.listen.on('chatRoomOpened', view => { ... });
*/
_converse.api.emit('chatRoomOpened', this);
_converse.api.trigger('chatRoomOpened', this);
},
render () {

View File

@ -267,7 +267,7 @@ converse.plugins.add('converse-notification', {
* @type { XMLElement }
* @example _converse.api.listen.on('messageNotification', stanza => { ... });
*/
_converse.api.emit('messageNotification', message);
_converse.api.trigger('messageNotification', message);
_converse.playSoundNotification();
_converse.showMessageNotification(message);
};

View File

@ -1137,7 +1137,7 @@ converse.plugins.add('converse-omemo', {
* @event _converse#OMEMOInitialized
* @example _converse.api.listen.on('OMEMOInitialized', () => { ... });
*/
_converse.api.emit('OMEMOInitialized');
_converse.api.trigger('OMEMOInitialized');
}
async function onOccupantAdded (chatroom, occupant) {

View File

@ -54,7 +54,7 @@ converse.plugins.add('converse-profile', {
* @type { _converse.XMPPStatus }
* @example _converse.api.listen.on('profileModalInitialized', status => { ... });
*/
_converse.api.emit('profileModalInitialized', this.model);
_converse.api.trigger('profileModalInitialized', this.model);
},
toHTML () {

View File

@ -182,7 +182,7 @@ converse.plugins.add('converse-roomslist', {
* @event _converse#roomsListInitialized
* @example _converse.api.listen.on('roomsListInitialized', status => { ... });
*/
_converse.api.emit('roomsListInitialized');
_converse.api.trigger('roomsListInitialized');
},
render () {

View File

@ -831,7 +831,7 @@ converse.plugins.add('converse-rosterview', {
* @event _converse#rosterViewInitialized
* @example _converse.api.listen.on('rosterViewInitialized', () => { ... });
*/
_converse.api.emit('rosterViewInitialized');
_converse.api.trigger('rosterViewInitialized');
},
render () {

View File

@ -768,7 +768,7 @@ converse.plugins.add('converse-chatboxes', {
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.emit('chatBoxesInitialized');
_converse.api.trigger('chatBoxesInitialized');
},
registerMessageHandler () {
@ -816,7 +816,7 @@ converse.plugins.add('converse-chatboxes', {
* @example _converse.api.listen.on('message', obj => { ... });
* @example _converse.api.waitUntil('chatBoxesFetched').then(() => { ... });
*/
_converse.api.emit('chatBoxesFetched');
_converse.api.trigger('chatBoxesFetched');
},
onConnected () {
@ -977,7 +977,7 @@ converse.plugins.add('converse-chatboxes', {
* @property { XMLElement } stanza
* @example _converse.api.listen.on('message', obj => { ... });
*/
_converse.api.emit('message', {'stanza': original_stanza, 'chatbox': chatbox});
_converse.api.trigger('message', {'stanza': original_stanza, 'chatbox': chatbox});
},
getChatBox (jid, attrs={}, create) {
@ -1034,7 +1034,7 @@ converse.plugins.add('converse-chatboxes', {
* @example _converse.api.listen.on('privateChatsAutoJoined', () => { ... });
* @example _converse.api.waitUntil('privateChatsAutoJoined').then(() => { ... });
*/
_converse.api.emit('privateChatsAutoJoined');
_converse.api.trigger('privateChatsAutoJoined');
}

View File

@ -304,12 +304,13 @@ function addPromise (promise) {
}
_converse.emit = function (name) {
/* Event emitter and promise resolver */
_converse.trigger.apply(this, arguments);
const promise = _converse.promises[name];
if (!_.isUndefined(promise)) {
promise.resolve();
}
_converse.log(
"(DEPRECATION) "+
"_converse.emit has been has been deprecated. "+
"Please use `_converse.api.trigger` instead.",
Strophe.LogLevel.WARN
)
_converse.api.emit.apply(_converse, arguments);
};
_converse.isUniView = function () {
@ -373,7 +374,7 @@ function initPlugins() {
* @example _converse.api.listen.on('pluginsInitialized', () => { ... });
* @example _converse.api.waitUntil('pluginsInitialized').then(() => { ... });
*/
_converse.api.emit('pluginsInitialized');
_converse.api.trigger('pluginsInitialized');
}
function initClientConfig () {
@ -399,7 +400,7 @@ function initClientConfig () {
* @example
* _converse.api.listen.on('clientConfigInitialized', () => { ... });
*/
_converse.api.emit('clientConfigInitialized');
_converse.api.trigger('clientConfigInitialized');
}
_converse.initConnection = function () {
@ -427,7 +428,7 @@ _converse.initConnection = function () {
*
* @event _converse#connectionInitialized
*/
_converse.api.emit('connectionInitialized');
_converse.api.trigger('connectionInitialized');
}
@ -465,7 +466,7 @@ function finishInitialization () {
function unregisterGlobalEventHandlers () {
document.removeEventListener("visibilitychange", _converse.saveWindowState);
_converse.api.emit('unregisteredGlobalEventHandlers');
_converse.api.trigger('unregisteredGlobalEventHandlers');
}
function cleanup () {
@ -696,7 +697,7 @@ _converse.initialize = async function (settings, callback) {
* @memberOf _converse
* @example _converse.api.listen.on('disconnected', () => { ... });
*/
_converse.api.emit('disconnected');
_converse.api.trigger('disconnected');
};
this.onDisconnected = function () {
@ -711,7 +712,7 @@ _converse.initialize = async function (settings, callback) {
/* In this case, we reconnect, because we might be receiving
* expirable tokens from the credentials_url.
*/
_converse.api.emit('will-reconnect');
_converse.api.trigger('will-reconnect');
return _converse.reconnect();
} else {
return _converse.disconnect();
@ -729,7 +730,7 @@ _converse.initialize = async function (settings, callback) {
*
* @event _converse#will-reconnect
*/
_converse.api.emit('will-reconnect');
_converse.api.trigger('will-reconnect');
_converse.reconnect();
};
@ -857,7 +858,7 @@ _converse.initialize = async function (settings, callback) {
* @event _converse#sessionInitialized
* @memberOf _converse
*/
_converse.api.emit('sessionInitialized');
_converse.api.trigger('sessionInitialized');
};
this.clearSession = function () {
@ -873,7 +874,7 @@ _converse.initialize = async function (settings, callback) {
* disconnected for some other reason.
* @event _converse#clearSession
*/
_converse.api.emit('clearSession');
_converse.api.trigger('clearSession');
};
this.logOut = function () {
@ -890,7 +891,7 @@ _converse.initialize = async function (settings, callback) {
* Triggered once the user has logged out.
* @event _converse#logout
*/
_converse.api.emit('logout');
_converse.api.trigger('logout');
};
this.saveWindowState = function (ev) {
@ -924,7 +925,7 @@ _converse.initialize = async function (settings, callback) {
* @property{ string } state - Either "hidden" or "visible"
* @example _converse.api.listen.on('windowStateChanged', obj => { ... });
*/
_converse.api.emit('windowStateChanged', {state});
_converse.api.trigger('windowStateChanged', {state});
};
this.registerGlobalEventHandlers = function () {
@ -938,7 +939,7 @@ _converse.initialize = async function (settings, callback) {
* @event _converse#registeredGlobalEventHandlers
* @example _converse.api.listen.on('registeredGlobalEventHandlers', () => { ... });
*/
_converse.api.emit('registeredGlobalEventHandlers');
_converse.api.trigger('registeredGlobalEventHandlers');
};
this.enableCarbons = function () {
@ -981,7 +982,7 @@ _converse.initialize = async function (settings, callback) {
* @example _converse.api.listen.on('statusInitialized', status => { ... });
* @example _converse.api.waitUntil('statusInitialized').then(() => { ... });
*/
_converse.api.emit('statusInitialized', reconnecting);
_converse.api.trigger('statusInitialized', reconnecting);
if (reconnecting) {
/**
* After the connection has dropped and converse.js has reconnected.
@ -990,7 +991,7 @@ _converse.initialize = async function (settings, callback) {
* @event _converse#reconnected
* @example _converse.api.listen.on('reconnected', () => { ... });
*/
_converse.api.emit('reconnected');
_converse.api.trigger('reconnected');
} else {
init_promise.resolve();
/**
@ -998,13 +999,13 @@ _converse.initialize = async function (settings, callback) {
* See also {@link _converse#event:pluginsInitialized}.
* @event _converse#initialized
*/
_converse.api.emit('initialized');
_converse.api.trigger('initialized');
/**
* Triggered after the connection has been established and Converse
* has got all its ducks in a row.
* @event _converse#initialized
*/
_converse.api.emit('connected');
_converse.api.trigger('connected');
}
};
@ -1013,7 +1014,7 @@ _converse.initialize = async function (settings, callback) {
_converse.bare_jid = Strophe.getBareJidFromJid(_converse.connection.jid);
_converse.resource = Strophe.getResourceFromJid(_converse.connection.jid);
_converse.domain = Strophe.getDomainFromJid(_converse.connection.jid);
_converse.api.emit('setUserJID');
_converse.api.trigger('setUserJID');
};
this.onConnected = function (reconnecting) {
@ -1035,7 +1036,7 @@ _converse.initialize = async function (settings, callback) {
},
initialize () {
this.on('change', () => _converse.api.emit('connfeedback', _converse.connfeedback));
this.on('change', () => _converse.api.trigger('connfeedback', _converse.connfeedback));
}
});
this.connfeedback = new this.ConnectionFeedback();
@ -1065,7 +1066,7 @@ _converse.initialize = async function (settings, callback) {
* @type { string }
* @example _converse.api.listen.on('statusChanged', status => { ... });
*/
_converse.api.emit('statusChanged', status);
_converse.api.trigger('statusChanged', status);
});
this.on('change:status_message', () => {
@ -1077,7 +1078,7 @@ _converse.initialize = async function (settings, callback) {
* @type { string }
* @example _converse.api.listen.on('statusMessageChanged', message => { ... });
*/
_converse.api.emit('statusMessageChanged', status_message);
_converse.api.trigger('statusMessageChanged', status_message);
});
},
@ -1140,7 +1141,7 @@ _converse.initialize = async function (settings, callback) {
};
xhr.onerror = function () {
delete _converse.connection;
_converse.api.emit('noResumeableSession', this);
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
@ -1168,7 +1169,7 @@ _converse.initialize = async function (settings, callback) {
* @type { _converse }
* @example _converse.api.listen.on('noResumeableSession', _converse => { ... });
*/
_converse.api.emit('noResumeableSession', this);
_converse.api.trigger('noResumeableSession', this);
};
xhr.send();
};
@ -1310,7 +1311,7 @@ _converse.initialize = async function (settings, callback) {
};
this.tearDown = function () {
_converse.api.emit('beforeTearDown');
_converse.api.trigger('beforeTearDown');
if (!_.isUndefined(_converse.session)) {
_converse.session.destroy();
}
@ -1320,7 +1321,7 @@ _converse.initialize = async function (settings, callback) {
window.removeEventListener('mousemove', _converse.onUserActivity);
window.removeEventListener(_converse.unloadevent, _converse.onUserActivity);
window.clearInterval(_converse.everySecondTrigger);
_converse.api.emit('afterTearDown');
_converse.api.trigger('afterTearDown');
return _converse;
};
@ -1388,14 +1389,28 @@ _converse.api = {
},
/**
* Lets you emit (i.e. trigger) events, which can be listened to via
* {@link _converse.api.listen.on} or {@link _converse.api.listen.once}
* (see [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)).
*
* Lets you emit (i.e. trigger) events.
* @deprecated since version 4.2.0. Use _converse.api.trigger instead.
* @method _converse.api.emit
*/
'emit' () {
_converse.emit.apply(_converse, arguments);
_converse.api.trigger.apply(this, arguments);
},
/**
* Lets you trigger events, which can be listened to via
* {@link _converse.api.listen.on} or {@link _converse.api.listen.once}
* (see [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)).
*
* @method _converse.api.trigger
*/
'trigger' () {
/* Event emitter and promise resolver */
_converse.trigger.apply(this, arguments);
const promise = _converse.promises[name];
if (!_.isUndefined(promise)) {
promise.resolve();
}
},
/**
@ -1581,7 +1596,7 @@ _converse.api = {
},
/**
* Converse and its plugins emit various events which you can listen to via the
* Converse and its plugins trigger various events which you can listen to via the
* {@link _converse.api.listen} namespace.
*
* Some of these events are also available as [ES2015 Promises](http://es6-features.org/#PromiseUsage)
@ -1616,7 +1631,7 @@ _converse.api = {
* Generally, it's the responsibility of the plugin which adds the promise to
* also resolve it.
*
* This is done by calling {@link _converse.api.emit}, which not only resolves the
* This is done by calling {@link _converse.api.trigger}, which not only resolves the
* promise, but also emits an event with the same name (which can be listened to
* via {@link _converse.api.listen}).
*
@ -1771,7 +1786,7 @@ _converse.api = {
.cnode(stanza.tree())
);
}
_converse.api.emit('send', stanza);
_converse.api.trigger('send', stanza);
},
/**
@ -1783,7 +1798,7 @@ _converse.api = {
'sendIQ' (stanza, timeout) {
return new Promise((resolve, reject) => {
_converse.connection.sendIQ(stanza, resolve, reject, timeout || _converse.IQ_TIMEOUT);
_converse.api.emit('send', stanza);
_converse.api.trigger('send', stanza);
});
}
};

View File

@ -101,7 +101,7 @@ converse.plugins.add('converse-disco', {
* @type { Backbone.Model }
* @example _converse.api.listen.on('featuresDiscovered', feature => { ... });
*/
_converse.api.emit('serviceDiscovered', feature);
_converse.api.trigger('serviceDiscovered', feature);
},
onFieldAdded (field) {
@ -112,7 +112,7 @@ converse.plugins.add('converse-disco', {
* @event _converse#discoExtensionFieldDiscovered
* @example _converse.api.listen.on('discoExtensionFieldDiscovered', () => { ... });
*/
_converse.api.emit('discoExtensionFieldDiscovered', field);
_converse.api.trigger('discoExtensionFieldDiscovered', field);
},
fetchFeatures () {
@ -246,7 +246,7 @@ converse.plugins.add('converse-disco', {
* @event _converse#addClientFeatures
* @example _converse.api.listen.on('addClientFeatures', () => { ... });
*/
_converse.api.emit('addClientFeatures');
_converse.api.trigger('addClientFeatures');
return this;
}
@ -276,7 +276,7 @@ converse.plugins.add('converse-disco', {
* @event _converse#streamFeaturesAdded
* @example _converse.api.listen.on('streamFeaturesAdded', () => { ... });
*/
_converse.api.emit('streamFeaturesAdded');
_converse.api.trigger('streamFeaturesAdded');
}
async function initializeDisco () {
@ -301,7 +301,7 @@ converse.plugins.add('converse-disco', {
* @event _converse#discoInitialized
* @example _converse.api.listen.on('discoInitialized', () => { ... });
*/
_converse.api.emit('discoInitialized');
_converse.api.trigger('discoInitialized');
}
_converse.api.listen.on('sessionInitialized', initStreamFeatures);

View File

@ -521,7 +521,7 @@ converse.plugins.add('converse-muc', {
* @property { string } reason - The original reason for the invitation
* @example _converse.api.listen.on('chatBoxMaximized', view => { ... });
*/
_converse.api.emit('roomInviteSent', {
_converse.api.trigger('roomInviteSent', {
'room': this,
'recipient': recipient,
'reason': reason
@ -1059,7 +1059,7 @@ converse.plugins.add('converse-muc', {
this.handleMessageCorrection(stanza) ||
this.isReceipt(stanza) ||
this.isChatMarker(stanza)) {
return _converse.api.emit('message', {'stanza': original_stanza});
return _converse.api.trigger('message', {'stanza': original_stanza});
}
const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza);
if (attrs.nick &&
@ -1073,7 +1073,7 @@ converse.plugins.add('converse-muc', {
msg.save({'received': moment().format()});
}
}
_converse.api.emit('message', {'stanza': original_stanza, 'chatbox': this});
_converse.api.trigger('message', {'stanza': original_stanza, 'chatbox': this});
},
onPresence (pres) {
@ -1411,7 +1411,7 @@ converse.plugins.add('converse-muc', {
* @example _converse.api.listen.on('roomsAutoJoined', () => { ... });
* @example _converse.api.waitUntil('roomsAutoJoined').then(() => { ... });
*/
_converse.api.emit('roomsAutoJoined');
_converse.api.trigger('roomsAutoJoined');
}
function disconnectChatRooms () {

View File

@ -71,7 +71,7 @@ converse.plugins.add('converse-roster', {
* @example _converse.api.listen.on('rosterInitialized', () => { ... });
* @example _converse.api.waitUntil('rosterInitialized').then(() => { ... });
*/
_converse.api.emit('rosterInitialized');
_converse.api.trigger('rosterInitialized');
};
@ -94,7 +94,7 @@ converse.plugins.add('converse-roster', {
* @event _converse#rosterContactsFetched
* @example _converse.api.listen.on('rosterContactsFetched', () => { ... });
*/
_converse.api.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
@ -110,9 +110,9 @@ converse.plugins.add('converse-roster', {
* @event _converse#rosterGroupsFetched
* @example _converse.api.listen.on('rosterGroupsFetched', () => { ... });
*/
_converse.api.emit('rosterGroupsFetched');
_converse.api.trigger('rosterGroupsFetched');
await _converse.roster.fetchRosterContacts();
_converse.api.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
@ -251,7 +251,7 @@ converse.plugins.add('converse-roster', {
* @type { _converse.RosterContact }
* @example _converse.api.listen.on('contactPresenceChanged', contact => { ... });
*/
this.presence.on('change:show', () => _converse.api.emit('contactPresenceChanged', this));
this.presence.on('change:show', () => _converse.api.trigger('contactPresenceChanged', this));
this.presence.on('change:show', () => this.trigger('presenceChanged'));
},
@ -439,7 +439,7 @@ converse.plugins.add('converse-roster', {
* @example _converse.api.listen.on('cachedRoster', (items) => { ... });
* @example _converse.api.waitUntil('cachedRoster').then(items => { ... });
*/
_converse.api.emit('cachedRoster', collection);
_converse.api.trigger('cachedRoster', collection);
}
},
@ -590,7 +590,7 @@ converse.plugins.add('converse-roster', {
* @type { XMLElement }
* @example _converse.api.listen.on('rosterPush', iq => { ... });
*/
_converse.api.emit('rosterPush', iq);
_converse.api.trigger('rosterPush', iq);
return;
},
@ -640,7 +640,7 @@ converse.plugins.add('converse-roster', {
* @example _converse.api.listen.on('roster', iq => { ... });
* @example _converse.api.waitUntil('roster').then(iq => { ... });
*/
_converse.api.emit('roster', iq);
_converse.api.trigger('roster', iq);
},
updateContact (item) {
@ -700,7 +700,7 @@ converse.plugins.add('converse-roster', {
* @type { _converse.RosterContact }
* @example _converse.api.listen.on('contactRequest', contact => { ... });
*/
_converse.api.emit('contactRequest', this.create(user_data));
_converse.api.trigger('contactRequest', this.create(user_data));
},
handleIncomingSubscription (presence) {
@ -921,7 +921,7 @@ converse.plugins.add('converse-roster', {
* @type { bool }
* @example _converse.api.listen.on('presencesInitialized', reconnecting => { ... });
*/
_converse.api.emit('presencesInitialized', reconnecting);
_converse.api.trigger('presencesInitialized', reconnecting);
});
_converse.api.listen.on('presencesInitialized', (reconnecting) => {
@ -933,7 +933,7 @@ converse.plugins.add('converse-roster', {
* @event _converse#rosterReadyAfterReconnection
* @example _converse.api.listen.on('rosterReadyAfterReconnection', () => { ... });
*/
_converse.api.emit('rosterReadyAfterReconnection');
_converse.api.trigger('rosterReadyAfterReconnection');
} else {
_converse.registerIntervalHandler();
_converse.initRoster();

View File

@ -41045,7 +41045,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.emit('chatBoxesInitialized');
_converse.api.trigger('chatBoxesInitialized');
},
registerMessageHandler() {
@ -41095,7 +41095,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
* @example _converse.api.waitUntil('chatBoxesFetched').then(() => { ... });
*/
_converse.api.emit('chatBoxesFetched');
_converse.api.trigger('chatBoxesFetched');
},
onConnected() {
@ -41264,7 +41264,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
*/
_converse.api.emit('message', {
_converse.api.trigger('message', {
'stanza': original_stanza,
'chatbox': chatbox
});
@ -41337,7 +41337,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
*/
_converse.api.emit('privateChatsAutoJoined');
_converse.api.trigger('privateChatsAutoJoined');
}
/************************ BEGIN Event Handlers ************************/
@ -41823,14 +41823,9 @@ function addPromise(promise) {
}
_converse.emit = function (name) {
/* Event emitter and promise resolver */
_converse.trigger.apply(this, arguments);
_converse.log("(DEPRECATION) " + "_converse.emit has been has been deprecated. " + "Please use `_converse.api.trigger` instead.", strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.WARN);
const promise = _converse.promises[name];
if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(promise)) {
promise.resolve();
}
_converse.api.emit.apply(_converse, arguments);
};
_converse.isUniView = function () {
@ -41888,7 +41883,7 @@ function initPlugins() {
*/
_converse.api.emit('pluginsInitialized');
_converse.api.trigger('pluginsInitialized');
}
function initClientConfig() {
@ -41917,7 +41912,7 @@ function initClientConfig() {
*/
_converse.api.emit('clientConfigInitialized');
_converse.api.trigger('clientConfigInitialized');
}
_converse.initConnection = function () {
@ -41947,7 +41942,7 @@ _converse.initConnection = function () {
* @event _converse#connectionInitialized
*/
_converse.api.emit('connectionInitialized');
_converse.api.trigger('connectionInitialized');
};
function setUpXMLLogging() {
@ -41990,7 +41985,7 @@ function finishInitialization() {
function unregisterGlobalEventHandlers() {
document.removeEventListener("visibilitychange", _converse.saveWindowState);
_converse.api.emit('unregisteredGlobalEventHandlers');
_converse.api.trigger('unregisteredGlobalEventHandlers');
}
function cleanup() {
@ -42261,7 +42256,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('disconnected');
_converse.api.trigger('disconnected');
};
this.onDisconnected = function () {
@ -42276,7 +42271,7 @@ _converse.initialize = async function (settings, callback) {
/* In this case, we reconnect, because we might be receiving
* expirable tokens from the credentials_url.
*/
_converse.api.emit('will-reconnect');
_converse.api.trigger('will-reconnect');
return _converse.reconnect();
} else {
@ -42293,7 +42288,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('will-reconnect');
_converse.api.trigger('will-reconnect');
_converse.reconnect();
};
@ -42444,7 +42439,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('sessionInitialized');
_converse.api.trigger('sessionInitialized');
};
this.clearSession = function () {
@ -42462,7 +42457,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('clearSession');
_converse.api.trigger('clearSession');
};
this.logOut = function () {
@ -42484,7 +42479,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('logout');
_converse.api.trigger('logout');
};
this.saveWindowState = function (ev) {
@ -42522,7 +42517,7 @@ _converse.initialize = async function (settings, callback) {
* @example _converse.api.listen.on('windowStateChanged', obj => { ... });
*/
_converse.api.emit('windowStateChanged', {
_converse.api.trigger('windowStateChanged', {
state
});
};
@ -42544,7 +42539,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('registeredGlobalEventHandlers');
_converse.api.trigger('registeredGlobalEventHandlers');
};
this.enableCarbons = function () {
@ -42589,7 +42584,7 @@ _converse.initialize = async function (settings, callback) {
* @example _converse.api.listen.on('statusInitialized', status => { ... });
* @example _converse.api.waitUntil('statusInitialized').then(() => { ... });
*/
_converse.api.emit('statusInitialized', reconnecting);
_converse.api.trigger('statusInitialized', reconnecting);
if (reconnecting) {
/**
@ -42599,7 +42594,7 @@ _converse.initialize = async function (settings, callback) {
* @event _converse#reconnected
* @example _converse.api.listen.on('reconnected', () => { ... });
*/
_converse.api.emit('reconnected');
_converse.api.trigger('reconnected');
} else {
init_promise.resolve();
/**
@ -42608,7 +42603,7 @@ _converse.initialize = async function (settings, callback) {
* @event _converse#initialized
*/
_converse.api.emit('initialized');
_converse.api.trigger('initialized');
/**
* Triggered after the connection has been established and Converse
* has got all its ducks in a row.
@ -42616,7 +42611,7 @@ _converse.initialize = async function (settings, callback) {
*/
_converse.api.emit('connected');
_converse.api.trigger('connected');
}
};
@ -42626,7 +42621,7 @@ _converse.initialize = async function (settings, callback) {
_converse.resource = strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].getResourceFromJid(_converse.connection.jid);
_converse.domain = strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].getDomainFromJid(_converse.connection.jid);
_converse.api.emit('setUserJID');
_converse.api.trigger('setUserJID');
};
this.onConnected = function (reconnecting) {
@ -42652,7 +42647,7 @@ _converse.initialize = async function (settings, callback) {
},
initialize() {
this.on('change', () => _converse.api.emit('connfeedback', _converse.connfeedback));
this.on('change', () => _converse.api.trigger('connfeedback', _converse.connfeedback));
}
});
@ -42686,7 +42681,7 @@ _converse.initialize = async function (settings, callback) {
* @example _converse.api.listen.on('statusChanged', status => { ... });
*/
_converse.api.emit('statusChanged', status);
_converse.api.trigger('statusChanged', status);
});
this.on('change:status_message', () => {
const status_message = this.get('status_message');
@ -42698,7 +42693,7 @@ _converse.initialize = async function (settings, callback) {
* @example _converse.api.listen.on('statusMessageChanged', message => { ... });
*/
_converse.api.emit('statusMessageChanged', status_message);
_converse.api.trigger('statusMessageChanged', status_message);
});
},
@ -42766,7 +42761,7 @@ _converse.initialize = async function (settings, callback) {
xhr.onerror = function () {
delete _converse.connection;
_converse.api.emit('noResumeableSession', this);
_converse.api.trigger('noResumeableSession', this);
reject(xhr.responseText);
};
@ -42798,7 +42793,7 @@ _converse.initialize = async function (settings, callback) {
* @example _converse.api.listen.on('noResumeableSession', _converse => { ... });
*/
_converse.api.emit('noResumeableSession', this);
_converse.api.trigger('noResumeableSession', this);
};
xhr.send();
@ -42937,7 +42932,7 @@ _converse.initialize = async function (settings, callback) {
};
this.tearDown = function () {
_converse.api.emit('beforeTearDown');
_converse.api.trigger('beforeTearDown');
if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_converse.session)) {
_converse.session.destroy();
@ -42950,7 +42945,7 @@ _converse.initialize = async function (settings, callback) {
window.removeEventListener(_converse.unloadevent, _converse.onUserActivity);
window.clearInterval(_converse.everySecondTrigger);
_converse.api.emit('afterTearDown');
_converse.api.trigger('afterTearDown');
return _converse;
}; // Initialization
@ -43025,14 +43020,30 @@ _converse.api = {
},
/**
* Lets you emit (i.e. trigger) events, which can be listened to via
* {@link _converse.api.listen.on} or {@link _converse.api.listen.once}
* (see [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)).
*
* Lets you emit (i.e. trigger) events.
* @deprecated since version 4.2.0. Use _converse.api.trigger instead.
* @method _converse.api.emit
*/
'emit'() {
_converse.emit.apply(_converse, arguments);
_converse.api.trigger.apply(this, arguments);
},
/**
* Lets you trigger events, which can be listened to via
* {@link _converse.api.listen.on} or {@link _converse.api.listen.once}
* (see [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)).
*
* @method _converse.api.trigger
*/
'trigger'() {
/* Event emitter and promise resolver */
_converse.trigger.apply(this, arguments);
const promise = _converse.promises[name];
if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(promise)) {
promise.resolve();
}
},
/**
@ -43237,7 +43248,7 @@ _converse.api = {
},
/**
* Converse and its plugins emit various events which you can listen to via the
* Converse and its plugins trigger various events which you can listen to via the
* {@link _converse.api.listen} namespace.
*
* Some of these events are also available as [ES2015 Promises](http://es6-features.org/#PromiseUsage)
@ -43272,7 +43283,7 @@ _converse.api = {
* Generally, it's the responsibility of the plugin which adds the promise to
* also resolve it.
*
* This is done by calling {@link _converse.api.emit}, which not only resolves the
* This is done by calling {@link _converse.api.trigger}, which not only resolves the
* promise, but also emits an event with the same name (which can be listened to
* via {@link _converse.api.listen}).
*
@ -43426,7 +43437,7 @@ _converse.api = {
}).up().cnode(stanza.tree()));
}
_converse.api.emit('send', stanza);
_converse.api.trigger('send', stanza);
},
/**
@ -43439,7 +43450,7 @@ _converse.api = {
return new es6_promise_dist_es6_promise_auto__WEBPACK_IMPORTED_MODULE_3___default.a((resolve, reject) => {
_converse.connection.sendIQ(stanza, resolve, reject, timeout || _converse.IQ_TIMEOUT);
_converse.api.emit('send', stanza);
_converse.api.trigger('send', stanza);
});
}
@ -43676,7 +43687,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
* @example _converse.api.listen.on('featuresDiscovered', feature => { ... });
*/
_converse.api.emit('serviceDiscovered', feature);
_converse.api.trigger('serviceDiscovered', feature);
},
onFieldAdded(field) {
@ -43688,7 +43699,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
* @example _converse.api.listen.on('discoExtensionFieldDiscovered', () => { ... });
*/
_converse.api.emit('discoExtensionFieldDiscovered', field);
_converse.api.trigger('discoExtensionFieldDiscovered', field);
},
fetchFeatures() {
@ -43846,7 +43857,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
*/
_converse.api.emit('addClientFeatures');
_converse.api.trigger('addClientFeatures');
return this;
}
@ -43877,7 +43888,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
*/
_converse.api.emit('streamFeaturesAdded');
_converse.api.trigger('streamFeaturesAdded');
}
async function initializeDisco() {
@ -43905,7 +43916,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
*/
_converse.api.emit('discoInitialized');
_converse.api.trigger('discoInitialized');
}
_converse.api.listen.on('sessionInitialized', initStreamFeatures);
@ -45454,7 +45465,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
*/
_converse.api.emit('roomInviteSent', {
_converse.api.trigger('roomInviteSent', {
'room': this,
'recipient': recipient,
'reason': reason
@ -46065,7 +46076,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
}
if (message || this.handleMessageCorrection(stanza) || this.isReceipt(stanza) || this.isChatMarker(stanza)) {
return _converse.api.emit('message', {
return _converse.api.trigger('message', {
'stanza': original_stanza
});
}
@ -46083,7 +46094,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
}
}
_converse.api.emit('message', {
_converse.api.trigger('message', {
'stanza': original_stanza,
'chatbox': this
});
@ -46461,7 +46472,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
*/
_converse.api.emit('roomsAutoJoined');
_converse.api.trigger('roomsAutoJoined');
}
function disconnectChatRooms() {
@ -47045,7 +47056,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.waitUntil('rosterInitialized').then(() => { ... });
*/
_converse.api.emit('rosterInitialized');
_converse.api.trigger('rosterInitialized');
};
_converse.populateRoster = async function () {
@ -47071,7 +47082,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.listen.on('rosterContactsFetched', () => { ... });
*/
_converse.api.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
@ -47088,11 +47099,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.listen.on('rosterGroupsFetched', () => { ... });
*/
_converse.api.emit('rosterGroupsFetched');
_converse.api.trigger('rosterGroupsFetched');
await _converse.roster.fetchRosterContacts();
_converse.api.emit('rosterContactsFetched');
_converse.api.trigger('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
@ -47239,7 +47250,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.listen.on('contactPresenceChanged', contact => { ... });
*/
this.presence.on('change:show', () => _converse.api.emit('contactPresenceChanged', this));
this.presence.on('change:show', () => _converse.api.trigger('contactPresenceChanged', this));
this.presence.on('change:show', () => this.trigger('presenceChanged'));
},
@ -47456,7 +47467,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.listen.on('cachedRoster', (items) => { ... });
* @example _converse.api.waitUntil('cachedRoster').then(items => { ... });
*/
_converse.api.emit('cachedRoster', collection);
_converse.api.trigger('cachedRoster', collection);
}
},
@ -47637,7 +47648,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.listen.on('rosterPush', iq => { ... });
*/
_converse.api.emit('rosterPush', iq);
_converse.api.trigger('rosterPush', iq);
return;
},
@ -47700,7 +47711,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
*/
_converse.api.emit('roster', iq);
_converse.api.trigger('roster', iq);
},
updateContact(item) {
@ -47769,7 +47780,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @example _converse.api.listen.on('contactRequest', contact => { ... });
*/
_converse.api.emit('contactRequest', this.create(user_data));
_converse.api.trigger('contactRequest', this.create(user_data));
},
handleIncomingSubscription(presence) {
@ -48019,7 +48030,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
*/
_converse.api.emit('presencesInitialized', reconnecting);
_converse.api.trigger('presencesInitialized', reconnecting);
});
_converse.api.listen.on('presencesInitialized', reconnecting => {
@ -48031,7 +48042,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
* @event _converse#rosterReadyAfterReconnection
* @example _converse.api.listen.on('rosterReadyAfterReconnection', () => { ... });
*/
_converse.api.emit('rosterReadyAfterReconnection');
_converse.api.trigger('rosterReadyAfterReconnection');
} else {
_converse.registerIntervalHandler();