Send out carbon IQ after stream resumption
This commit is contained in:
parent
d4382fda19
commit
760fa4ae63
@ -5,38 +5,46 @@
|
|||||||
* @description Implements support for XEP-0280 Message Carbons
|
* @description Implements support for XEP-0280 Message Carbons
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import log from '@converse/headless/log';
|
import log from '@converse/headless/log.js';
|
||||||
import { Strophe } from 'strophe.js/src/strophe';
|
import { Strophe } from 'strophe.js/src/strophe';
|
||||||
import { _converse, api, converse } from "../core.js";
|
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
|
/**
|
||||||
|
* Ask the XMPP server to enable Message Carbons
|
||||||
|
* See [XEP-0280](https://xmpp.org/extensions/xep-0280.html#enabling)
|
||||||
*/
|
*/
|
||||||
function enableCarbons (reconnecting) {
|
async function enableCarbons (reconnecting) {
|
||||||
if (reconnecting) {
|
if (reconnecting && _converse.session.get('carbons_enabled')) {
|
||||||
_converse.session?.set({'carbons_enabled': false})
|
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')) {
|
if (!api.settings.get("message_carbons") || _converse.session?.get('carbons_enabled')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const carbons_iq = new Strophe.Builder('iq', {
|
|
||||||
'from': _converse.connection.jid,
|
|
||||||
'id': 'enablecarbons',
|
|
||||||
'type': 'set'
|
|
||||||
})
|
|
||||||
.c('enable', {xmlns: Strophe.NS.CARBONS});
|
|
||||||
|
|
||||||
_converse.connection.addHandler((iq) => {
|
const iq = new Strophe.Builder('iq', {
|
||||||
if (iq.querySelectorAll('error').length > 0) {
|
'from': _converse.connection.jid,
|
||||||
log.warn('An error occurred while trying to enable message carbons.');
|
'type': 'set'
|
||||||
} else {
|
}).c('enable', {xmlns: Strophe.NS.CARBONS});
|
||||||
_converse.session.set({'carbons_enabled': true});
|
|
||||||
log.debug('Message carbons have been enabled.');
|
const result = await api.sendIQ(iq, null, false);
|
||||||
}
|
if (result === null) {
|
||||||
_converse.session.save(); // Gather multiple sets into one save
|
log.warn(`A timeout occurred while trying to enable carbons`);
|
||||||
}, null, "iq", null, "enablecarbons");
|
} else if (u.isErrorStanza(result)) {
|
||||||
_converse.connection.send(carbons_iq);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +55,7 @@ converse.plugins.add('converse-carbons', {
|
|||||||
message_carbons: true
|
message_carbons: true
|
||||||
});
|
});
|
||||||
|
|
||||||
api.listen.on('afterResourceBinding', enableCarbons);
|
api.listen.on('connected', () => enableCarbons());
|
||||||
|
api.listen.on('reconnected', () => enableCarbons(true));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user