Commit d41a7a14 authored by JC Brand's avatar JC Brand

Use API to emit and listen to events

parent 74816434
This diff is collapsed.
......@@ -141,7 +141,7 @@ For example:
.. code-block:: javascript
_converse.emit('foo-completed');
_converse.api.emit('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
......
......@@ -298,7 +298,7 @@ In this case, you should first listen for the ``connection`` event, and then do
initialize: function () {
var _converse = this._converse;
_converse.on('connected', function () {
_converse.api.listen.on('connected', function () {
_converse.api.archive.query({'with': 'admin2@localhost'});
});
}
......@@ -332,7 +332,7 @@ method of the plugin:
.. code-block:: javascript
_converse.on('chatBoxOpened', function renderMinimizeButton (view) {
_converse.api.listen.on('chatBoxOpened', function renderMinimizeButton (view) {
// Inserts a "minimize" button in the chatview's header
// Implementation code removed for brevity
......
......@@ -545,19 +545,19 @@ converse.plugins.add('converse-bookmarks', {
_converse.bookmarksview = new _converse.BookmarksView({'model': _converse.bookmarks});
await _converse.bookmarks.fetchBookmarks();
}
_converse.emit('bookmarksInitialized');
_converse.api.emit('bookmarksInitialized');
}
_converse.on('clearSession', () => {
_converse.api.listen.on('clearSession', () => {
if (!_.isUndefined(_converse.bookmarks)) {
_converse.bookmarks.browserStorage._clear();
window.sessionStorage.removeItem(_converse.bookmarks.fetched_flag);
}
});
_converse.on('reconnected', initBookmarks);
_converse.api.listen.on('reconnected', initBookmarks);
_converse.on('connected', async () => {
_converse.api.listen.on('connected', async () => {
// Add a handler for bookmarks pushed from other connected clients
// (from the same user obviously)
_converse.connection.addHandler(message => {
......
......@@ -168,7 +168,7 @@ converse.plugins.add('converse-chatboxviews', {
_converse.chatboxviews = new _converse.ChatBoxViews({
'model': _converse.chatboxes
});
_converse.emit('chatBoxViewsInitialized');
_converse.api.emit('chatBoxViewsInitialized');
});
_converse.api.listen.on('clearSession', () => _converse.chatboxviews.closeAllChatBoxes());
......
......@@ -180,7 +180,7 @@ converse.plugins.add('converse-chatview', {
onStatusMessageChanged (item) {
this.render();
_converse.emit('contactStatusMessageChanged', {
_converse.api.emit('contactStatusMessageChanged', {
'contact': item.attributes,
'message': item.get('status')
});
......@@ -201,7 +201,7 @@ converse.plugins.add('converse-chatview', {
this.model.on('contactAdded', this.registerContactEventHandlers, this);
this.model.on('change', this.render, this);
this.registerContactEventHandlers();
_converse.emit('userDetailsModalInitialized', this.model);
_converse.api.emit('userDetailsModalInitialized', this.model);
},
toHTML () {
......@@ -315,8 +315,8 @@ converse.plugins.add('converse-chatview', {
this.render();
this.fetchMessages();
_converse.emit('chatBoxOpened', this);
_converse.emit('chatBoxInitialized', this);
_converse.api.emit('chatBoxOpened', this);
_converse.api.emit('chatBoxInitialized', this);
},
initDebounced () {
......@@ -351,7 +351,7 @@ converse.plugins.add('converse-chatview', {
this.el.querySelector('.chat-toolbar').innerHTML = toolbar(options);
this.addSpoilerButton(options);
this.addFileUploadButton();
_converse.emit('renderToolbar', this);
_converse.api.emit('renderToolbar', this);
return this;
},
......@@ -485,7 +485,7 @@ converse.plugins.add('converse-chatview', {
this.insertIntoDOM();
this.scrollDown();
this.content.addEventListener('scroll', this.markScrolled.bind(this));
_converse.emit('afterMessagesFetched', this);
_converse.api.emit('afterMessagesFetched', this);
},
fetchMessages () {
......@@ -792,7 +792,7 @@ converse.plugins.add('converse-chatview', {
if (message.get('correcting')) {
this.insertIntoTextArea(message.get('message'), true, true);
}
_converse.emit('messageAdded', {
_converse.api.emit('messageAdded', {
'message': message,
'chatbox': this.model
});
......@@ -878,7 +878,7 @@ converse.plugins.add('converse-chatview', {
textarea.value = '';
u.removeClass('correcting', textarea);
textarea.style.height = 'auto'; // Fixes weirdness
_converse.emit('messageSend', message);
_converse.api.emit('messageSend', message);
}
textarea.removeAttribute('disabled');
u.removeClass('disabled', textarea);
......@@ -1081,7 +1081,7 @@ converse.plugins.add('converse-chatview', {
toggleCall (ev) {
ev.stopPropagation();
_converse.emit('callButtonClicked', {
_converse.api.emit('callButtonClicked', {
connection: _converse.connection,
model: this.model
});
......@@ -1162,7 +1162,7 @@ converse.plugins.add('converse-chatview', {
_converse.log(e, Strophe.LogLevel.ERROR);
}
this.remove();
_converse.emit('chatBoxClosed', this);
_converse.api.emit('chatBoxClosed', this);
return this;
},
......@@ -1182,7 +1182,7 @@ converse.plugins.add('converse-chatview', {
const textarea_el = this.el.querySelector('.chat-textarea');
if (!_.isNull(textarea_el)) {
textarea_el.focus();
_converse.emit('chatBoxFocused', this);
_converse.api.emit('chatBoxFocused', this);
}
return this;
},
......@@ -1265,7 +1265,7 @@ converse.plugins.add('converse-chatview', {
if (_converse.windowState !== 'hidden') {
this.model.clearUnreadMsgCounter();
}
_converse.emit('chatBoxScrolledDown', {'chatbox': this.model});
_converse.api.emit('chatBoxScrolledDown', {'chatbox': this.model});
},
onWindowStateChanged (state) {
......@@ -1283,7 +1283,7 @@ converse.plugins.add('converse-chatview', {
}
});
_converse.on('chatBoxViewsInitialized', () => {
_converse.api.listen.on('chatBoxViewsInitialized', () => {
const that = _converse.chatboxviews;
_converse.chatboxes.on('add', item => {
if (!that.get(item.get('id')) && item.get('type') === _converse.PRIVATE_CHAT_TYPE) {
......@@ -1292,7 +1292,7 @@ converse.plugins.add('converse-chatview', {
});
});
_converse.on('connected', () => {
_converse.api.listen.on('connected', () => {
// Advertise that we support XEP-0382 Message Spoilers
_converse.api.disco.own.features.add(Strophe.NS.SPOILER);
});
......
......@@ -224,7 +224,7 @@ converse.plugins.add('converse-controlbox', {
if (this.model.get('connected')) {
this.insertRoster();
}
_converse.emit('controlboxInitialized', this);
_converse.api.emit('controlboxInitialized', this);
},
render () {
......@@ -331,7 +331,7 @@ converse.plugins.add('converse-controlbox', {
} else {
this.model.trigger('hide');
}
_converse.emit('controlBoxClosed', this);
_converse.api.emit('controlBoxClosed', this);
return this;
},
......@@ -348,7 +348,7 @@ converse.plugins.add('converse-controlbox', {
return;
}
u.addClass('hidden', this.el);
_converse.emit('chatBoxClosed', this);
_converse.api.emit('chatBoxClosed', this);
if (!_converse.connection.connected) {
_converse.controlboxtoggle.render();
}
......@@ -359,7 +359,7 @@ converse.plugins.add('converse-controlbox', {
onControlBoxToggleHidden () {
this.model.set('closed', false);
this.el.classList.remove('hidden');
_converse.emit('controlBoxOpened', this);
_converse.api.emit('controlBoxOpened', this);
},
show () {
......@@ -591,7 +591,7 @@ converse.plugins.add('converse-controlbox', {
}
});
_converse.on('chatBoxViewsInitialized', () => {
_converse.api.listen.on('chatBoxViewsInitialized', () => {
const that = _converse.chatboxviews;
_converse.chatboxes.on('add', item => {
if (item.get('type') === _converse.CONTROLBOX_TYPE) {
......@@ -606,7 +606,7 @@ converse.plugins.add('converse-controlbox', {
});
});
_converse.on('clearSession', () => {
_converse.api.listen.on('clearSession', () => {
if (_converse.config.get('trusted')) {
const chatboxes = _.get(_converse, 'chatboxes', null);
if (!_.isNil(chatboxes)) {
......@@ -625,7 +625,7 @@ converse.plugins.add('converse-controlbox', {
_converse.api.waitUntil('chatBoxViewsInitialized')
]).then(addControlBox).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
_converse.on('chatBoxesFetched', () => {
_converse.api.listen.on('chatBoxesFetched', () => {
const controlbox = _converse.chatboxes.get('controlbox') || addControlBox();
controlbox.save({connected:true});
});
......
......@@ -81,8 +81,8 @@ converse.plugins.add('converse-headline', {
this.model.on('change:minimized', this.onMinimizedChanged, this);
this.render().insertHeading().fetchMessages().insertIntoDOM().hide();
_converse.emit('chatBoxOpened', this);
_converse.emit('chatBoxInitialized', this);
_converse.api.emit('chatBoxOpened', this);
_converse.api.emit('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.emit('message', {'chatbox': chatbox, 'stanza': message});
_converse.api.emit('message', {'chatbox': chatbox, 'stanza': message});
}
}
......@@ -137,11 +137,11 @@ converse.plugins.add('converse-headline', {
return true
}, null, 'message');
}
_converse.on('connected', registerHeadlineHandler);
_converse.on('reconnected', registerHeadlineHandler);
_converse.api.listen.on('connected', registerHeadlineHandler);
_converse.api.listen.on('reconnected', registerHeadlineHandler);
_converse.on('chatBoxViewsInitialized', () => {
_converse.api.listen.on('chatBoxViewsInitialized', () => {
const that = _converse.chatboxviews;
_converse.chatboxes.on('add', item => {
if (!that.get(item.get('id')) && item.get('type') === _converse.HEADLINES_TYPE) {
......
......@@ -176,9 +176,9 @@ converse.plugins.add('converse-mam-views', {
const { _converse } = this;
/* Event handlers */
_converse.on('afterMessagesFetched', view => view.fetchNewestMessages());
_converse.api.listen.on('afterMessagesFetched', view => view.fetchNewestMessages());
_converse.on('reconnected', () => {
_converse.api.listen.on('reconnected', () => {
const private_chats = _converse.chatboxviews.filter(
view => _.at(view, 'model.attributes.type')[0] === 'chatbox'
);
......
......@@ -131,7 +131,7 @@ converse.plugins.add('converse-minimize', {
this.model.clearUnreadMsgCounter();
}
this.show();
this.__super__._converse.emit('chatBoxMaximized', this);
this.__super__._converse.api.emit('chatBoxMaximized', this);
return this;
},
......@@ -146,7 +146,7 @@ converse.plugins.add('converse-minimize', {
}
this.setChatState(_converse.INACTIVE).model.minimize();
this.hide();
_converse.emit('chatBoxMinimized', this);
_converse.api.emit('chatBoxMinimized', this);
},
},
......@@ -358,7 +358,7 @@ converse.plugins.add('converse-minimize', {
view.close();
} else {
this.model.destroy();
_converse.emit('chatBoxClosed', this);
_converse.api.emit('chatBoxClosed', this);
}
return this;
},
......@@ -515,7 +515,7 @@ converse.plugins.add('converse-minimize', {
_converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes
});
_converse.emit('minimizedChatsInitialized');
_converse.api.emit('minimizedChatsInitialized');
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
......
......@@ -76,7 +76,7 @@ converse.plugins.add('converse-muc-views', {
this.el.querySelector('.controlbox-pane').insertAdjacentElement(
'beforeEnd', this.roomspanel.render().el);
_converse.emit('roomsPanelRendered');
_converse.api.emit('roomsPanelRendered');
},
renderControlBoxPane () {
......@@ -561,7 +561,7 @@ converse.plugins.add('converse-muc-views', {
} else {
this.fetchMessages();
}
_converse.emit('chatRoomOpened', this);
_converse.api.emit('chatRoomOpened', this);
},
render () {
......@@ -2063,7 +2063,7 @@ converse.plugins.add('converse-muc-views', {
}
/************************ BEGIN Event Handlers ************************/
_converse.on('chatBoxViewsInitialized', () => {
_converse.api.listen.on('chatBoxViewsInitialized', () => {
function openChatRoomFromURIClicked (ev) {
ev.preventDefault();
......@@ -2107,7 +2107,7 @@ converse.plugins.add('converse-muc-views', {
}
});
}
_converse.on('reconnected', reconnectToChatRooms);
_converse.api.listen.on('reconnected', reconnectToChatRooms);
/************************ END Event Handlers ************************/
......
......@@ -285,15 +285,15 @@ converse.plugins.add('converse-notification', {
}
};
_converse.on('pluginsInitialized', function () {
_converse.api.listen.on('pluginsInitialized', function () {
// We only register event handlers after all plugins are
// registered, because other plugins might override some of our
// handlers.
_converse.on('contactRequest', _converse.handleContactRequestNotification);
_converse.on('contactPresenceChanged', _converse.handleChatStateNotification);
_converse.on('message', _converse.handleMessageNotification);
_converse.on('feedback', _converse.handleFeedback);
_converse.on('connected', _converse.requestPermission);
_converse.api.listen.on('contactRequest', _converse.handleContactRequestNotification);
_converse.api.listen.on('contactPresenceChanged', _converse.handleChatStateNotification);
_converse.api.listen.on('message', _converse.handleMessageNotification);
_converse.api.listen.on('feedback', _converse.handleFeedback);
_converse.api.listen.on('connected', _converse.requestPermission);
});
}
});
......
......@@ -1132,7 +1132,7 @@ converse.plugins.add('converse-omemo', {
await fetchOwnDevices();
await restoreOMEMOSession();
await _converse.omemo_store.publishBundle();
_converse.emit('OMEMOInitialized');
_converse.api.emit('OMEMOInitialized');
}
async function onOccupantAdded (chatroom, occupant) {
......
......@@ -48,7 +48,7 @@ converse.plugins.add('converse-profile', {
initialize () {
this.model.on('change', this.render, this);
_converse.BootstrapModal.prototype.initialize.apply(this, arguments);
_converse.emit('profileModalInitialized', this.model);
_converse.api.emit('profileModalInitialized', this.model);
},
toHTML () {
......
......@@ -273,7 +273,7 @@ converse.plugins.add('converse-roomslist', {
_converse.api.emit('roomsListInitialized');
};
_converse.on('connected', async () => {
_converse.api.listen.on('connected', async () => {
if (_converse.allow_bookmarks) {
await _converse.api.waitUntil('bookmarksInitialized');
} else {
......
......@@ -815,9 +815,9 @@ converse.plugins.add('converse-rosterview', {
// just this group's) have been fetched from browser
// storage or the XMPP server and once they've been
// assigned to their various groups.
_converse.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this));
_converse.api.listen.on('rosterGroupsFetched', this.sortAndPositionAllItems.bind(this));
_converse.on('rosterContactsFetched', () => {
_converse.api.listen.on('rosterContactsFetched', () => {
_converse.roster.each((contact) => this.addRosterContact(contact, {'silent': true}));
this.update();
this.updateFilter();
......@@ -1032,7 +1032,7 @@ converse.plugins.add('converse-rosterview', {
'model': _converse.rostergroups
});
_converse.rosterview.render();
_converse.emit('rosterViewInitialized');
_converse.api.emit('rosterViewInitialized');
}
_converse.api.listen.on('rosterInitialized', initRoster);
_converse.api.listen.on('rosterReadyAfterReconnection', initRoster);
......
......@@ -796,7 +796,7 @@ converse.plugins.add('converse-chatboxes', {
chatbox.trigger('show');
}
});
_converse.emit('chatBoxesFetched');
_converse.api.emit('chatBoxesFetched');
},
onConnected () {
......@@ -949,7 +949,7 @@ converse.plugins.add('converse-chatboxes', {
}
}
}
_converse.emit('message', {'stanza': original_stanza, 'chatbox': chatbox});
_converse.api.emit('message', {'stanza': original_stanza, 'chatbox': chatbox});
},
getChatBox (jid, attrs={}, create) {
......@@ -998,15 +998,15 @@ converse.plugins.add('converse-chatboxes', {
Strophe.LogLevel.ERROR);
}
});
_converse.emit('privateChatsAutoJoined');
_converse.api.emit('privateChatsAutoJoined');
}
/************************ BEGIN Event Handlers ************************/
_converse.on('chatBoxesFetched', autoJoinChats);
_converse.api.listen.on('chatBoxesFetched', autoJoinChats);
_converse.on('addClientFeatures', () => {
_converse.api.listen.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT);
_converse.api.disco.own.features.add(Strophe.NS.HTTPUPLOAD);
_converse.api.disco.own.features.add(Strophe.NS.OUTOFBAND);
......@@ -1014,7 +1014,7 @@ converse.plugins.add('converse-chatboxes', {
_converse.api.listen.on('pluginsInitialized', () => {
_converse.chatboxes = new _converse.ChatBoxes();
_converse.emit('chatBoxesInitialized');
_converse.api.emit('chatBoxesInitialized');
});
_converse.api.listen.on('presencesInitialized', () => _converse.chatboxes.onConnected());
......
......@@ -380,7 +380,7 @@ function initPlugins() {
* // Your code here...
* });
*/
_converse.emit('pluginsInitialized');
_converse.api.emit('pluginsInitialized');
}
function initClientConfig () {
......@@ -406,7 +406,7 @@ function initClientConfig () {
* @example
* _converse.api.listen.on('clientConfigInitialized', () => { ... });
*/
_converse.emit('clientConfigInitialized');
_converse.api.emit('clientConfigInitialized');
}
_converse.initConnection = function () {
......@@ -434,7 +434,7 @@ _converse.initConnection = function () {
*
* @event _converse#connectionInitialized
*/
_converse.emit('connectionInitialized');
_converse.api.emit('connectionInitialized');
}
......@@ -463,7 +463,7 @@ function finishInitialization () {
Backbone.history.start();
}
if (_converse.idle_presence_timeout > 0) {
_converse.on('addClientFeatures', () => {
_converse.api.listen.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.IDLE);
});
}
......@@ -472,7 +472,7 @@ function finishInitialization () {
function unregisterGlobalEventHandlers () {
document.removeEventListener("visibilitychange", _converse.saveWindowState);
_converse.emit('unregisteredGlobalEventHandlers');
_converse.api.emit('unregisteredGlobalEventHandlers');
}
function cleanup () {
......@@ -706,7 +706,7 @@ _converse.initialize = async function (settings, callback) {
* @example
* _converse.api.listen.on('disconnected', () => { ... });
*/
_converse.emit('disconnected');
_converse.api.emit('disconnected');
};
this.onDisconnected = function () {
......@@ -721,7 +721,7 @@ _converse.initialize = async function (settings, callback) {
/* In this case, we reconnect, because we might be receiving
* expirable tokens from the credentials_url.
*/
_converse.emit('will-reconnect');
_converse.api.emit('will-reconnect');
return _converse.reconnect();
} else {
return _converse.disconnect();
......@@ -739,7 +739,7 @@ _converse.initialize = async function (settings, callback) {
*
* @event _converse#will-reconnect
*/
_converse.emit('will-reconnect');
_converse.api.emit('will-reconnect');
_converse.reconnect();
};
......@@ -869,7 +869,7 @@ _converse.initialize = async function (settings, callback) {
* @event _converse#sessionInitialized
* @memberOf _converse
*/
_converse.emit('sessionInitialized');
_converse.api.emit('sessionInitialized');
};
this.clearSession = function () {
......@@ -886,7 +886,7 @@ _converse.initialize = async function (settings, callback) {
*
* @event _converse#clearSession
*/
_converse.emit('clearSession');
_converse.api.emit('clearSession');
};
this.logOut = function () {
......@@ -904,7 +904,7 @@ _converse.initialize = async function (settings, callback) {
*
* @event _converse#logout
*/
_converse.emit('logout');
_converse.api.emit('logout');
};
this.saveWindowState = function (ev) {
......@@ -930,13 +930,13 @@ _converse.initialize = async function (settings, callback) {
_converse.clearMsgCounter();
}
_converse.windowState = state;
_converse.emit('windowStateChanged', {state});
_converse.api.emit('windowStateChanged', {state});
};
this.registerGlobalEventHandlers = function () {
document.addEventListener("visibilitychange", _converse.saveWindowState);
_converse.saveWindowState({'type': document.hidden ? "blur" : "focus"}); // Set initial state
_converse.emit('registeredGlobalEventHandlers');
_converse.api.emit('registeredGlobalEventHandlers');
};
this.enableCarbons = function () {
......@@ -984,9 +984,9 @@ _converse.initialize = async function (settings, callback) {
* // As an ES2015 Promise
* _converse.api.waitUntil('statusInitialized').then(() => { ... });
*/
_converse.emit('statusInitialized', reconnecting);
_converse.api.emit('statusInitialized', reconnecting);
if (reconnecting) {
_converse.emit('reconnected');
_converse.api.emit('reconnected');
} else {
init_promise.resolve();
/**
......@@ -995,14 +995,14 @@ _converse.initialize = async function (settings, callback) {
*
* @event _converse#initialized
*/
_converse.emit('initialized');
_converse.api.emit('initialized');
/**
* Emitted after the connection has been established and Converse
* has got all its ducks in a row.
*
* @event _converse#initialized
*/
_converse.emit('connected');
_converse.api.emit('connected');
}
};
......@@ -1011,7 +1011,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.emit('setUserJID');
_converse.api.emit('setUserJID');
};
this.onConnected = function (reconnecting) {
......@@ -1033,7 +1033,7 @@ _converse.initialize = async function (settings, callback) {
},
initialize () {
this.on('change', () => _converse.emit('connfeedback', _converse.connfeedback));
this.on('change', () => _converse.api.emit('connfeedback', _converse.connfeedback));
}
});
this.connfeedback = new this.ConnectionFeedback();
......@@ -1057,13 +1057,13 @@ _converse.initialize = async function (settings, callback) {
this.on('change:status', (item) => {
const status = this.get('status');
this.sendPresence(status);
_converse.emit('statusChanged', status);
_converse.api.emit('statusChanged', status);
});
this.on('change:status_message', () => {
const status_message = this.get('status_message');
this.sendPresence(this.get('status'), status_message);
_converse.emit('statusMessageChanged', status_message);
_converse.api.emit('statusMessageChanged', status_message);
});
},
......@@ -1126,7 +1126,7 @@ _converse.initialize = async function (settings, callback) {
};
xhr.onerror = function () {
delete _converse.connection;
_converse.emit('noResumeableSession', this);
_converse.api.emit('noResumeableSession', this);
reject(xhr.responseText);
};
xhr.send();
......@@ -1148,7 +1148,7 @@ _converse.initialize = async function (settings, callback) {
};
xhr.onerror = function () {
delete _converse.connection;
_converse.emit('noResumeableSession', this);
_converse.api.emit('noResumeableSession', this);
};
xhr.send();
};
......@@ -1290,7 +1290,7 @@ _converse.initialize = async function (settings, callback) {
};
this.tearDown = function () {
_converse.emit('beforeTearDown');
_converse.api.emit('beforeTearDown');
if (!_.isUndefined(_converse.session)) {
_converse.session.destroy();
}
......@@ -1300,7 +1300,7 @@ _converse.initialize = async function (settings, callback) {
window.removeEventListener('mousemove', _converse.onUserActivity);
window.removeEventListener(_converse.unloadevent, _converse.onUserActivity);
window.clearInterval(_converse.everySecondTrigger);
_converse.emit('afterTearDown');
_converse.api.emit('afterTearDown');
return _converse;
};
......@@ -1755,7 +1755,7 @@ _converse.api = {
.cnode(stanza.tree())
);
}
_converse.emit('send', stanza);
_converse.api.emit('send', stanza);
},
/**
......@@ -1768,7 +1768,7 @@ _converse.api = {
'sendIQ' (stanza, timeout) {
return new Promise((resolve, reject) => {
_converse.connection.sendIQ(stanza, resolve, reject, timeout || _converse.IQ_TIMEOUT);
_converse.emit('send', stanza);
_converse.api.emit('send', stanza);
});
}
};
......
......@@ -94,12 +94,12 @@ converse.plugins.add('converse-disco', {
onFeatureAdded (feature) {
feature.entity = this;
_converse.emit('serviceDiscovered', feature);
_converse.api.emit('serviceDiscovered', feature);
},
onFieldAdded (field) {
field.entity = this;
_converse.emit('discoExtensionFieldDiscovered', field);
_converse.api.emit('discoExtensionFieldDiscovered', field);
},
fetchFeatures () {
......@@ -227,7 +227,7 @@ converse.plugins.add('converse-disco', {
if (_converse.message_carbons) {
_converse.api.disco.own.features.add(Strophe.NS.CARBONS);
}
_converse.emit('addClientFeatures');
_converse.api.emit('addClientFeatures');
return this;
}
......@@ -250,7 +250,7 @@ converse.plugins.add('converse-disco', {
}
}
});
_converse.emit('streamFeaturesAdded');
_converse.api.emit('streamFeaturesAdded');
}
async function initializeDisco () {
......@@ -268,7 +268,7 @@ converse.plugins.add('converse-disco', {
// create one.
_converse.disco_entities.create({'jid': _converse.domain});
}
_converse.emit('discoInitialized');
_converse.api.emit('discoInitialized');
}
_converse.api.listen.on('sessionInitialized', initStreamFeatures);
......
......@@ -209,7 +209,7 @@ converse.plugins.add('converse-mam', {
};
/************************ BEGIN Event Handlers ************************/
_converse.on('serviceDiscovered', (feature) => {
_converse.api.listen.on('serviceDiscovered', (feature) => {
const prefs = feature.get('preferences') || {};
if (feature.get('var') === Strophe.NS.MAM &&
prefs['default'] !== _converse.message_archiving && // eslint-disable-line dot-notation
......@@ -221,7 +221,7 @@ converse.plugins.add('converse-mam', {
}
});
_converse.on('addClientFeatures', () => _converse.api.disco.own.features.add(Strophe.NS.MAM));
_converse.api.listen.on('addClientFeatures', () => _converse.api.disco.own.features.add(Strophe.NS.MAM));
/************************ END Event Handlers ************************/
......
......@@ -1043,7 +1043,7 @@ converse.plugins.add('converse-muc', {
this.handleMessageCorrection(stanza) ||
this.isReceipt(stanza) ||
this.isChatMarker(stanza)) {
return _converse.emit('message', {'stanza': original_stanza});
return _converse.api.emit('message', {'stanza': original_stanza});
}
const attrs = await this.getMessageAttributesFromStanza(stanza, original_stanza);
if (attrs.nick &&
......@@ -1057,7 +1057,7 @@ converse.plugins.add('converse-muc', {
msg.save({'received': moment().format()});
}
}
_converse.emit('message', {'stanza': original_stanza, 'chatbox': this});
_converse.api.emit('message', {'stanza': original_stanza, 'chatbox': this});
},
onPresence (pres) {
......@@ -1341,8 +1341,8 @@ converse.plugins.add('converse-muc', {
return true;
}, 'jabber:x:conference', 'message');
};
_converse.on('connected', registerDirectInvitationHandler);
_converse.on('reconnected', registerDirectInvitationHandler);
_converse.api.listen.on('connected', registerDirectInvitationHandler);
_converse.api.listen.on('reconnected', registerDirectInvitationHandler);
}
const getChatRoom = function (jid, attrs, create) {
......@@ -1380,7 +1380,7 @@ converse.plugins.add('converse-muc', {
Strophe.LogLevel.ERROR);
}
});
_converse.emit('roomsAutoJoined');
_converse.api.emit('roomsAutoJoined');
}
function disconnectChatRooms () {
......@@ -1415,7 +1415,7 @@ converse.plugins.add('converse-muc', {
/************************ BEGIN Event Handlers ************************/
_converse.on('addClientFeatures', () => {
_converse.api.listen.on('addClientFeatures', () => {
if (_converse.allow_muc) {
_converse.api.disco.own.features.add(Strophe.NS.MUC);
}
......
......@@ -87,7 +87,7 @@ converse.plugins.add('converse-ping', {
// Wrapper so that we can spy on registerPingHandler in tests
_converse.registerPingHandler();
};
_converse.on('connected', onConnected);
_converse.on('reconnected', onConnected);
_converse.api.listen.on('connected', onConnected);
_converse.api.listen.on('reconnected', onConnected);
}
});
......@@ -63,7 +63,7 @@ converse.plugins.add('converse-roster', {
_converse.rostergroups = new _converse.RosterGroups();
_converse.rostergroups.browserStorage = new Backbone.BrowserStorage[storage](
`converse.roster.groups${_converse.bare_jid}`);
_converse.emit('rosterInitialized');
_converse.api.emit('rosterInitialized');
};
......@@ -80,7 +80,7 @@ converse.plugins.add('converse-roster', {
_converse.send_initial_presence = true;
try {
await _converse.roster.fetchFromServer();
_converse.emit('rosterContactsFetched');
_converse.api.emit('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
......@@ -89,9 +89,9 @@ converse.plugins.add('converse-roster', {
} else {
try {
await _converse.rostergroups.fetchRosterGroups();
_converse.emit('rosterGroupsFetched');
_converse.api.emit('rosterGroupsFetched');
await _converse.roster.fetchRosterContacts();
_converse.emit('rosterContactsFetched');
_converse.api.emit('rosterContactsFetched');
} catch (reason) {
_converse.log(reason, Strophe.LogLevel.ERROR);
} finally {
......@@ -223,7 +223,7 @@ converse.plugins.add('converse-roster', {
this.setChatBox();
this.presence.on('change:show', () => _converse.emit('contactPresenceChanged', this));
this.presence.on('change:show', () => _converse.api.emit('contactPresenceChanged', this));
this.presence.on('change:show', () => this.trigger('presenceChanged'));
},
......@@ -404,7 +404,7 @@ converse.plugins.add('converse-roster', {
_converse.send_initial_presence = true;
return _converse.roster.fetchFromServer();
} else {
_converse.emit('cachedRoster', collection);
_converse.api.emit('cachedRoster', collection);
}
},
......@@ -549,7 +549,7 @@ converse.plugins.add('converse-roster', {
return;
}
this.updateContact(items.pop());
_converse.emit('rosterPush', iq);
_converse.api.emit('rosterPush', iq);
return;
},
......@@ -590,7 +590,7 @@ converse.plugins.add('converse-roster', {
this.data.save('version', query.getAttribute('ver'));
_converse.session.save('roster_fetched', true);
}
_converse.emit('roster', iq);
_converse.api.emit('roster', iq);
},
updateContact (item) {
......@@ -644,7 +644,7 @@ converse.plugins.add('converse-roster', {
'requesting': true,
'nickname': nickname
};
_converse.emit('contactRequest', this.create(user_data));
_converse.api.emit('contactRequest', this.create(user_data));
},
handleIncomingSubscription (presence) {
......@@ -856,7 +856,7 @@ converse.plugins.add('converse-roster', {
_converse.presences.browserStorage =
new Backbone.BrowserStorage.session(`converse.presences-${_converse.bare_jid}`);
_converse.presences.fetch();
_converse.emit('presencesInitialized', reconnecting);
_converse.api.emit('presencesInitialized', reconnecting);
});
_converse.api.listen.on('presencesInitialized', (reconnecting) => {
......@@ -865,7 +865,7 @@ converse.plugins.add('converse-roster', {
// cached data. However we still emit an event, to give
// event handlers a chance to register views for the
// roster and its groups, before we start populating.
_converse.emit('rosterReadyAfterReconnection');
_converse.api.emit('rosterReadyAfterReconnection');
} else {
_converse.registerIntervalHandler();
_converse.initRoster();
......
......@@ -130,7 +130,7 @@ converse.plugins.add('converse-vcard', {
_converse.api.listen.on('sessionInitialized', _converse.initVCardCollection);
_converse.on('addClientFeatures', () => {
_converse.api.listen.on('addClientFeatures', () => {
_converse.api.disco.own.features.add(Strophe.NS.VCARD);
});
......
This diff is collapsed.
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