Răsfoiți Sursa

Always enable carbons upon connection or reconnection

Previously we tried to remember whether carbons were enabled before by
saving a flag in the session storage, but apparently this resulted in
false positives and carbons then not being enabled.

With carbons not enabled, clients don't get sent messages.

I don't like the idea of enabling carbons every time the page reloads,
but the alternative is lost messages which is way worse.

I think the issue is that it's not possible to guarantee that the
session is always properly cleared. For example if Converse crashes, and
then the page is reloaded, the session will wrongly indicate that
carbons have been enabled, even though they won't be.
JC Brand 2 ani în urmă
părinte
comite
b4eb6c0994

+ 1 - 1
src/headless/plugins/chat/index.js

@@ -54,6 +54,6 @@ converse.plugins.add('converse-chat', {
         api.listen.on('clearSession', onClearSession);
 
         api.listen.on('connected', () => enableCarbons());
-        api.listen.on('reconnected', () => enableCarbons(true));
+        api.listen.on('reconnected', () => enableCarbons());
     },
 });

+ 1 - 15
src/headless/plugins/chat/utils.js

@@ -151,19 +151,7 @@ export async function handleMessageStanza (stanza) {
  * 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;
-    }
-
+export async function enableCarbons () {
     const domain = Strophe.getDomainFromJid(_converse.bare_jid);
     const supported = await api.disco.supports(Strophe.NS.CARBONS, domain);
 
@@ -184,8 +172,6 @@ export async function enableCarbons (reconnecting) {
         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
 }

+ 0 - 1
src/headless/plugins/smacks/tests/smacks.js

@@ -231,7 +231,6 @@ describe("XEP-0198 Stream Management", function () {
                 "unacked_stanzas": [],
                 "smacks_stream_id": "some-long-sm-id",
                 "push_enabled": ["romeo@montague.lit"],
-                "carbons_enabled": true,
                 "roster_cached": true
             })
         );