From 6573d080e403cf8134e8a8eedc073230fe4ecd78 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 13 May 2022 10:32:54 +0200 Subject: [PATCH] Message carbons - Remove the `converse-carbons` plugin and make carbons part of the `converse-chat` plugin. - Remove the `message_carbons` configuration setting. Carbons are now always enabled. --- CHANGES.md | 2 + docs/source/configuration.rst | 16 -------- src/headless/headless.js | 1 - src/headless/plugins/carbons.js | 61 ----------------------------- src/headless/plugins/chat/index.js | 33 +++++++--------- src/headless/plugins/chat/utils.js | 37 ++++++++++++++++- src/headless/plugins/disco/utils.js | 4 +- src/headless/shared/constants.js | 1 - 8 files changed, 54 insertions(+), 101 deletions(-) delete mode 100644 src/headless/plugins/carbons.js diff --git a/CHANGES.md b/CHANGES.md index 05d9be758..33efdef11 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,8 @@ - Don't automatically convert OpenStreetMap URLs into `geo:` URIs in sent messages - Remove the `allow_chat_pending_contacts` config option. - Show roster contacts with `subscription` set to `none` +- Remove the `converse-carbons` plugin and make carbons part of the `converse-chat` plugin. +- Remove the `message_carbons` configuration setting. Carbons are now always enabled. ## 9.1.1 (2022-05-05) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 2886c138c..307238708 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -1202,22 +1202,6 @@ from the XMPP server. Used in conjunction with ``message_archiving`` and in context of `XEP-0313: Message Archive Management `_. -message_carbons ---------------- - -* Default: ``true`` - -Support for `XEP-0280: Message Carbons `_ - -In order to keep all IM clients for a user engaged in a conversation, -outbound messages are carbon-copied to all interested resources. - -This is especially important with Converse, where each browser -tab serves as a separate IM client. - -XEP-0280 requires server support, so make sure that message carbons are enabled -on your server. - message_limit ------------- diff --git a/src/headless/headless.js b/src/headless/headless.js index 8794578e4..b2fee1957 100644 --- a/src/headless/headless.js +++ b/src/headless/headless.js @@ -6,7 +6,6 @@ import "./plugins/adhoc.js"; // XEP-0050 Ad Hoc Commands import "./plugins/bookmarks/index.js"; // XEP-0199 XMPP Ping import "./plugins/bosh.js"; // XEP-0206 BOSH import "./plugins/caps/index.js"; // XEP-0115 Entity Capabilities -import "./plugins/carbons.js"; // XEP-0280 Message Carbons import "./plugins/chat/index.js"; // RFC-6121 Instant messaging import "./plugins/chatboxes/index.js"; import "./plugins/disco/index.js"; // XEP-0030 Service discovery diff --git a/src/headless/plugins/carbons.js b/src/headless/plugins/carbons.js deleted file mode 100644 index 0d3f031e2..000000000 --- a/src/headless/plugins/carbons.js +++ /dev/null @@ -1,61 +0,0 @@ -/** - * @module converse-carbons - * @copyright The Converse.js contributors - * @license Mozilla Public License (MPLv2) - * @description Implements support for XEP-0280 Message Carbons - */ - -import log from '@converse/headless/log.js'; -import { Strophe } from 'strophe.js/src/strophe'; -import { _converse, api, converse } from "../core.js"; - -const { u } = converse.env; - - -/** - * Ask the XMPP server to enable Message Carbons - * See [XEP-0280](https://xmpp.org/extensions/xep-0280.html#enabling) - */ -async function enableCarbons (reconnecting) { - if (reconnecting && _converse.session.get('carbons_enabled')) { - if (_converse.session.get('smacks_enabled')) { - // No need to re-enable carbons when resuming a XEP-0198 stream - return; - } - _converse.session.set({'carbons_enabled': false}) - } - - if (!api.settings.get("message_carbons") || _converse.session?.get('carbons_enabled')) { - return; - } - - const iq = new Strophe.Builder('iq', { - 'from': _converse.connection.jid, - 'type': 'set' - }).c('enable', {xmlns: Strophe.NS.CARBONS}); - - const result = await api.sendIQ(iq, null, false); - if (result === null) { - log.warn(`A timeout occurred while trying to enable carbons`); - } else if (u.isErrorStanza(result)) { - log.warn('An error occurred while trying to enable message carbons.'); - log.error(result); - } else { - _converse.session.set({'carbons_enabled': true}); - log.debug('Message carbons have been enabled.'); - } - _converse.session.save(); // Gather multiple sets into one save -} - - -converse.plugins.add('converse-carbons', { - - initialize () { - api.settings.extend({ - message_carbons: true - }); - - api.listen.on('connected', () => enableCarbons()); - api.listen.on('reconnected', () => enableCarbons(true)); - } -}); diff --git a/src/headless/plugins/chat/index.js b/src/headless/plugins/chat/index.js index ab00f0bf2..571910c67 100644 --- a/src/headless/plugins/chat/index.js +++ b/src/headless/plugins/chat/index.js @@ -6,24 +6,18 @@ import ChatBox from './model.js'; import MessageMixin from './message.js'; import ModelWithContact from './model-with-contact.js'; import chat_api from './api.js'; -import { Collection } from "@converse/skeletor/src/collection"; +import { Collection } from '@converse/skeletor/src/collection'; import { _converse, api, converse } from '../../core.js'; -import { autoJoinChats, handleMessageStanza, onClearSession, openChat, registerMessageHandlers } from './utils.js'; - +import { + autoJoinChats, + enableCarbons, + handleMessageStanza, + onClearSession, + openChat, + registerMessageHandlers, +} from './utils.js'; converse.plugins.add('converse-chat', { - /* Optional dependencies are other plugins which might be - * overridden or relied upon, and therefore need to be loaded before - * this plugin. They are called "optional" because they might not be - * available, in which case any overrides applicable to them will be - * ignored. - * - * It's possible however to make optional dependencies non-optional. - * If the setting "strict_plugin_dependencies" is set to true, - * an error will be raised if the plugin is not found. - * - * NB: These plugins need to have already been loaded via require.js. - */ dependencies: ['converse-chatboxes', 'converse-disco'], initialize () { @@ -40,14 +34,14 @@ converse.plugins.add('converse-chat', { 'filter_by_resource': false, 'prune_messages_above': undefined, 'pruning_behavior': 'unscrolled', - 'send_chat_markers': ["received", "displayed", "acknowledged"], + 'send_chat_markers': ['received', 'displayed', 'acknowledged'], 'send_chat_state_notifications': true, }); _converse.Message = ModelWithContact.extend(MessageMixin); _converse.Messages = Collection.extend({ model: _converse.Message, - comparator: 'time' + comparator: 'time', }); Object.assign(_converse, { ChatBox, handleMessageStanza }); @@ -58,5 +52,8 @@ converse.plugins.add('converse-chat', { api.listen.on('chatBoxesFetched', autoJoinChats); api.listen.on('presencesInitialized', registerMessageHandlers); api.listen.on('clearSession', onClearSession); - } + + api.listen.on('connected', () => enableCarbons()); + api.listen.on('reconnected', () => enableCarbons(true)); + }, }); diff --git a/src/headless/plugins/chat/utils.js b/src/headless/plugins/chat/utils.js index 52f5618b4..ea5e14a28 100644 --- a/src/headless/plugins/chat/utils.js +++ b/src/headless/plugins/chat/utils.js @@ -106,7 +106,6 @@ export function registerMessageHandlers () { /** * Handler method for all incoming single-user chat "message" stanzas. - * @private * @param { MessageAttributes } attrs - The message attributes */ export async function handleMessageStanza (stanza) { @@ -146,3 +145,39 @@ export async function handleMessageStanza (stanza) { */ api.trigger('message', data); } + +/** + * Ask the XMPP server to enable Message Carbons + * See [XEP-0280](https://xmpp.org/extensions/xep-0280.html#enabling) + * @param { Boolean } reconnecting + */ +export async function enableCarbons (reconnecting) { + if (reconnecting && _converse.session.get('carbons_enabled')) { + if (_converse.session.get('smacks_enabled')) { + // No need to re-enable carbons when resuming a XEP-0198 stream + return; + } + _converse.session.set({'carbons_enabled': false}) + } + + if (_converse.session?.get('carbons_enabled')) { + return; + } + + const iq = new Strophe.Builder('iq', { + 'from': _converse.connection.jid, + 'type': 'set' + }).c('enable', {xmlns: Strophe.NS.CARBONS}); + + const result = await api.sendIQ(iq, null, false); + if (result === null) { + log.warn(`A timeout occurred while trying to enable carbons`); + } else if (u.isErrorStanza(result)) { + log.warn('An error occurred while trying to enable message carbons.'); + log.error(result); + } else { + _converse.session.set({'carbons_enabled': true}); + log.debug('Message carbons have been enabled.'); + } + _converse.session.save(); // Gather multiple sets into one save +} diff --git a/src/headless/plugins/disco/utils.js b/src/headless/plugins/disco/utils.js index f605a7f49..2b40c31e2 100644 --- a/src/headless/plugins/disco/utils.js +++ b/src/headless/plugins/disco/utils.js @@ -42,9 +42,7 @@ function addClientFeatures () { api.disco.own.features.add(Strophe.NS.CHATSTATES); api.disco.own.features.add(Strophe.NS.DISCO_INFO); api.disco.own.features.add(Strophe.NS.ROSTERX); // Limited support - if (api.settings.get("message_carbons")) { - api.disco.own.features.add(Strophe.NS.CARBONS); - } + api.disco.own.features.add(Strophe.NS.CARBONS); /** * Triggered in converse-disco once the core disco features of * Converse have been added. diff --git a/src/headless/shared/constants.js b/src/headless/shared/constants.js index 324988a7f..decf3a2b7 100644 --- a/src/headless/shared/constants.js +++ b/src/headless/shared/constants.js @@ -23,7 +23,6 @@ export const CORE_PLUGINS = [ 'converse-bookmarks', 'converse-bosh', 'converse-caps', - 'converse-carbons', 'converse-chat', 'converse-chatboxes', 'converse-disco',