Commit c25cc4c7 authored by JC Brand's avatar JC Brand

Bugfix. Existing occupants weren't found because query was only by jid

Which meant that occupants were being duplicated.

updates #1146
parent 1aceaa9c
This diff is collapsed.
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
'none': 2, 'none': 2,
}; };
const { Strophe, Backbone, Promise, $iq, $build, $msg, $pres, b64_sha1, sizzle, _, moment } = converse.env; const { Strophe, Backbone, Promise, $iq, $build, $msg, $pres, b64_sha1, sizzle, f, moment, _ } = converse.env;
// Add Strophe Namespaces // Add Strophe Namespaces
Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin"); Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin");
...@@ -1028,26 +1028,29 @@ ...@@ -1028,26 +1028,29 @@
}, },
fetchMembers () { fetchMembers () {
const old_jids = _.uniq(_.concat(
_.map(this.where({'affiliation': 'admin'}), (item) => item.get('jid')),
_.map(this.where({'affiliation': 'member'}), (item) => item.get('jid')),
_.map(this.where({'affiliation': 'owner'}), (item) => item.get('jid'))
));
this.chatroom.getJidsWithAffiliations(['member', 'owner', 'admin']) this.chatroom.getJidsWithAffiliations(['member', 'owner', 'admin'])
.then((jids) => { .then((new_members) => {
_.each(_.difference(old_jids, jids), (removed_jid) => { const new_jids = new_members.map(m => m.jid).filter(m => !_.isUndefined(m)),
// Remove absent occupants who've been removed from new_nicks = new_members.map(m => !m.jid && m.nick || undefined).filter(m => !_.isUndefined(m)),
// the members lists. removed_members = this.filter(m => {
if (removed_jid === _converse.bare_jid) { return; } return f.includes(m.get('affiliation'), ['admin', 'member', 'owner']) &&
const occupant = this.findOccupant({'jid': removed_jid}); !f.includes(m.get('nick'), new_nicks) &&
if (!occupant) { return; } !f.includes(m.get('jid'), new_jids);
});
_.each(removed_members, (occupant) => {
if (occupant.get('jid') === _converse.bare_jid) { return; }
if (occupant.get('show') === 'offline') { if (occupant.get('show') === 'offline') {
occupant.destroy(); occupant.destroy();
} }
}); });
_.each(jids, (attrs) => { _.each(new_members, (attrs) => {
const occupant = this.findOccupant({'jid': attrs.jid}); let occupant;
if (attrs.jid) {
occupant = this.findOccupant({'jid': attrs.jid});
} else {
occupant = this.findOccupant({'nick': attrs.nick});
}
if (occupant) { if (occupant) {
occupant.save(attrs); occupant.save(attrs);
} else { } else {
......
...@@ -174,7 +174,7 @@ ...@@ -174,7 +174,7 @@
.c('item').attrs({ .c('item').attrs({
affiliation: 'owner', affiliation: 'owner',
jid: _converse.bare_jid, jid: _converse.bare_jid,
role: 'participant' role: 'moderator'
}).up() }).up()
.c('status').attrs({code:'110'}); .c('status').attrs({code:'110'});
_converse.connection._dataRecv(utils.createRequest(presence)); _converse.connection._dataRecv(utils.createRequest(presence));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment