Skip to content
Snippets Groups Projects

History, Reply to messages and RAI

Merged Emmanuel Vodor requested to merge beta into master
1 file
+ 51
13
Compare changes
  • Side-by-side
  • Inline
+ 51
13
@@ -22,18 +22,57 @@ converse.plugins.add('converse-rai', {
const conn_status = this.session.get('connection_status');
const { api } = this.__super__._converse;
if (this.get('hidden') && conn_status === converse.ROOMSTATUS.ENTERED) {
if (api.settings.get('muc_subscribe_to_rai') && this.getOwnAffiliation() !== 'none') {
if (conn_status !== converse.ROOMSTATUS.DISCONNECTED) {
this.sendMarkerForLastMessage('received', true);
await this.leave();
await this.close();
}
}
if (this.get('hidden')
&& conn_status === converse.ROOMSTATUS.ENTERED
&& api.settings.get('muc_subscribe_to_rai')
&& this.getOwnAffiliation() !== 'none'
) {
this.sendMarkerForLastMessage('received', true);
await this.leave();
await this.close();
} else if (conn_status === converse.ROOMSTATUS.DISCONNECTED) {
await this.rejoin();
}
},
/**
* Subscribe to RAI if connected to the room, but it's hidden.
* @private
* @method _converse.ChatRoom#onConnectionStatusChanged
*/
async onConnectionStatusChanged() {
const conn_status = this.session.get('connection_status');
const { api } = this.__super__._converse;
if (this.get('hidden')
&& conn_status === converse.ROOMSTATUS.ENTERED
&& api.settings.get('muc_subscribe_to_rai')
&& this.getOwnAffiliation() !== 'none'
) {
await this.leave();
await this.close();
this.enableRAI();
} else {
await this.__super__.onConnectionStatusChanged.apply(this, arguments);
}
},
/**
* Ensures that the user is subscribed to XEP-0437 Room Activity Indicators
* if `muc_subscribe_to_rai` is set to `true`.
* Only affiliated users can subscribe to RAI, but this method doesn't
* check whether the current user is affiliated because it's intended to be
* called after the MUC has been left and we don't have that information
* anymore.
* @private
* @method _converse.ChatRoom#enableRAI
*/
enableRAI() {
const { api } = this.__super__._converse;
if (api.settings.get('muc_subscribe_to_rai')) {
api.rooms.subscribe(this.get('jid'));
}
},
},
ChatBox: {
/**
@@ -55,10 +94,8 @@ converse.plugins.add('converse-rai', {
const _converse = this._converse;
const { api } = _converse;
// Register namespace
Strophe.addNamespace('RAI', 'urn:xmpp:rai:0');
// Register settings
api.settings.extend({
muc_subscribe_to_rai: false,
});
@@ -71,9 +108,10 @@ converse.plugins.add('converse-rai', {
* @param {string|Array} jids
* @returns {void}
*/
subscribe(jids) {
async subscribe(jids) {
if (!api.settings.get('muc_subscribe_to_rai')) {
console.error('Can\'t subscribe to RAI, this feature is not enabled');
log.error(`You must enable the 'muc_subscribe_to_rai' option before subscribing to a MUC.`);
return;
}
if (typeof jids === 'string') {
@@ -87,7 +125,7 @@ converse.plugins.add('converse-rai', {
'xmlns': Strophe.NS.RAI,
});
api.send(rai);
console.log('Sent RAI stanza for muc_domain', muc_domain, rai.toString());
log.debug(`Sent RAI stanza for domain "${muc_domain}"`);
});
},
});
Loading