|
@@ -480,17 +480,41 @@ converse.plugins.add('converse-muc', {
|
|
|
return this.occupants.fetched;
|
|
|
},
|
|
|
|
|
|
+ handleAffiliationChangedMessage (stanza) {
|
|
|
+ const item = sizzle(`x[xmlns="${Strophe.NS.MUC_USER}"] item`, stanza).pop();
|
|
|
+ if (item) {
|
|
|
+ const from = stanza.getAttribute("from");
|
|
|
+ const type = stanza.getAttribute("type");
|
|
|
+ const affiliation = item.getAttribute('affiliation');
|
|
|
+ const jid = item.getAttribute('jid');
|
|
|
+ const data = {
|
|
|
+ from, type, affiliation,
|
|
|
+ 'nick': Strophe.getNodeFromJid(jid),
|
|
|
+ 'states': [],
|
|
|
+ 'show': type == 'unavailable' ? 'offline' : 'online',
|
|
|
+ 'role': item.getAttribute('role'),
|
|
|
+ 'jid': Strophe.getBareJidFromJid(jid),
|
|
|
+ 'resource': Strophe.getResourceFromJid(jid)
|
|
|
+ }
|
|
|
+ const occupant = this.occupants.findOccupant({'jid': data.jid});
|
|
|
+ if (occupant) {
|
|
|
+ occupant.save(data);
|
|
|
+ } else {
|
|
|
+ this.occupants.create(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
registerHandlers () {
|
|
|
// Register presence and message handlers for this groupchat
|
|
|
const room_jid = this.get('jid');
|
|
|
this.removeHandlers();
|
|
|
- this.presence_handler = _converse.connection.addHandler(stanza => {
|
|
|
- this.onPresence(stanza);
|
|
|
- return true;
|
|
|
- },
|
|
|
+ this.presence_handler = _converse.connection.addHandler(
|
|
|
+ stanza => (this.onPresence(stanza) || true),
|
|
|
null, 'presence', null, null, room_jid,
|
|
|
{'ignoreNamespaceFragment': true, 'matchBareFromJid': true}
|
|
|
);
|
|
|
+
|
|
|
this.message_handler = _converse.connection.addHandler(stanza => {
|
|
|
if (sizzle(`message > result[xmlns="${Strophe.NS.MAM}"]`, stanza).pop()) {
|
|
|
// MAM messages are handled in converse-mam.
|
|
@@ -504,61 +528,27 @@ converse.plugins.add('converse-muc', {
|
|
|
}, null, 'message', 'groupchat', null, room_jid,
|
|
|
{'matchBareFromJid': true}
|
|
|
);
|
|
|
- this.muc_notifications_handler = _converse.connection.addHandler(stanza => {
|
|
|
- const item = sizzle(`x[xmlns="${Strophe.NS.MUC_USER}"] item`, stanza).pop();
|
|
|
-
|
|
|
- if (item) {
|
|
|
- const from = stanza.getAttribute("from");
|
|
|
- const type = stanza.getAttribute("type");
|
|
|
- const affiliation = item.getAttribute('affiliation');
|
|
|
- const jid = item.getAttribute('jid');
|
|
|
-
|
|
|
- const data = {
|
|
|
- 'from': from,
|
|
|
- 'nick': Strophe.getNodeFromJid(jid),
|
|
|
- 'type': type,
|
|
|
- 'states': [],
|
|
|
- 'show': type == 'unavailable' ? 'offline' : 'online',
|
|
|
- 'affiliation': affiliation,
|
|
|
- 'role': item.getAttribute('role'),
|
|
|
- 'jid': Strophe.getBareJidFromJid(jid),
|
|
|
- 'resource': Strophe.getResourceFromJid(jid)
|
|
|
- }
|
|
|
|
|
|
- const occupant = this.occupants.findOccupant({'jid': data.jid});
|
|
|
-
|
|
|
- if (occupant) {
|
|
|
- occupant.save(data);
|
|
|
- } else {
|
|
|
- this.occupants.create(data);
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
-
|
|
|
- }, Strophe.NS.MUC_USER, 'message', null, null, room_jid);
|
|
|
+ this.affiliation_message_handler = _converse.connection.addHandler(
|
|
|
+ stanza => (this.handleAffiliationChangedMessage(stanza) || true),
|
|
|
+ Strophe.NS.MUC_USER, 'message', null, null, room_jid
|
|
|
+ );
|
|
|
},
|
|
|
|
|
|
removeHandlers () {
|
|
|
// Remove the presence and message handlers that were
|
|
|
// registered for this groupchat.
|
|
|
if (this.message_handler) {
|
|
|
- if (_converse.connection) {
|
|
|
- _converse.connection.deleteHandler(this.message_handler);
|
|
|
- }
|
|
|
+ _converse.connection && _converse.connection.deleteHandler(this.message_handler);
|
|
|
delete this.message_handler;
|
|
|
}
|
|
|
if (this.presence_handler) {
|
|
|
- if (_converse.connection) {
|
|
|
- _converse.connection.deleteHandler(this.presence_handler);
|
|
|
- }
|
|
|
+ _converse.connection && _converse.connection.deleteHandler(this.presence_handler);
|
|
|
delete this.presence_handler;
|
|
|
}
|
|
|
-
|
|
|
- if (this.muc_notifications_handler) {
|
|
|
- if (_converse.connection) {
|
|
|
- _converse.connection.deleteHandler(this.muc_notifications_handler);
|
|
|
- }
|
|
|
- delete this.muc_notifications_handler;
|
|
|
+ if (this.affiliation_message_handler) {
|
|
|
+ _converse.connection && _converse.connection.deleteHandler(this.affiliation_message_handler);
|
|
|
+ delete this.affiliation_message_handler;
|
|
|
}
|
|
|
return this;
|
|
|
},
|