Skip to content
Snippets Groups Projects
Commit 14c1699e authored by Emmanuel Vodor's avatar Emmanuel Vodor
Browse files

Merge branch '161_new_converse_rai' into 'beta'

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

See merge request !116
parents c337afe3 e4ace9be
No related branches found
No related tags found
2 merge requests!116cleanup code and subscribe to rai if a room is open hidden,!113History, Reply to messages and RAI
Pipeline #10502 passed with stage
in 1 minute and 24 seconds
......@@ -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,
});
......@@ -73,7 +110,8 @@ converse.plugins.add('converse-rai', {
*/
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}"`);
});
},
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment