Commit 030c26a8 authored by JC Brand's avatar JC Brand

Use `api` shortcut instead of `_converse.api`

parent d057177f
......@@ -65,14 +65,14 @@ converse.plugins.add('converse-bookmark-views', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
_converse.api.settings.update({
api.settings.update({
hide_open_bookmarks: true,
muc_respect_autojoin: true
});
......@@ -96,7 +96,7 @@ converse.plugins.add('converse-bookmark-views', {
*/
ev.preventDefault();
const jid = ev.target.getAttribute('data-room-jid');
_converse.api.rooms.open(jid, {'bring_to_foreground': true});
api.rooms.open(jid, {'bring_to_foreground': true});
_converse.chatboxviews.get(jid).renderBookmarkForm();
},
});
......@@ -203,7 +203,7 @@ converse.plugins.add('converse-bookmark-views', {
},
toHTML () {
const is_hidden = b => !!(_converse.api.settings.get('hide_open_bookmarks') && _converse.chatboxes.get(b.get('jid')));
const is_hidden = b => !!(api.settings.get('hide_open_bookmarks') && _converse.chatboxes.get(b.get('jid')));
return tpl_bookmarks_list({
'_converse': _converse,
'bookmarks': this.model,
......@@ -231,7 +231,7 @@ converse.plugins.add('converse-bookmark-views', {
const data = {
'name': name || Strophe.unescapeNode(Strophe.getNodeFromJid(jid)) || jid
}
_converse.api.rooms.open(jid, data, true);
api.rooms.open(jid, data, true);
},
removeBookmark: _converse.removeBookmarkViaEvent,
......@@ -255,7 +255,7 @@ converse.plugins.add('converse-bookmark-views', {
/************************ BEGIN Event Handlers ************************/
const initBookmarkViews = async function () {
await _converse.api.waitUntil('roomsPanelRendered');
await api.waitUntil('roomsPanelRendered');
_converse.bookmarksview = new _converse.BookmarksView({'model': _converse.bookmarks});
/**
* Triggered once the _converse.Bookmarks collection and _converse.BookmarksView view
......@@ -263,11 +263,11 @@ converse.plugins.add('converse-bookmark-views', {
* @event _converse#bookmarkViewsInitialized
* @example _converse.api.listen.on('bookmarkViewsInitialized', () => { ... });
*/
_converse.api.trigger('bookmarkViewsInitialized');
api.trigger('bookmarkViewsInitialized');
}
_converse.api.listen.on('bookmarksInitialized', initBookmarkViews);
_converse.api.listen.on('chatRoomViewInitialized', view => view.setBookmarkState());
api.listen.on('bookmarksInitialized', initBookmarkViews);
api.listen.on('chatRoomViewInitialized', view => view.setBookmarkState());
/************************ END Event Handlers ************************/
}
});
......@@ -48,14 +48,15 @@ converse.plugins.add('converse-chatboxviews', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
_converse.api.promises.add(['chatBoxViewsInitialized']);
api.promises.add(['chatBoxViewsInitialized']);
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
_converse.api.settings.update({
api.settings.update({
'animate': true,
'theme': 'default'
});
......@@ -74,7 +75,7 @@ converse.plugins.add('converse-chatboxviews', {
if (el === null) {
el = document.createElement('div');
el.setAttribute('id', 'conversejs');
u.addClass(`theme-${_converse.api.settings.get('theme')}`, el);
u.addClass(`theme-${api.settings.get('theme')}`, el);
const body = _converse.root.querySelector('body');
if (body) {
body.appendChild(el);
......@@ -97,9 +98,9 @@ converse.plugins.add('converse-chatboxviews', {
bg.innerHTML = tpl_background_logo();
}
const body = document.querySelector('body');
body.classList.add(`converse-${_converse.api.settings.get("view_mode")}`);
this.el.classList.add(`converse-${_converse.api.settings.get("view_mode")}`);
if (_converse.api.settings.get("singleton")) {
body.classList.add(`converse-${api.settings.get("view_mode")}`);
this.el.classList.add(`converse-${api.settings.get("view_mode")}`);
if (api.settings.get("singleton")) {
this.el.classList.add(`converse-singleton`);
}
this.render();
......@@ -133,7 +134,7 @@ converse.plugins.add('converse-chatboxviews', {
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('chatBoxesInitialized', () => {
api.listen.on('chatBoxesInitialized', () => {
_converse.chatboxviews = new _converse.ChatBoxViews({
'model': _converse.chatboxes
});
......@@ -142,17 +143,17 @@ converse.plugins.add('converse-chatboxviews', {
* @event _converse#chatBoxViewsInitialized
* @example _converse.api.listen.on('chatBoxViewsInitialized', () => { ... });
*/
_converse.api.trigger('chatBoxViewsInitialized');
api.trigger('chatBoxViewsInitialized');
});
_converse.api.listen.on('clearSession', () => _converse.chatboxviews.closeAllChatBoxes());
api.listen.on('clearSession', () => _converse.chatboxviews.closeAllChatBoxes());
function calculateViewportHeightUnit () {
const vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
_converse.api.listen.on('chatBoxViewsInitialized', () => calculateViewportHeightUnit());
api.listen.on('chatBoxViewsInitialized', () => calculateViewportHeightUnit());
window.addEventListener('resize', () => calculateViewportHeightUnit());
/************************ END Event Handlers ************************/
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -134,8 +134,9 @@ converse.plugins.add('converse-dragresize', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
_converse.api.settings.update({
api.settings.update({
'allow_dragresize': true,
});
......@@ -252,7 +253,7 @@ converse.plugins.add('converse-dragresize', {
},
onStartVerticalResize (ev, trigger=true) {
if (!_converse.api.settings.get('allow_dragresize')) {
if (!api.settings.get('allow_dragresize')) {
return true;
}
// Record element attributes for mouseMove().
......@@ -270,12 +271,12 @@ converse.plugins.add('converse-dragresize', {
* @event _converse#startVerticalResize
* @example _converse.api.listen.on('startVerticalResize', (view) => { ... });
*/
_converse.api.trigger('startVerticalResize', this);
api.trigger('startVerticalResize', this);
}
},
onStartHorizontalResize (ev, trigger=true) {
if (!_converse.api.settings.get('allow_dragresize')) {
if (!api.settings.get('allow_dragresize')) {
return true;
}
const flyout = this.el.querySelector('.box-flyout'),
......@@ -292,7 +293,7 @@ converse.plugins.add('converse-dragresize', {
* @event _converse#startHorizontalResize
* @example _converse.api.listen.on('startHorizontalResize', (view) => { ... });
*/
_converse.api.trigger('startHorizontalResize', this);
api.trigger('startHorizontalResize', this);
}
},
......@@ -306,7 +307,7 @@ converse.plugins.add('converse-dragresize', {
* @event _converse#startDiagonalResize
* @example _converse.api.listen.on('startDiagonalResize', (view) => { ... });
*/
_converse.api.trigger('startDiagonalResize', this);
api.trigger('startDiagonalResize', this);
},
};
Object.assign(_converse.ChatBoxView.prototype, dragResizable);
......@@ -332,7 +333,7 @@ converse.plugins.add('converse-dragresize', {
function onMouseMove (ev) {
if (!_converse.resizing || !_converse.api.settings.get('allow_dragresize')) {
if (!_converse.resizing || !api.settings.get('allow_dragresize')) {
return true;
}
ev.preventDefault();
......@@ -341,7 +342,7 @@ converse.plugins.add('converse-dragresize', {
function onMouseUp (ev) {
if (!_converse.resizing || !_converse.api.settings.get('allow_dragresize')) {
if (!_converse.resizing || !api.settings.get('allow_dragresize')) {
return true;
}
ev.preventDefault();
......@@ -353,7 +354,7 @@ converse.plugins.add('converse-dragresize', {
_converse.resizing.chatbox.width,
_converse.resizing.chatbox.model.get('default_width')
);
if (_converse.api.connection.connected()) {
if (api.connection.connected()) {
_converse.resizing.chatbox.model.save({'height': height});
_converse.resizing.chatbox.model.save({'width': width});
} else {
......@@ -374,9 +375,9 @@ converse.plugins.add('converse-dragresize', {
document.removeEventListener('mouseup', onMouseUp);
}
_converse.api.listen.on('registeredGlobalEventHandlers', registerGlobalEventHandlers);
_converse.api.listen.on('unregisteredGlobalEventHandlers', unregisterGlobalEventHandlers);
_converse.api.listen.on('beforeShowingChatView', view => view.initDragResize().setDimensions());
api.listen.on('registeredGlobalEventHandlers', registerGlobalEventHandlers);
api.listen.on('unregisteredGlobalEventHandlers', unregisterGlobalEventHandlers);
api.listen.on('beforeShowingChatView', view => view.initDragResize().setDimensions());
/************************ END Event Handlers ************************/
}
});
......@@ -68,9 +68,10 @@ converse.plugins.add('converse-emoji-views', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
const { __ } = _converse;
_converse.api.settings.update({
api.settings.update({
'use_system_emojis': true,
'visible_toolbar_buttons': {
'emoji': true
......@@ -91,7 +92,7 @@ converse.plugins.add('converse-emoji-views', {
},
async createEmojiPicker () {
await _converse.api.emojis.initialize()
await api.emojis.initialize()
const id = `converse.emoji-${_converse.bare_jid}-${this.model.get('jid')}`;
const emojipicker = new _converse.EmojiPicker({'id': id});
......@@ -151,7 +152,7 @@ converse.plugins.add('converse-emoji-views', {
Object.assign(
this.model.toJSON(), {
'_converse': _converse,
'emoji_categories': _converse.api.settings.get('emoji_categories'),
'emoji_categories': api.settings.get('emoji_categories'),
'emojis_by_category': _converse.emojis.json,
'onSkintonePicked': ev => this.chooseSkinTone(ev),
'onEmojiPicked': ev => this.insertEmoji(ev),
......@@ -415,18 +416,18 @@ converse.plugins.add('converse-emoji-views', {
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('chatBoxClosed', view => view.emoji_picker_view && view.emoji_picker_view.remove());
api.listen.on('chatBoxClosed', view => view.emoji_picker_view && view.emoji_picker_view.remove());
_converse.api.listen.on('renderToolbar', view => {
if (_converse.api.settings.get('visible_toolbar_buttons').emoji) {
api.listen.on('renderToolbar', view => {
if (api.settings.get('visible_toolbar_buttons').emoji) {
const html = tpl_emoji_button({'tooltip_insert_smiley': __('Insert emojis')});
view.el.querySelector('.chat-toolbar').insertAdjacentHTML('afterBegin', html);
}
});
_converse.api.listen.on('headlinesBoxInitialized', () => _converse.api.emojis.initialize());
_converse.api.listen.on('chatRoomInitialized', () => _converse.api.emojis.initialize());
_converse.api.listen.on('chatBoxInitialized', () => _converse.api.emojis.initialize());
api.listen.on('headlinesBoxInitialized', () => api.emojis.initialize());
api.listen.on('chatRoomInitialized', () => api.emojis.initialize());
api.listen.on('chatBoxInitialized', () => api.emojis.initialize());
/************************ END Event Handlers ************************/
}
......
......@@ -48,6 +48,7 @@ converse.plugins.add('converse-headlines-view', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
const viewWithHeadlinesPanel = {
......@@ -62,7 +63,7 @@ converse.plugins.add('converse-headlines-view', {
* @event _converse#headlinesPanelRendered
* @example _converse.api.listen.on('headlinesPanelRendered', () => { ... });
*/
_converse.api.trigger('headlinesPanelRendered');
api.trigger('headlinesPanelRendered');
return this.headlinepanel;
}
}
......@@ -150,7 +151,7 @@ converse.plugins.add('converse-headlines-view', {
* @type { _converse.HeadlinesBoxView }
* @example _converse.api.listen.on('headlinesBoxViewInitialized', view => { ... });
*/
_converse.api.trigger('headlinesBoxViewInitialized', this);
api.trigger('headlinesBoxViewInitialized', this);
},
render () {
......@@ -177,7 +178,7 @@ converse.plugins.add('converse-headlines-view', {
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('chatBoxViewsInitialized', () => {
api.listen.on('chatBoxViewsInitialized', () => {
const views = _converse.chatboxviews;
_converse.chatboxes.on('add', item => {
if (!views.get(item.get('id')) && item.get('type') === _converse.HEADLINES_TYPE) {
......
......@@ -32,6 +32,7 @@ converse.plugins.add('converse-message-view', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
const { __ } = _converse;
......@@ -65,7 +66,7 @@ converse.plugins.add('converse-message-view', {
}
_converse.api.settings.update({
api.settings.update({
'show_images_inline': true,
'time_format': 'HH:mm',
});
......@@ -153,7 +154,7 @@ converse.plugins.add('converse-message-view', {
},
fadeOut () {
if (_converse.api.settings.get('animate')) {
if (api.settings.get('animate')) {
setTimeout(() => this.remove(), 600);
u.addClass('fade-out', this.el);
} else {
......@@ -204,10 +205,10 @@ converse.plugins.add('converse-message-view', {
* @param { string } text - The message text
* @example _converse.api.listen.on('beforeMessageBodyTransformed', (view, text) => { ... });
*/
await _converse.api.trigger('beforeMessageBodyTransformed', this, text, {'Synchronous': true});
await api.trigger('beforeMessageBodyTransformed', this, text, {'Synchronous': true});
text = this.model.isMeCommand() ? text.substring(4) : text;
text = xss.filterXSS(text, {'whiteList': {}, 'onTag': onTagFoundDuringXSSFilter});
text = u.geoUriToHttp(text, _converse.api.settings.get("geouri_replacement"));
text = u.geoUriToHttp(text, api.settings.get("geouri_replacement"));
text = u.addMentionsMarkup(text, this.model.get('references'), this.model.collection.chatbox);
text = u.addHyperlinks(text);
text = u.renderNewLines(text);
......@@ -220,12 +221,12 @@ converse.plugins.add('converse-message-view', {
* @param { string } text - The message text
* @example _converse.api.listen.on('afterMessageBodyTransformed', (view, text) => { ... });
*/
await _converse.api.trigger('afterMessageBodyTransformed', this, text, {'Synchronous': true});
await api.trigger('afterMessageBodyTransformed', this, text, {'Synchronous': true});
return text;
},
async renderChatMessage () {
await _converse.api.waitUntil('emojisInitialized');
await api.waitUntil('emojisInitialized');
const time = dayjs(this.model.get('time'));
const role = this.model.vcard ? this.model.vcard.get('role') : null;
const roles = role ? role.split(',') : [];
......@@ -243,7 +244,7 @@ converse.plugins.add('converse-message-view', {
'is_me_message': this.model.isMeCommand(),
'label_show': __('Show more'),
'occupant': this.model.occupant,
'pretty_time': time.format(_converse.api.settings.get('time_format')),
'pretty_time': time.format(api.settings.get('time_format')),
'retraction_text': is_retracted ? this.getRetractionText() : null,
'roles': roles,
'time': time.toISOString(),
......@@ -259,7 +260,7 @@ converse.plugins.add('converse-message-view', {
const msg_content = msg.querySelector('.chat-msg__text');
if (text && text !== url) {
msg_content.innerHTML = await this.transformBodyText(text);
if (_converse.api.settings.get('show_images_inline')) {
if (api.settings.get('show_images_inline')) {
u.renderImageURLs(_converse, msg_content).then(() => this.triggerRendered());
}
}
......
......@@ -165,8 +165,9 @@ converse.plugins.add('converse-minimize', {
*/
const { _converse } = this;
const { __ } = _converse;
const { api } = _converse;
_converse.api.settings.update({'no_trimming': false});
api.settings.update({'no_trimming': false});
const minimizableChatBox = {
maximize () {
......@@ -210,7 +211,7 @@ converse.plugins.add('converse-minimize', {
* @type { _converse.ChatBoxView }
* @example _converse.api.listen.on('chatBoxMaximized', view => { ... });
*/
_converse.api.trigger('chatBoxMaximized', this);
api.trigger('chatBoxMaximized', this);
return this;
},
......@@ -239,7 +240,7 @@ converse.plugins.add('converse-minimize', {
* @type { _converse.ChatBoxView }
* @example _converse.api.listen.on('chatBoxMinimized', view => { ... });
*/
_converse.api.trigger('chatBoxMinimized', this);
api.trigger('chatBoxMinimized', this);
return this;
},
......@@ -314,7 +315,7 @@ converse.plugins.add('converse-minimize', {
* @param { _converse.ChatBoxView|_converse.ChatRoomView|_converse.ControlBoxView|_converse.HeadlinesBoxView } [newchat]
*/
async trimChats (newchat) {
if (_converse.api.settings.get('no_trimming') || !_converse.api.connection.connected() || _converse.api.settings.get("view_mode") !== 'overlayed') {
if (api.settings.get('no_trimming') || !api.connection.connected() || api.settings.get("view_mode") !== 'overlayed') {
return;
}
const shown_chats = this.getShownChats();
......@@ -328,7 +329,7 @@ converse.plugins.add('converse-minimize', {
// fullscreen. In this case we don't trim.
return;
}
await _converse.api.waitUntil('minimizedChatsInitialized');
await api.waitUntil('minimizedChatsInitialized');
const minimized_el = _converse.minimized_chats?.el;
if (minimized_el) {
while ((this.getMinimizedWidth() + this.getBoxesWidth(newchat)) > body_width) {
......@@ -369,7 +370,7 @@ converse.plugins.add('converse-minimize', {
Object.assign(_converse.ChatBoxViews.prototype, chatTrimmer);
_converse.api.promises.add('minimizedChatsInitialized');
api.promises.add('minimizedChatsInitialized');
_converse.MinimizedChatBoxView = View.extend({
tagName: 'div',
......@@ -390,7 +391,7 @@ converse.plugins.add('converse-minimize', {
* @type { _converse.MinimizedChatBoxView }
* @example _converse.api.listen.on('minimizedChatViewInitialized', view => { ... });
*/
_converse.api.trigger('minimizedChatViewInitialized', this);
api.trigger('minimizedChatViewInitialized', this);
},
render () {
......@@ -413,7 +414,7 @@ converse.plugins.add('converse-minimize', {
view.close();
} else {
this.model.destroy();
_converse.api.trigger('chatBoxClosed', this);
api.trigger('chatBoxClosed', this);
}
return this;
},
......@@ -562,17 +563,17 @@ converse.plugins.add('converse-minimize', {
* @event _converse#minimizedChatsInitialized
* @example _converse.api.listen.on('minimizedChatsInitialized', () => { ... });
*/
_converse.api.trigger('minimizedChatsInitialized');
api.trigger('minimizedChatsInitialized');
}
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('chatBoxViewsInitialized', () => initMinimizedChats());
_converse.api.listen.on('chatBoxInsertedIntoDOM', view => _converse.chatboxviews.trimChats(view));
_converse.api.listen.on('controlBoxOpened', view => _converse.chatboxviews.trimChats(view));
api.listen.on('chatBoxViewsInitialized', () => initMinimizedChats());
api.listen.on('chatBoxInsertedIntoDOM', view => _converse.chatboxviews.trimChats(view));
api.listen.on('controlBoxOpened', view => _converse.chatboxviews.trimChats(view));
const debouncedTrimChats = debounce(() => _converse.chatboxviews.trimChats(), 250);
_converse.api.listen.on('registeredGlobalEventHandlers', () => window.addEventListener("resize", debouncedTrimChats));
_converse.api.listen.on('unregisteredGlobalEventHandlers', () => window.removeEventListener("resize", debouncedTrimChats));
api.listen.on('registeredGlobalEventHandlers', () => window.addEventListener("resize", debouncedTrimChats));
api.listen.on('unregisteredGlobalEventHandlers', () => window.removeEventListener("resize", debouncedTrimChats));
/************************ END Event Handlers ************************/
}
});
This diff is collapsed.
......@@ -20,17 +20,18 @@ converse.plugins.add('converse-notification', {
*/
const { _converse } = this;
const { __ } = _converse;
const { api } = _converse;
_converse.supports_html5_notification = "Notification" in window;
_converse.api.settings.update({
api.settings.update({
notify_all_room_messages: false,
show_desktop_notifications: true,
show_chat_state_notifications: false,
chatstate_notification_blacklist: [],
// ^ a list of JIDs to ignore concerning chat state notifications
play_sounds: true,
sounds_path: _converse.api.settings.get("assets_path")+'/sounds/',
sounds_path: api.settings.get("assets_path")+'/sounds/',
notification_icon: 'logo/conversejs-filled.svg',
notification_delay: 5000
});
......@@ -135,7 +136,7 @@ converse.plugins.add('converse-notification', {
const full_from_jid = message.getAttribute('from'),
from_jid = Strophe.getBareJidFromJid(full_from_jid);
if (message.getAttribute('type') === 'headline') {
if (!from_jid.includes('@') || _converse.api.settings.get("allow_non_roster_messaging")) {
if (!from_jid.includes('@') || api.settings.get("allow_non_roster_messaging")) {
title = __("Notification from %1$s", from_jid);
} else {
return;
......@@ -154,7 +155,7 @@ converse.plugins.add('converse-notification', {
if (roster_item !== undefined) {
title = __("%1$s says", roster_item.getDisplayName());
} else {
if (_converse.api.settings.get("allow_non_roster_messaging")) {
if (api.settings.get("allow_non_roster_messaging")) {
title = __("%1$s says", from_jid);
} else {
return;
......@@ -262,7 +263,7 @@ converse.plugins.add('converse-notification', {
* @type { XMLElement }
* @example _converse.api.listen.on('messageNotification', stanza => { ... });
*/
_converse.api.trigger('messageNotification', message);
api.trigger('messageNotification', message);
_converse.playSoundNotification();
_converse.showMessageNotification(message);
};
......@@ -286,15 +287,15 @@ converse.plugins.add('converse-notification', {
}
};
_converse.api.listen.on('pluginsInitialized', function () {
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.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);
api.listen.on('contactRequest', _converse.handleContactRequestNotification);
api.listen.on('contactPresenceChanged', _converse.handleChatStateNotification);
api.listen.on('message', _converse.handleMessageNotification);
api.listen.on('feedback', _converse.handleFeedback);
api.listen.on('connected', _converse.requestPermission);
});
}
});
......@@ -55,8 +55,9 @@ converse.plugins.add("converse-oauth", {
render () {
const { _converse } = this.__super__;
const { api } = _converse;
const result = this.__super__.render.apply(this, arguments);
if (_converse.oauth_providers && !_converse.api.settings.get("auto_login")) {
if (_converse.oauth_providers && !api.settings.get("auto_login")) {
this.insertOAuthProviders();
}
return result;
......@@ -68,10 +69,11 @@ converse.plugins.add("converse-oauth", {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this,
{ __ } = _converse;
const { _converse } = this;
const { api } = _converse;
const { __ } = _converse;
_converse.api.settings.update({
api.settings.update({
'oauth_providers': {},
});
......@@ -79,7 +81,7 @@ converse.plugins.add("converse-oauth", {
'sync': function sync () {},
initialize () {
_converse.api.settings.get('oauth_providers').forEach(provider => {
api.settings.get('oauth_providers').forEach(provider => {
const item = new Model(Object.assign(provider, {
'login_text': __('Log in with %1$s', provider.name)
}));
......@@ -102,7 +104,7 @@ converse.plugins.add("converse-oauth", {
async fetchOAuthProfileDataAndLogin () {
const profile = await this.oauth_service.api('me');
const response = this.oauth_service.getAuthResponse();
_converse.api.user.login(
api.user.login(
`${profile.name}@${this.provider.get('host')}`,
response.access_token
);
......
......@@ -242,12 +242,13 @@ converse.plugins.add('converse-omemo', {
*/
const { _converse } = this;
const { __ } = _converse;
const { api } = _converse;
_converse.api.settings.update({
api.settings.update({
'omemo_default': false,
});
_converse.api.promises.add(['OMEMOInitialized']);
api.promises.add(['OMEMOInitialized']);
_converse.NUM_PREKEYS = 100; // Set here so that tests can override
......@@ -306,7 +307,7 @@ converse.plugins.add('converse-omemo', {
},
reportDecryptionError (e) {
if (_converse.api.settings.get("loglevel") === 'debug') {
if (api.settings.get("loglevel") === 'debug') {
const { __ } = _converse;
this.createMessage({
'message': __("Sorry, could not decrypt a received OMEMO message due to an error.") + ` ${e.name} ${e.message}`,
......@@ -414,10 +415,10 @@ converse.plugins.add('converse-omemo', {
err_msgs.push(__("Unable to send an encrypted message due to an unexpected error."));
err_msgs.push(e.iq.outerHTML);
}
_converse.api.alert('error', __('Error'), err_msgs);
api.alert('error', __('Error'), err_msgs);
log.error(e);
} else if (e.user_facing) {
_converse.api.alert('error', __('Error'), [e.message]);
api.alert('error', __('Error'), [e.message]);
log.error(e);
} else {
throw e;
......@@ -471,7 +472,7 @@ converse.plugins.add('converse-omemo', {
this.model.contact.getDisplayName()
)];
}
return _converse.api.alert('error', __('Error'), messages);
return api.alert('error', __('Error'), messages);
}
ev.preventDefault();
this.model.save({'omemo_active': !this.model.get('omemo_active')});
......@@ -500,7 +501,7 @@ converse.plugins.add('converse-omemo', {
}
async function getDevicesForContact (jid) {
await _converse.api.waitUntil('OMEMOInitialized');
await api.waitUntil('OMEMOInitialized');
const devicelist = _converse.devicelists.get(jid) || _converse.devicelists.create({'jid': jid});
await devicelist.fetchDevices();
return devicelist.devices;
......@@ -828,7 +829,7 @@ converse.plugins.add('converse-omemo', {
Object.values(this.get('prekeys')).forEach((prekey, id) => item.c('preKeyPublic', {'preKeyId': id}).t(prekey.pubKey).up());
const options = {'pubsub#access_model': 'open'};
return _converse.api.pubsub.publish(null, node, item, options, false);
return api.pubsub.publish(null, node, item, options, false);
},
async generateMissingPreKeys () {
......@@ -933,7 +934,7 @@ converse.plugins.add('converse-omemo', {
let iq;
try {
iq = await _converse.api.sendIQ(stanza)
iq = await api.sendIQ(stanza)
} catch (iq) {
throw new IQError("Could not fetch bundle", iq);
}
......@@ -1037,7 +1038,7 @@ converse.plugins.add('converse-omemo', {
let iq;
try {
iq = await _converse.api.sendIQ(stanza);
iq = await api.sendIQ(stanza);
} catch (e) {
log.error(e);
return [];
......@@ -1054,7 +1055,7 @@ converse.plugins.add('converse-omemo', {
const item = $build('item').c('list', {'xmlns': Strophe.NS.OMEMO})
this.devices.filter(d => d.get('active')).forEach(d => item.c('device', {'id': d.get('id')}).up());
const options = {'pubsub#access_model': 'open'};
return _converse.api.pubsub.publish(null, Strophe.NS.OMEMO_DEVICELIST, item, options, false);
return api.pubsub.publish(null, Strophe.NS.OMEMO_DEVICELIST, item, options, false);
},
removeOwnDevices (device_ids) {
......@@ -1193,7 +1194,7 @@ converse.plugins.add('converse-omemo', {
* @event _converse#OMEMOInitialized
* @example _converse.api.listen.on('OMEMOInitialized', () => { ... });
*/
_converse.api.trigger('OMEMOInitialized');
api.trigger('OMEMOInitialized');
}
async function onOccupantAdded (chatroom, occupant) {
......@@ -1216,20 +1217,20 @@ converse.plugins.add('converse-omemo', {
async function checkOMEMOSupported (chatbox) {
let supported;
if (chatbox.get('type') === _converse.CHATROOMS_TYPE) {
await _converse.api.waitUntil('OMEMOInitialized');
await api.waitUntil('OMEMOInitialized');
supported = chatbox.features.get('nonanonymous') && chatbox.features.get('membersonly');
} else if (chatbox.get('type') === _converse.PRIVATE_CHAT_TYPE) {
supported = await _converse.contactHasOMEMOSupport(chatbox.get('jid'));
}
chatbox.set('omemo_supported', supported);
if (supported && _converse.api.settings.get('omemo_default')) {
if (supported && api.settings.get('omemo_default')) {
chatbox.set('omemo_active', true);
}
}
/******************** Event Handlers ********************/
_converse.api.waitUntil('chatBoxesInitialized').then(() =>
api.waitUntil('chatBoxesInitialized').then(() =>
_converse.chatboxes.on('add', chatbox => {
checkOMEMOSupported(chatbox);
if (chatbox.get('type') === _converse.CHATROOMS_TYPE) {
......@@ -1239,24 +1240,24 @@ converse.plugins.add('converse-omemo', {
})
);
_converse.api.listen.on('connected', registerPEPPushHandler);
_converse.api.listen.on('renderToolbar', view => view.renderOMEMOToolbarButton());
_converse.api.listen.on('statusInitialized', initOMEMO);
_converse.api.listen.on('addClientFeatures',
() => _converse.api.disco.own.features.add(`${Strophe.NS.OMEMO_DEVICELIST}+notify`));
api.listen.on('connected', registerPEPPushHandler);
api.listen.on('renderToolbar', view => view.renderOMEMOToolbarButton());
api.listen.on('statusInitialized', initOMEMO);
api.listen.on('addClientFeatures',
() => api.disco.own.features.add(`${Strophe.NS.OMEMO_DEVICELIST}+notify`));
_converse.api.listen.on('userDetailsModalInitialized', (contact) => {
api.listen.on('userDetailsModalInitialized', (contact) => {
const jid = contact.get('jid');
_converse.generateFingerprints(jid).catch(e => log.error(e));
});
_converse.api.listen.on('profileModalInitialized', () => {
api.listen.on('profileModalInitialized', () => {
_converse.generateFingerprints(_converse.bare_jid).catch(e => log.error(e));
});
_converse.api.listen.on('afterTearDown', () => (delete _converse.omemo_store));
api.listen.on('afterTearDown', () => (delete _converse.omemo_store));
_converse.api.listen.on('clearSession', () => {
api.listen.on('clearSession', () => {
if (_converse.shouldClearCache() && _converse.devicelists) {
_converse.devicelists.clearStore();
delete _converse.devicelists;
......
......@@ -27,10 +27,11 @@ converse.plugins.add('converse-profile', {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this,
{ __ } = _converse;
const { _converse } = this;
const { api } = _converse;
const { __ } = _converse;
_converse.api.settings.update({
api.settings.update({
'show_client_info': true
});
......@@ -52,7 +53,7 @@ converse.plugins.add('converse-profile', {
* @type { _converse.XMPPStatus }
* @example _converse.api.listen.on('profileModalInitialized', status => { ... });
*/
_converse.api.trigger('profileModalInitialized', this.model);
api.trigger('profileModalInitialized', this.model);
},
toHTML () {
......@@ -84,11 +85,11 @@ converse.plugins.add('converse-profile', {
},
setVCard (data) {
_converse.api.vcard.set(_converse.bare_jid, data)
.then(() => _converse.api.vcard.update(this.model.vcard, true))
api.vcard.set(_converse.bare_jid, data)
.then(() => api.vcard.update(this.model.vcard, true))
.catch((err) => {
log.fatal(err);
_converse.api.show('error', __('Error'), [
api.show('error', __('Error'), [
__("Sorry, an error happened while trying to save your profile data."),
__("You can check your browser's developer console for any error output.")
]);
......@@ -251,7 +252,7 @@ converse.plugins.add('converse-profile', {
ev.preventDefault();
const result = confirm(__("Are you sure you want to log out?"));
if (result === true) {
_converse.api.user.logout();
api.user.logout();
}
},
......@@ -274,8 +275,8 @@ converse.plugins.add('converse-profile', {
/******************** Event Handlers ********************/
_converse.api.listen.on('controlBoxPaneInitialized', async view => {
await _converse.api.waitUntil('VCardsInitialized');
api.listen.on('controlBoxPaneInitialized', async view => {
await api.waitUntil('VCardsInitialized');
_converse.xmppstatusview = new _converse.XMPPStatusView({'model': _converse.xmppstatus});
view.el.insertAdjacentElement('afterBegin', _converse.xmppstatusview.render().el);
});
......
......@@ -22,8 +22,9 @@ converse.plugins.add('converse-push', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
_converse.api.settings.update({
api.settings.update({
'push_app_servers': [],
'enable_muc_push': false
});
......@@ -32,7 +33,7 @@ converse.plugins.add('converse-push', {
if (!push_app_server.jid) {
return;
}
if (!(await _converse.api.disco.supports(Strophe.NS.PUSH, domain || _converse.bare_jid))) {
if (!(await api.disco.supports(Strophe.NS.PUSH, domain || _converse.bare_jid))) {
log.warn(`Not disabling push app server "${push_app_server.jid}", no disco support from your server.`);
return;
}
......@@ -47,7 +48,7 @@ converse.plugins.add('converse-push', {
if (push_app_server.node) {
stanza.attrs({'node': push_app_server.node});
}
_converse.api.sendIQ(stanza)
api.sendIQ(stanza)
.catch(e => {
log.error(`Could not disable push app server for ${push_app_server.jid}`);
log.error(e);
......@@ -58,15 +59,15 @@ converse.plugins.add('converse-push', {
if (!push_app_server.jid || !push_app_server.node) {
return;
}
const identity = await _converse.api.disco.getIdentity('pubsub', 'push', push_app_server.jid);
const identity = await api.disco.getIdentity('pubsub', 'push', push_app_server.jid);
if (!identity) {
return log.warn(
`Not enabling push the service "${push_app_server.jid}", it doesn't have the right disco identtiy.`
);
}
const result = await Promise.all([
_converse.api.disco.supports(Strophe.NS.PUSH, push_app_server.jid),
_converse.api.disco.supports(Strophe.NS.PUSH, domain)
api.disco.supports(Strophe.NS.PUSH, push_app_server.jid),
api.disco.supports(Strophe.NS.PUSH, domain)
]);
if (!result[0] && !result[1]) {
log.warn(`Not enabling push app server "${push_app_server.jid}", no disco support from your server.`);
......@@ -88,7 +89,7 @@ converse.plugins.add('converse-push', {
.c('field', {'var': 'secret'})
.c('value').t(push_app_server.secret);
}
return _converse.api.sendIQ(stanza);
return api.sendIQ(stanza);
}
async function enablePush (domain) {
......@@ -97,8 +98,8 @@ converse.plugins.add('converse-push', {
if (push_enabled.includes(domain)) {
return;
}
const enabled_services = reject(_converse.api.settings.get('push_app_servers'), 'disable');
const disabled_services = filter(_converse.api.settings.get('push_app_servers'), 'disable');
const enabled_services = reject(api.settings.get('push_app_servers'), 'disable');
const disabled_services = filter(api.settings.get('push_app_servers'), 'disable');
const enabled = enabled_services.map(s => enablePushAppServer(domain, s));
const disabled = disabled_services.map(s => disablePushAppServer(domain, s));
try {
......@@ -111,15 +112,15 @@ converse.plugins.add('converse-push', {
}
_converse.session.save('push_enabled', push_enabled);
}
_converse.api.listen.on('statusInitialized', () => enablePush());
api.listen.on('statusInitialized', () => enablePush());
function onChatBoxAdded (model) {
if (model.get('type') == _converse.CHATROOMS_TYPE) {
enablePush(Strophe.getDomainFromJid(model.get('jid')));
}
}
if (_converse.api.settings.get('enable_muc_push')) {
_converse.api.listen.on('chatBoxesInitialized', () => _converse.chatboxes.on('add', onChatBoxAdded));
if (api.settings.get('enable_muc_push')) {
api.listen.on('chatBoxesInitialized', () => _converse.chatboxes.on('add', onChatBoxAdded));
}
}
});
......
......@@ -7,6 +7,7 @@
* @license Mozilla Public License (MPLv2)
*/
import "converse-controlbox";
import { __ } from '@converse/headless/i18n';
import { View } from "skeletor.js/src/view";
import { pick } from "lodash";
import converse from "@converse/headless/converse-core";
......@@ -63,15 +64,15 @@ converse.plugins.add('converse-register', {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this,
{ __ } = _converse;
const { _converse } = this;
const { api } = _converse;
_converse.CONNECTION_STATUS[Strophe.Status.REGIFAIL] = 'REGIFAIL';
_converse.CONNECTION_STATUS[Strophe.Status.REGISTERED] = 'REGISTERED';
_converse.CONNECTION_STATUS[Strophe.Status.CONFLICT] = 'CONFLICT';
_converse.CONNECTION_STATUS[Strophe.Status.NOTACCEPTABLE] = 'NOTACCEPTABLE';
_converse.api.settings.update({
api.settings.update({
'allow_registration': true,
'domain_placeholder': __(" e.g. conversejs.org"), // Placeholder text shown in the domain input on the registration form
'providers_link': 'https://compliance.conversations.im/', // Link to XMPP providers shown on registration page
......@@ -95,7 +96,7 @@ converse.plugins.add('converse-register', {
},
renderRegistrationPanel () {
if (_converse.api.settings.get('allow_registration')) {
if (api.settings.get('allow_registration')) {
this.registerpanel = new _converse.RegisterPanel({
'model': this.model
});
......@@ -113,7 +114,7 @@ converse.plugins.add('converse-register', {
function setActiveForm (value) {
_converse.api.waitUntil('controlBoxInitialized').then(() => {
api.waitUntil('controlBoxInitialized').then(() => {
const controlbox = _converse.chatboxes.get('controlbox')
controlbox.set({'active-form': value});
}).catch(e => log.fatal(e));
......@@ -138,22 +139,22 @@ converse.plugins.add('converse-register', {
initialize () {
this.reset();
_converse.api.listen.on('connectionInitialized', () => this.registerHooks());
api.listen.on('connectionInitialized', () => this.registerHooks());
},
render () {
this.model.set('registration_form_rendered', false);
this.el.innerHTML = tpl_register_panel({
'__': __,
'default_domain': _converse.api.settings.get('registration_domain'),
'default_domain': api.settings.get('registration_domain'),
'label_register': __('Fetch registration form'),
'help_providers': __('Tip: A list of public XMPP providers is available'),
'help_providers_link': __('here'),
'href_providers': _converse.api.settings.get('providers_link'),
'domain_placeholder': _converse.api.settings.get('domain_placeholder')
'href_providers': api.settings.get('providers_link'),
'domain_placeholder': api.settings.get('domain_placeholder')
});
if (_converse.api.settings.get('registration_domain')) {
this.fetchRegistrationForm(_converse.api.settings.get('registration_domain'));
if (api.settings.get('registration_domain')) {
this.fetchRegistrationForm(api.settings.get('registration_domain'));
}
return this;
},
......@@ -324,7 +325,7 @@ converse.plugins.add('converse-register', {
'beforeend',
tpl_registration_request({
'__': _converse.__,
'cancel': _converse.api.settings.get('registration_domain'),
'cancel': api.settings.get('registration_domain'),
})
);
},
......@@ -447,11 +448,11 @@ converse.plugins.add('converse-register', {
renderRegistrationForm (stanza) {
const form = this.el.querySelector('form');
form.innerHTML = tpl_registration_form({
'__': _converse.__,
'__': __,
'domain': this.domain,
'title': this.title,
'instructions': this.instructions,
'registration_domain': _converse.api.settings.get('registration_domain')
'registration_domain': api.settings.get('registration_domain')
});
const buttons = form.querySelector('fieldset.buttons');
......@@ -522,9 +523,9 @@ converse.plugins.add('converse-register', {
_converse.connection._proto._abortAllRequests();
_converse.connection.reset();
if (this.model.get('registration_form_rendered')) {
if (_converse.api.settings.get('registration_domain') && this.model.get('registration_form_rendered')) {
if (api.settings.get('registration_domain') && this.model.get('registration_form_rendered')) {
this.fetchRegistrationForm(
_converse.api.settings.get('registration_domain')
api.settings.get('registration_domain')
);
}
} else {
......@@ -645,7 +646,7 @@ converse.plugins.add('converse-register', {
});
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('controlBoxInitialized', view => {
api.listen.on('controlBoxInitialized', view => {
view.model.on('change:active-form', view.showLoginOrRegisterForm, view);
});
/************************ END Event Handlers ************************/
......
......@@ -38,9 +38,10 @@ converse.plugins.add('converse-roomslist', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
// Promises exposed by this plugin
_converse.api.promises.add('roomsListInitialized');
api.promises.add('roomsListInitialized');
_converse.RoomsList = Model.extend({
......@@ -121,8 +122,8 @@ converse.plugins.add('converse-roomslist', {
const data = {
'name': name || Strophe.unescapeNode(Strophe.getNodeFromJid(jid)) || jid
}
await _converse.api.rooms.open(jid, data, true);
_converse.api.chatviews.get(jid).maybeFocus();
await api.rooms.open(jid, data, true);
api.chatviews.get(jid).maybeFocus();
},
closeRoom (ev) {
......@@ -164,22 +165,22 @@ converse.plugins.add('converse-roomslist', {
* @event _converse#roomsListInitialized
* @example _converse.api.listen.on('roomsListInitialized', status => { ... });
*/
_converse.api.trigger('roomsListInitialized');
api.trigger('roomsListInitialized');
};
_converse.api.listen.on('connected', async () => {
api.listen.on('connected', async () => {
if (_converse.allow_bookmarks) {
await _converse.api.waitUntil('bookmarksInitialized');
await api.waitUntil('bookmarksInitialized');
} else {
await Promise.all([
_converse.api.waitUntil('chatBoxesFetched'),
_converse.api.waitUntil('roomsPanelRendered')
api.waitUntil('chatBoxesFetched'),
api.waitUntil('roomsPanelRendered')
]);
}
initRoomsListView();
});
_converse.api.listen.on('reconnected', initRoomsListView);
api.listen.on('reconnected', initRoomsListView);
}
});
This diff is collapsed.
......@@ -60,20 +60,21 @@ converse.plugins.add('converse-bookmarks', {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this,
{ __ } = _converse;
const { _converse } = this;
const { api } = _converse;
const { __ } = _converse;
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
_converse.api.settings.update({
api.settings.update({
allow_bookmarks: true,
allow_public_bookmarks: false,
muc_respect_autojoin: true
});
_converse.api.promises.add('bookmarksInitialized');
api.promises.add('bookmarksInitialized');
/**
* Check if the user has a bookmark with a saved nickanme
......@@ -82,7 +83,7 @@ converse.plugins.add('converse-bookmarks', {
* @method _converse#getNicknameFromBookmark
*/
_converse.getNicknameFromBookmark = function (jid) {
if (!_converse.bookmarks || !_converse.api.settings.get('allow_bookmarks')) {
if (!_converse.bookmarks || !api.settings.get('allow_bookmarks')) {
return null;
}
const bookmark = _converse.bookmarks.findWhere({'jid': jid});
......@@ -116,8 +117,8 @@ converse.plugins.add('converse-bookmarks', {
},
async openBookmarkedRoom (bookmark) {
if ( _converse.api.settings.get('muc_respect_autojoin') && bookmark.get('autojoin')) {
const groupchat = await _converse.api.rooms.create(bookmark.get('jid'), bookmark.get('nick'));
if ( api.settings.get('muc_respect_autojoin') && bookmark.get('autojoin')) {
const groupchat = await api.rooms.create(bookmark.get('jid'), bookmark.get('nick'));
groupchat.maybeShow();
}
return bookmark;
......@@ -166,13 +167,13 @@ converse.plugins.add('converse-bookmarks', {
.c('value').t('true').up().up()
.c('field', {'var':'pubsub#access_model'})
.c('value').t('whitelist');
return _converse.api.sendIQ(stanza);
return api.sendIQ(stanza);
},
onBookmarkError (iq, options) {
log.error("Error while trying to add bookmark");
log.error(iq);
_converse.api.alert(
api.alert(
'error', __('Error'), [__("Sorry, something went wrong while trying to save your bookmark.")]
);
this.findWhere({'jid': options.jid}).destroy();
......@@ -184,7 +185,7 @@ converse.plugins.add('converse-bookmarks', {
'type': 'get',
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'});
_converse.api.sendIQ(stanza)
api.sendIQ(stanza)
.then(iq => this.onBookmarksReceived(deferred, iq))
.catch(iq => this.onBookmarksReceivedError(deferred, iq)
);
......@@ -231,7 +232,7 @@ converse.plugins.add('converse-bookmarks', {
onBookmarksReceivedError (deferred, iq) {
if (iq === null) {
log.error('Error: timeout while fetching bookmarks');
_converse.api.alert('error', __('Timeout Error'),
api.alert('error', __('Timeout Error'),
[__("The server did not return your bookmarks within the allowed time. "+
"You can reload the page to request them again.")]
);
......@@ -263,16 +264,16 @@ converse.plugins.add('converse-bookmarks', {
});
_converse.checkBookmarksSupport = async function () {
const identity = await _converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid);
const identity = await api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid);
if (_converse.allow_public_bookmarks) {
return !!identity;
} else {
return _converse.api.disco.supports(Strophe.NS.PUBSUB+'#publish-options', _converse.bare_jid);
return api.disco.supports(Strophe.NS.PUBSUB+'#publish-options', _converse.bare_jid);
}
}
const initBookmarks = async function () {
if (!_converse.api.settings.get('allow_bookmarks')) {
if (!api.settings.get('allow_bookmarks')) {
return;
}
if (await _converse.checkBookmarksSupport()) {
......@@ -284,11 +285,11 @@ converse.plugins.add('converse-bookmarks', {
* @event _converse#bookmarksInitialized
* @example _converse.api.listen.on('bookmarksInitialized', () => { ... });
*/
_converse.api.trigger('bookmarksInitialized');
api.trigger('bookmarksInitialized');
}
}
_converse.api.listen.on('clearSession', () => {
api.listen.on('clearSession', () => {
if (_converse.bookmarks !== undefined) {
_converse.bookmarks.clearStore({'silent': true});
window.sessionStorage.removeItem(_converse.bookmarks.fetched_flag);
......@@ -296,19 +297,19 @@ converse.plugins.add('converse-bookmarks', {
}
});
_converse.api.listen.on('reconnected', initBookmarks);
api.listen.on('reconnected', initBookmarks);
_converse.api.listen.on('connected', async () => {
api.listen.on('connected', async () => {
// Add a handler for bookmarks pushed from other connected clients
_converse.connection.addHandler(message => {
if (sizzle('event[xmlns="'+Strophe.NS.PUBSUB+'#event"] items[node="storage:bookmarks"]', message).length) {
_converse.api.waitUntil('bookmarksInitialized')
api.waitUntil('bookmarksInitialized')
.then(() => _converse.bookmarks.createBookmarksFromStanza(message))
.catch(e => log.fatal(e));
}
}, null, 'message', 'headline', null, _converse.bare_jid);
await Promise.all([_converse.api.waitUntil('chatBoxesFetched')]);
await Promise.all([api.waitUntil('chatBoxesFetched')]);
initBookmarks();
});
}
......
......@@ -22,8 +22,9 @@ converse.plugins.add('converse-bosh', {
initialize () {
const { _converse } = this;
const { api } = _converse;
_converse.api.settings.update({
api.settings.update({
bosh_service_url: undefined,
prebind_url: null
});
......@@ -51,11 +52,11 @@ converse.plugins.add('converse-bosh', {
_converse.startNewPreboundBOSHSession = function () {
if (!_converse.api.settings.get('prebind_url')) {
if (!api.settings.get('prebind_url')) {
throw new Error("startNewPreboundBOSHSession: If you use prebind then you MUST supply a prebind_url");
}
const xhr = new XMLHttpRequest();
xhr.open('GET', _converse.api.settings.get('prebind_url'), true);
xhr.open('GET', api.settings.get('prebind_url'), true);
xhr.setRequestHeader('Accept', 'application/json, text/javascript');
xhr.onload = async function () {
if (xhr.status >= 200 && xhr.status < 400) {
......@@ -79,7 +80,7 @@ converse.plugins.add('converse-bosh', {
* @type { _converse }
* @example _converse.api.listen.on('noResumeableBOSHSession', _converse => { ... });
*/
_converse.api.trigger('noResumeableBOSHSession', _converse);
api.trigger('noResumeableBOSHSession', _converse);
};
xhr.send();
}
......@@ -101,7 +102,7 @@ converse.plugins.add('converse-bosh', {
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('clearSession', () => {
api.listen.on('clearSession', () => {
if (_converse.bosh_session === undefined) {
// Remove manually, even if we don't have the corresponding
// model, to avoid trying to reconnect to a stale BOSH session
......@@ -114,28 +115,28 @@ converse.plugins.add('converse-bosh', {
}
});
_converse.api.listen.on('setUserJID', () => {
api.listen.on('setUserJID', () => {
if (_converse.bosh_session !== undefined) {
_converse.bosh_session.save({'jid': _converse.jid});
}
});
_converse.api.listen.on('addClientFeatures', () => _converse.api.disco.own.features.add(Strophe.NS.BOSH));
api.listen.on('addClientFeatures', () => api.disco.own.features.add(Strophe.NS.BOSH));
/************************ END Event Handlers ************************/
/************************ BEGIN API ************************/
Object.assign(_converse.api, {
Object.assign(api, {
/**
* This namespace lets you access the BOSH tokens
*
* @namespace _converse.api.tokens
* @memberOf _converse.api
* @namespace api.tokens
* @memberOf api
*/
tokens: {
/**
* @method _converse.api.tokens.get
* @method api.tokens.get
* @param {string} [id] The type of token to return ('rid' or 'sid').
* @returns 'string' A token, either the RID or SID token depending on what's asked for.
* @example _converse.api.tokens.get('rid');
......
This diff is collapsed.
......@@ -26,8 +26,9 @@ converse.plugins.add('converse-chatboxes', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
_converse.api.promises.add([
api.promises.add([
'chatBoxesFetched',
'chatBoxesInitialized',
'privateChatsAutoJoined'
......@@ -78,7 +79,7 @@ converse.plugins.add('converse-chatboxes', {
* @example _converse.api.listen.on('message', obj => { ... });
* @example _converse.api.waitUntil('chatBoxesFetched').then(() => { ... });
*/
_converse.api.trigger('chatBoxesFetched');
api.trigger('chatBoxesFetched');
},
onConnected (reconnecting) {
......@@ -114,13 +115,13 @@ converse.plugins.add('converse-chatboxes', {
/************************ BEGIN Event Handlers ************************/
_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);
api.listen.on('addClientFeatures', () => {
api.disco.own.features.add(Strophe.NS.MESSAGE_CORRECT);
api.disco.own.features.add(Strophe.NS.HTTPUPLOAD);
api.disco.own.features.add(Strophe.NS.OUTOFBAND);
});
_converse.api.listen.on('pluginsInitialized', () => {
api.listen.on('pluginsInitialized', () => {
_converse.chatboxes = new _converse.ChatBoxes();
/**
* Triggered once the _converse.ChatBoxes collection has been initialized.
......@@ -128,32 +129,32 @@ converse.plugins.add('converse-chatboxes', {
* @example _converse.api.listen.on('chatBoxesInitialized', () => { ... });
* @example _converse.api.waitUntil('chatBoxesInitialized').then(() => { ... });
*/
_converse.api.trigger('chatBoxesInitialized');
api.trigger('chatBoxesInitialized');
});
_converse.api.listen.on('presencesInitialized', (reconnecting) => _converse.chatboxes.onConnected(reconnecting));
_converse.api.listen.on('reconnected', () => _converse.chatboxes.forEach(m => m.onReconnection()));
_converse.api.listen.on('windowStateChanged', d => (d.state === 'visible') && _converse.clearMsgCounter());
api.listen.on('presencesInitialized', (reconnecting) => _converse.chatboxes.onConnected(reconnecting));
api.listen.on('reconnected', () => _converse.chatboxes.forEach(m => m.onReconnection()));
api.listen.on('windowStateChanged', d => (d.state === 'visible') && _converse.clearMsgCounter());
/************************ END Event Handlers ************************/
/************************ BEGIN API ************************/
Object.assign(_converse.api, {
Object.assign(api, {
/**
* The "chatboxes" namespace.
*
* @namespace _converse.api.chatboxes
* @memberOf _converse.api
* @namespace api.chatboxes
* @memberOf api
*/
chatboxes: {
/**
* @method _converse.api.chats.create
* @method api.chats.create
* @param { String|String[] } jids - A JID or array of JIDs
* @param { Object } [attrs] An object containing configuration attributes
* @param { Model } model - The type of chatbox that should be created
*/
async create (jids=[], attrs={}, model) {
await _converse.api.waitUntil('chatBoxesFetched');
await api.waitUntil('chatBoxesFetched');
if (isString(jids)) {
return createChatBox(jids, attrs, model);
} else {
......@@ -162,11 +163,11 @@ converse.plugins.add('converse-chatboxes', {
},
/**
* @method _converse.api.chats.get
* @method api.chats.get
* @param { String|String[] } jids - A JID or array of JIDs
*/
async get (jids) {
await _converse.api.waitUntil('chatBoxesFetched');
await api.waitUntil('chatBoxesFetched');
if (jids === undefined) {
return _converse.chatboxes.models;
} else if (isString(jids)) {
......
This diff is collapsed.
......@@ -61,9 +61,10 @@ converse.plugins.add('converse-emoji', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
const { ___ } = _converse;
_converse.api.settings.update({
api.settings.update({
'emoji_image_path': twemoji.default.base,
'emoji_categories': {
"smileys": ":grinning:",
......@@ -98,8 +99,8 @@ converse.plugins.add('converse-emoji', {
});
_converse.emojis = {};
_converse.api.promises.add('emojisInitialized', false);
twemoji.default.base = _converse.api.settings.get('emoji_image_path');
api.promises.add('emojisInitialized', false);
twemoji.default.base = api.settings.get('emoji_image_path');
/**
......@@ -162,7 +163,7 @@ converse.plugins.add('converse-emoji', {
}
};
const transform = u.shortnamesToEmojis;
return _converse.api.settings.get('use_system_emojis') ? transform : text => twemoji.default.parse(transform(text), how);
return api.settings.get('use_system_emojis') ? transform : text => twemoji.default.parse(transform(text), how);
},
/**
......@@ -263,18 +264,18 @@ converse.plugins.add('converse-emoji', {
/************************ BEGIN API ************************/
// We extend the default converse.js API to add methods specific to MUC groupchats.
Object.assign(_converse.api, {
Object.assign(api, {
/**
* The "rooms" namespace groups methods relevant to chatrooms
* (aka groupchats).
*
* @namespace _converse.api.rooms
* @memberOf _converse.api
* @namespace api.rooms
* @memberOf api
*/
emojis: {
/**
* Initializes Emoji support by downloading the emojis JSON (and any applicable images).
* @method _converse.api.emojis.initialize
* @method api.emojis.initialize
* @returns {Promise}
*/
async initialize () {
......@@ -300,7 +301,7 @@ converse.plugins.add('converse-emoji', {
* fetched and its save to start calling emoji utility methods.
* @event _converse#emojisInitialized
*/
_converse.api.trigger('emojisInitialized');
api.trigger('emojisInitialized');
}
}
});
......
......@@ -47,6 +47,7 @@ converse.plugins.add('converse-headlines', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
/**
* Shows headline messages
......@@ -58,7 +59,7 @@ converse.plugins.add('converse-headlines', {
defaults () {
return {
'bookmarked': false,
'hidden': ['mobile', 'fullscreen'].includes(_converse.api.settings.get("view_mode")),
'hidden': ['mobile', 'fullscreen'].includes(api.settings.get("view_mode")),
'message_type': 'headline',
'num_unread': 0,
'time_opened': this.get('time_opened') || (new Date()).getTime(),
......@@ -75,7 +76,7 @@ converse.plugins.add('converse-headlines', {
* @type { _converse.HeadlinesBox }
* @example _converse.api.listen.on('headlinesBoxInitialized', model => { ... });
*/
_converse.api.trigger('headlinesBoxInitialized', this);
api.trigger('headlinesBoxInitialized', this);
}
});
......@@ -85,7 +86,7 @@ converse.plugins.add('converse-headlines', {
const from_jid = message.getAttribute('from');
if (from_jid.includes('@') &&
!_converse.roster.get(from_jid) &&
!_converse.api.settings.get("allow_non_roster_messaging")) {
!api.settings.get("allow_non_roster_messaging")) {
return;
}
if (message.querySelector('body') === null) {
......@@ -100,7 +101,7 @@ converse.plugins.add('converse-headlines', {
});
const attrs = await chatbox.getMessageAttributesFromStanza(message, message);
await chatbox.createMessage(attrs);
_converse.api.trigger('message', {'chatbox': chatbox, 'stanza': message});
api.trigger('message', {'chatbox': chatbox, 'stanza': message});
}
}
......@@ -112,26 +113,26 @@ converse.plugins.add('converse-headlines', {
return true
}, null, 'message');
}
_converse.api.listen.on('connected', registerHeadlineHandler);
_converse.api.listen.on('reconnected', registerHeadlineHandler);
api.listen.on('connected', registerHeadlineHandler);
api.listen.on('reconnected', registerHeadlineHandler);
/************************ END Event Handlers ************************/
/************************ BEGIN API ************************/
Object.assign(_converse.api, {
Object.assign(api, {
/**
* The "headlines" namespace, which is used for headline-channels
* which are read-only channels containing messages of type
* "headline".
*
* @namespace _converse.api.headlines
* @memberOf _converse.api
* @namespace api.headlines
* @memberOf api
*/
headlines: {
/**
* Retrieves a headline-channel or all headline-channels.
*
* @method _converse.api.headlines.get
* @method api.headlines.get
* @param {String|String[]} jids - e.g. 'buddy@example.com' or ['buddy1@example.com', 'buddy2@example.com']
* @param {Object} [attrs] - Attributes to be set on the _converse.ChatBox model.
* @param {Boolean} [create=false] - Whether the chat should be created if it's not found.
......@@ -139,9 +140,9 @@ converse.plugins.add('converse-headlines', {
*/
async get (jids, attrs={}, create=false) {
async function _get (jid) {
let model = await _converse.api.chatboxes.get(jid);
let model = await api.chatboxes.get(jid);
if (!model && create) {
model = await _converse.api.chatboxes.create(jid, attrs, _converse.HeadlinesBox);
model = await api.chatboxes.create(jid, attrs, _converse.HeadlinesBox);
} else {
model = (model && model.get('type') === _converse.HEADLINES_TYPE) ? model : null;
if (model && Object.keys(attrs).length) {
......@@ -151,7 +152,7 @@ converse.plugins.add('converse-headlines', {
return model;
}
if (jids === undefined) {
const chats = await _converse.api.chatboxes.get();
const chats = await api.chatboxes.get();
return chats.filter(c => (c.get('type') === _converse.HEADLINES_TYPE));
} else if (isString(jids)) {
return _get(jids);
......
This diff is collapsed.
This diff is collapsed.
......@@ -22,9 +22,11 @@ converse.plugins.add('converse-ping', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
let lastStanzaDate;
_converse.api.settings.update({
api.settings.update({
ping_interval: 60 //in seconds
});
......@@ -39,14 +41,14 @@ converse.plugins.add('converse-ping', {
function registerPongHandler () {
if (_converse.connection.disco !== undefined) {
_converse.api.disco.own.features.add(Strophe.NS.PING);
api.disco.own.features.add(Strophe.NS.PING);
}
return _converse.connection.addHandler(pong, Strophe.NS.PING, "iq", "get");
}
function registerPingHandler () {
_converse.connection.addHandler(() => {
if (_converse.api.settings.get('ping_interval') > 0) {
if (api.settings.get('ping_interval') > 0) {
// Handler on each stanza, saves the received date
// in order to ping only when needed.
lastStanzaDate = new Date();
......@@ -56,13 +58,13 @@ converse.plugins.add('converse-ping', {
}
setTimeout(() => {
if (_converse.api.settings.get('ping_interval') > 0) {
if (api.settings.get('ping_interval') > 0) {
const now = new Date();
if (!lastStanzaDate) {
lastStanzaDate = now;
}
if ((now - lastStanzaDate)/1000 > _converse.api.settings.get('ping_interval')) {
return _converse.api.ping();
if ((now - lastStanzaDate)/1000 > api.settings.get('ping_interval')) {
return api.ping();
}
return true;
}
......@@ -75,25 +77,25 @@ converse.plugins.add('converse-ping', {
registerPongHandler();
registerPingHandler();
};
_converse.api.listen.on('connected', onConnected);
_converse.api.listen.on('reconnected', onConnected);
api.listen.on('connected', onConnected);
api.listen.on('reconnected', onConnected);
function onWindowStateChanged (data) {
if (data.state === 'visible' && _converse.api.connection.connected()) {
_converse.api.ping(null, 5000);
if (data.state === 'visible' && api.connection.connected()) {
api.ping(null, 5000);
}
}
_converse.api.listen.on('windowStateChanged', onWindowStateChanged);
api.listen.on('windowStateChanged', onWindowStateChanged);
/************************ END Event Handlers ************************/
/************************ BEGIN API ************************/
Object.assign(_converse.api, {
Object.assign(api, {
/**
* Pings the service represented by the passed in JID by sending an IQ stanza.
* @private
* @method _converse.api.ping
* @method api.ping
* @param { String } [jid] - The JID of the service to ping
* @param { Integer } [timeout] - The amount of time in
* milliseconds to wait for a response. The default is 10000;
......@@ -112,11 +114,11 @@ converse.plugins.add('converse-ping', {
'id': u.getUniqueId('ping')
}).c('ping', {'xmlns': Strophe.NS.PING});
const result = await _converse.api.sendIQ(iq, timeout || 10000, false);
const result = await api.sendIQ(iq, timeout || 10000, false);
if (result === null) {
log.warn(`Timeout while pinging ${jid}`);
if (jid === Strophe.getDomainFromJid(_converse.bare_jid)) {
_converse.api.connection.reconnect();
api.connection.reconnect();
}
} else if (u.isErrorStanza(result)) {
log.error(`Error while pinging ${jid}`);
......
......@@ -21,6 +21,7 @@ converse.plugins.add('converse-pubsub', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
/************************ BEGIN API ************************/
......@@ -58,7 +59,7 @@ converse.plugins.add('converse-pubsub', {
if (options) {
jid = jid || _converse.bare_jid;
if (await _converse.api.disco.supports(Strophe.NS.PUBSUB + '#publish-options', jid)) {
if (await api.disco.supports(Strophe.NS.PUBSUB + '#publish-options', jid)) {
stanza.c('publish-options')
.c('x', {'xmlns': Strophe.NS.XFORM, 'type': 'submit'})
.c('field', {'var': 'FORM_TYPE', 'type': 'hidden'})
......@@ -71,7 +72,7 @@ converse.plugins.add('converse-pubsub', {
}
}
try {
_converse.api.sendIQ(stanza);
api.sendIQ(stanza);
} catch (iq) {
if (iq instanceof Element &&
strict_options &&
......@@ -82,7 +83,7 @@ converse.plugins.add('converse-pubsub', {
const el = stanza.nodeTree;
el.querySelector('publish-options').outerHTML = '';
log.warn(`PubSub: Republishing without publish options. ${el.outerHTML}`);
_converse.api.sendIQ(el);
api.sendIQ(el);
} else {
throw iq;
}
......
This diff is collapsed.
......@@ -18,21 +18,22 @@ converse.plugins.add('converse-smacks', {
initialize () {
const { _converse } = this;
const { api } = _converse;
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
// configuration settings.
_converse.api.settings.update({
api.settings.update({
'enable_smacks': true,
'smacks_max_unacked_stanzas': 5,
});
function isStreamManagementSupported () {
if (_converse.api.connection.isType('bosh') && !_converse.isTestEnv()) {
if (api.connection.isType('bosh') && !_converse.isTestEnv()) {
return false;
}
return _converse.api.disco.stream.getFeature('sm', Strophe.NS.SM);
return api.disco.stream.getFeature('sm', Strophe.NS.SM);
}
function handleAck (el) {
......@@ -69,7 +70,7 @@ converse.plugins.add('converse-smacks', {
if (_converse.session.get('smacks_enabled')) {
const h = _converse.session.get('num_stanzas_handled');
const stanza = u.toStanza(`<a xmlns="${Strophe.NS.SM}" h="${h}"/>`);
_converse.api.send(stanza);
api.send(stanza);
}
return true;
}
......@@ -132,7 +133,7 @@ converse.plugins.add('converse-smacks', {
* Triggered when the XEP-0198 stream could not be resumed.
* @event _converse#streamResumptionFailed
*/
_converse.api.trigger('streamResumptionFailed');
api.trigger('streamResumptionFailed');
return true;
}
......@@ -158,7 +159,7 @@ converse.plugins.add('converse-smacks', {
// service worker or handling IQ[type="result"] stanzas
// differently, more like push stanzas, so that they don't need
// explicit handlers.
stanzas.forEach(s => _converse.api.send(s));
stanzas.forEach(s => api.send(s));
}
function onResumedStanza (el) {
......@@ -179,13 +180,13 @@ converse.plugins.add('converse-smacks', {
const previous_id = _converse.session.get('smacks_stream_id');
const h = _converse.session.get('num_stanzas_handled');
const stanza = u.toStanza(`<resume xmlns="${Strophe.NS.SM}" h="${h}" previd="${previous_id}"/>`);
_converse.api.send(stanza);
api.send(stanza);
_converse.connection.flush();
await promise;
}
async function sendEnableStanza () {
if (!_converse.api.settings.get('enable_smacks') || _converse.session.get('smacks_enabled')) {
if (!api.settings.get('enable_smacks') || _converse.session.get('smacks_enabled')) {
return;
}
if (await isStreamManagementSupported()) {
......@@ -193,16 +194,16 @@ converse.plugins.add('converse-smacks', {
_converse.connection._addSysHandler(el => promise.resolve(saveSessionData(el)), Strophe.NS.SM, 'enabled');
_converse.connection._addSysHandler(el => promise.resolve(onFailedStanza(el)), Strophe.NS.SM, 'failed');
const resume = (_converse.api.connection.isType('websocket') || _converse.isTestEnv());
const resume = (api.connection.isType('websocket') || _converse.isTestEnv());
const stanza = u.toStanza(`<enable xmlns="${Strophe.NS.SM}" resume="${resume}"/>`);
_converse.api.send(stanza);
api.send(stanza);
_converse.connection.flush();
await promise;
}
}
async function enableStreamManagement () {
if (!_converse.api.settings.get('enable_smacks')) {
if (!api.settings.get('enable_smacks')) {
return;
}
if (!(await isStreamManagementSupported())) {
......@@ -235,21 +236,21 @@ converse.plugins.add('converse-smacks', {
'unacked_stanzas',
(_converse.session.get('unacked_stanzas') || []).concat([stanza_string])
);
const max_unacked = _converse.api.settings.get('smacks_max_unacked_stanzas');
const max_unacked = api.settings.get('smacks_max_unacked_stanzas');
if (max_unacked > 0) {
const num = _converse.session.get('num_stanzas_since_last_ack') + 1;
if (num % max_unacked === 0) {
// Request confirmation of sent stanzas
_converse.api.send(u.toStanza(`<r xmlns="${Strophe.NS.SM}"/>`));
api.send(u.toStanza(`<r xmlns="${Strophe.NS.SM}"/>`));
}
_converse.session.save({'num_stanzas_since_last_ack': num});
}
}
}
_converse.api.listen.on('userSessionInitialized', initSessionData);
_converse.api.listen.on('beforeResourceBinding', enableStreamManagement);
_converse.api.listen.on('afterResourceBinding', sendEnableStanza);
_converse.api.listen.on('send', onStanzaSent);
api.listen.on('userSessionInitialized', initSessionData);
api.listen.on('beforeResourceBinding', enableStreamManagement);
api.listen.on('afterResourceBinding', sendEnableStanza);
api.listen.on('send', onStanzaSent);
}
});
......@@ -14,8 +14,9 @@ converse.plugins.add('converse-status', {
initialize () {
const { _converse } = this;
const { api } = _converse;
_converse.api.settings.update({
api.settings.update({
auto_away: 0, // Seconds after which user status is set to 'away'
auto_xa: 0, // Seconds after which user status is set to 'xa'
csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
......@@ -25,7 +26,7 @@ converse.plugins.add('converse-status', {
_converse.XMPPStatus = Model.extend({
defaults () {
return {"status": _converse.api.settings.get("default_state")}
return {"status": api.settings.get("default_state")}
},
initialize () {
......@@ -50,7 +51,7 @@ converse.plugins.add('converse-status', {
constructPresence (type, status_message) {
let presence;
type = isString(type) ? type : (this.get('status') || _converse.api.settings.get("default_state"));
type = isString(type) ? type : (this.get('status') || api.settings.get("default_state"));
status_message = isString(status_message) ? status_message : this.get('status_message');
// Most of these presence types are actually not explicitly sent,
// but I add all of them here for reference and future proofing.
......@@ -73,7 +74,7 @@ converse.plugins.add('converse-status', {
presence.c('status').t(status_message).up();
}
const priority = _converse.api.settings.get("priority");
const priority = api.settings.get("priority");
presence.c('priority').t(isNaN(Number(priority)) ? 0 : priority).up();
if (_converse.idle) {
const idle_since = new Date();
......@@ -84,7 +85,7 @@ converse.plugins.add('converse-status', {
},
sendPresence (type, status_message) {
_converse.api.send(this.constructPresence(type, status_message));
api.send(this.constructPresence(type, status_message));
}
});
......@@ -97,7 +98,7 @@ converse.plugins.add('converse-status', {
* @param { String } stat - The user's chat status
*/
_converse.sendCSI = function (stat) {
_converse.api.send($build(stat, {xmlns: Strophe.NS.CSI}));
api.send($build(stat, {xmlns: Strophe.NS.CSI}));
_converse.inactive = (stat === _converse.INACTIVE) ? true : false;
};
......@@ -123,7 +124,7 @@ converse.plugins.add('converse-status', {
_converse.auto_changed_status = false;
// XXX: we should really remember the original state here, and
// then set it back to that...
_converse.xmppstatus.set('status', _converse.api.settings.get("default_state"));
_converse.xmppstatus.set('status', api.settings.get("default_state"));
}
};
......@@ -138,24 +139,24 @@ converse.plugins.add('converse-status', {
}
const stat = _converse.xmppstatus.get('status');
_converse.idle_seconds++;
if (_converse.api.settings.get("csi_waiting_time") > 0 &&
_converse.idle_seconds > _converse.api.settings.get("csi_waiting_time") &&
if (api.settings.get("csi_waiting_time") > 0 &&
_converse.idle_seconds > api.settings.get("csi_waiting_time") &&
!_converse.inactive) {
_converse.sendCSI(_converse.INACTIVE);
}
if (_converse.api.settings.get("idle_presence_timeout") > 0 &&
_converse.idle_seconds > _converse.api.settings.get("idle_presence_timeout") &&
if (api.settings.get("idle_presence_timeout") > 0 &&
_converse.idle_seconds > api.settings.get("idle_presence_timeout") &&
!_converse.idle) {
_converse.idle = true;
_converse.xmppstatus.sendPresence();
}
if (_converse.api.settings.get("auto_away") > 0 &&
_converse.idle_seconds > _converse.api.settings.get("auto_away") &&
if (api.settings.get("auto_away") > 0 &&
_converse.idle_seconds > api.settings.get("auto_away") &&
stat !== 'away' && stat !== 'xa' && stat !== 'dnd') {
_converse.auto_changed_status = true;
_converse.xmppstatus.set('status', 'away');
} else if (_converse.api.settings.get("auto_xa") > 0 &&
_converse.idle_seconds > _converse.api.settings.get("auto_xa") &&
} else if (api.settings.get("auto_xa") > 0 &&
_converse.idle_seconds > api.settings.get("auto_xa") &&
stat !== 'xa' && stat !== 'dnd') {
_converse.auto_changed_status = true;
_converse.xmppstatus.set('status', 'xa');
......@@ -167,10 +168,10 @@ converse.plugins.add('converse-status', {
* Required for the auto_away, auto_xa and csi_waiting_time features.
*/
if (
_converse.api.settings.get("auto_away") < 1 &&
_converse.api.settings.get("auto_xa") < 1 &&
_converse.api.settings.get("csi_waiting_time") < 1 &&
_converse.api.settings.get("idle_presence_timeout") < 1
api.settings.get("auto_away") < 1 &&
api.settings.get("auto_xa") < 1 &&
api.settings.get("csi_waiting_time") < 1 &&
api.settings.get("idle_presence_timeout") < 1
) {
// Waiting time of less then one second means features aren't used.
return;
......@@ -192,7 +193,7 @@ converse.plugins.add('converse-status', {
};
_converse.api.listen.on('presencesInitialized', (reconnecting) => {
api.listen.on('presencesInitialized', (reconnecting) => {
if (!reconnecting) {
_converse.registerIntervalHandler();
}
......@@ -206,7 +207,7 @@ converse.plugins.add('converse-status', {
* @example _converse.api.listen.on('statusInitialized', status => { ... });
* @example _converse.api.waitUntil('statusInitialized').then(() => { ... });
*/
_converse.api.trigger('statusInitialized', reconnecting);
api.trigger('statusInitialized', reconnecting);
}
......@@ -230,15 +231,15 @@ converse.plugins.add('converse-status', {
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('clearSession', () => {
api.listen.on('clearSession', () => {
if (_converse.shouldClearCache() && _converse.xmppstatus) {
_converse.xmppstatus.destroy();
delete _converse.xmppstatus;
}
});
_converse.api.listen.on('connected', () => initStatus(false));
_converse.api.listen.on('reconnected', () => initStatus(true));
api.listen.on('connected', () => initStatus(false));
api.listen.on('reconnected', () => initStatus(true));
/************************ END Event Handlers ************************/
......
......@@ -65,8 +65,9 @@ converse.plugins.add('converse-vcard', {
* loaded by converse.js's plugin machinery.
*/
const { _converse } = this;
const { api } = _converse;
_converse.api.promises.add('VCardsInitialized');
api.promises.add('VCardsInitialized');
_converse.VCard = Model.extend({
......@@ -105,7 +106,7 @@ converse.plugins.add('converse-vcard', {
initialize () {
this.on('add', vcard => {
_converse.api.vcard.update(vcard);
api.vcard.update(vcard);
});
}
});
......@@ -152,7 +153,7 @@ converse.plugins.add('converse-vcard', {
const to = Strophe.getBareJidFromJid(jid) === _converse.bare_jid ? null : jid;
let iq;
try {
iq = await _converse.api.sendIQ(createStanza("get", to))
iq = await api.sendIQ(createStanza("get", to))
} catch (iq) {
return {
'stanza': iq,
......@@ -174,7 +175,7 @@ converse.plugins.add('converse-vcard', {
} else {
jid = model.get('jid');
}
await _converse.api.waitUntil('VCardsInitialized');
await api.waitUntil('VCardsInitialized');
model.vcard = _converse.vcards.findWhere({'jid': jid});
if (!model.vcard) {
model.vcard = _converse.vcards.create({'jid': jid});
......@@ -202,7 +203,7 @@ converse.plugins.add('converse-vcard', {
async function setVCardOnMUCMessage (message) {
await _converse.api.waitUntil('VCardsInitialized');
await api.waitUntil('VCardsInitialized');
if (['error', 'info'].includes(message.get('type'))) {
return;
} else {
......@@ -229,13 +230,13 @@ converse.plugins.add('converse-vcard', {
* Triggered as soon as the `_converse.vcards` collection has been initialized and populated from cache.
* @event _converse#VCardsInitialized
*/
_converse.api.trigger('VCardsInitialized');
api.trigger('VCardsInitialized');
}
function clearVCardsSession () {
if (_converse.shouldClearCache()) {
_converse.api.promises.add('VCardsInitialized');
api.promises.add('VCardsInitialized');
if (_converse.vcards) {
_converse.vcards.clearStore();
delete _converse.vcards;
......@@ -246,14 +247,14 @@ converse.plugins.add('converse-vcard', {
/************************ BEGIN Event Handlers ************************/
_converse.api.listen.on('chatBoxInitialized', m => setVCardOnModel(m));
_converse.api.listen.on('chatRoomInitialized', m => setVCardOnModel(m));
_converse.api.listen.on('chatRoomMessageInitialized', m => setVCardOnMUCMessage(m));
_converse.api.listen.on('addClientFeatures', () => _converse.api.disco.own.features.add(Strophe.NS.VCARD));
_converse.api.listen.on('clearSession', () => clearVCardsSession());
_converse.api.listen.on('messageInitialized', m => setVCardOnModel(m));
_converse.api.listen.on('rosterContactInitialized', m => setVCardOnModel(m));
_converse.api.listen.on('statusInitialized', _converse.initVCardCollection);
api.listen.on('chatBoxInitialized', m => setVCardOnModel(m));
api.listen.on('chatRoomInitialized', m => setVCardOnModel(m));
api.listen.on('chatRoomMessageInitialized', m => setVCardOnMUCMessage(m));
api.listen.on('addClientFeatures', () => api.disco.own.features.add(Strophe.NS.VCARD));
api.listen.on('clearSession', () => clearVCardsSession());
api.listen.on('messageInitialized', m => setVCardOnModel(m));
api.listen.on('rosterContactInitialized', m => setVCardOnModel(m));
api.listen.on('statusInitialized', _converse.initVCardCollection);
/************************ BEGIN API ************************/
......@@ -289,7 +290,7 @@ converse.plugins.add('converse-vcard', {
throw Error("No jid provided for the VCard data");
}
const vcard_el = Strophe.xmlHtmlNode(tpl_vcard(data)).firstElementChild;
return _converse.api.sendIQ(createStanza("set", jid, vcard_el));
return api.sendIQ(createStanza("set", jid, vcard_el));
},
/**
......
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