Skip to content
Snippets Groups Projects

cleanup code and subscribe to rai if a room is open hidden

Merged Emmanuel Vodor requested to merge 161_new_converse_rai into beta
1 file
+ 50
12
Compare changes
  • Side-by-side
  • Inline
+ 50
12
@@ -22,18 +22,57 @@ converse.plugins.add('converse-rai', {
@@ -22,18 +22,57 @@ converse.plugins.add('converse-rai', {
const conn_status = this.session.get('connection_status');
const conn_status = this.session.get('connection_status');
const { api } = this.__super__._converse;
const { api } = this.__super__._converse;
if (this.get('hidden') && conn_status === converse.ROOMSTATUS.ENTERED) {
if (this.get('hidden')
if (api.settings.get('muc_subscribe_to_rai') && this.getOwnAffiliation() !== 'none') {
&& conn_status === converse.ROOMSTATUS.ENTERED
if (conn_status !== converse.ROOMSTATUS.DISCONNECTED) {
&& api.settings.get('muc_subscribe_to_rai')
this.sendMarkerForLastMessage('received', true);
&& this.getOwnAffiliation() !== 'none'
await this.leave();
) {
await this.close();
this.sendMarkerForLastMessage('received', true);
}
await this.leave();
}
await this.close();
} else if (conn_status === converse.ROOMSTATUS.DISCONNECTED) {
} else if (conn_status === converse.ROOMSTATUS.DISCONNECTED) {
await this.rejoin();
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: {
ChatBox: {
/**
/**
@@ -55,10 +94,8 @@ converse.plugins.add('converse-rai', {
@@ -55,10 +94,8 @@ converse.plugins.add('converse-rai', {
const _converse = this._converse;
const _converse = this._converse;
const { api } = _converse;
const { api } = _converse;
// Register namespace
Strophe.addNamespace('RAI', 'urn:xmpp:rai:0');
Strophe.addNamespace('RAI', 'urn:xmpp:rai:0');
// Register settings
api.settings.extend({
api.settings.extend({
muc_subscribe_to_rai: false,
muc_subscribe_to_rai: false,
});
});
@@ -73,7 +110,8 @@ converse.plugins.add('converse-rai', {
@@ -73,7 +110,8 @@ converse.plugins.add('converse-rai', {
*/
*/
subscribe(jids) {
subscribe(jids) {
if (!api.settings.get('muc_subscribe_to_rai')) {
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') {
if (typeof jids === 'string') {
@@ -87,7 +125,7 @@ converse.plugins.add('converse-rai', {
@@ -87,7 +125,7 @@ converse.plugins.add('converse-rai', {
'xmlns': Strophe.NS.RAI,
'xmlns': Strophe.NS.RAI,
});
});
api.send(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