Commit c1be16aa authored by JC Brand's avatar JC Brand

Bugfix. Store and find occupant views by id, not jid

because we don't always have a jid...
parent 93a8dfc0
...@@ -1069,9 +1069,9 @@ ...@@ -1069,9 +1069,9 @@
}, },
onOccupantAdded: function (item) { onOccupantAdded: function (item) {
var view = this.get(item.get('jid')); var view = this.get(item.get('id'));
if (!view) { if (!view) {
view = this.add(item.get('jid'), new converse.ChatRoomOccupantView({model: item})); view = this.add(item.get('id'), new converse.ChatRoomOccupantView({model: item}));
} else { } else {
delete view.model; // Remove ref to old model to help garbage collection delete view.model; // Remove ref to old model to help garbage collection
view.model = item; view.model = item;
...@@ -1117,22 +1117,30 @@ ...@@ -1117,22 +1117,30 @@
return data; return data;
}, },
updateOccupantsOnPresence: function (pres) { findOccupant: function (data) {
var occupant, attributes; /* Try to find an existing occupant based on the passed in
var data = this.parsePresence(pres); * data object.
if (data.type === 'error') { *
return true; * If we have a JID, we use that as lookup variable,
} * otherwise we use the nick. We don't always have both,
// If we have a JID, we use that to look up the user, * but should have at least one or the other.
// otherwise we use the nick. We don't always have both, */
// but should have at least one or the other.
var jid = Strophe.getBareJidFromJid(data.jid); var jid = Strophe.getBareJidFromJid(data.jid);
if (jid !== null) { if (jid !== null) {
occupant = this.model.where({'jid': jid}).pop(); return this.model.where({'jid': jid}).pop();
} else { } else {
occupant = this.model.where({'nick': data.nick}).pop(); return this.model.where({'nick': data.nick}).pop();
} }
},
updateOccupantsOnPresence: function (pres) {
var attributes;
var data = this.parsePresence(pres);
var jid = Strophe.getBareJidFromJid(data.jid);
if (data.type === 'error') {
return true;
}
var occupant = this.findOccupant(data);
switch (data.type) { switch (data.type) {
case 'unavailable': case 'unavailable':
if (_.contains(['owner', 'admin', 'member'], occupant.get('affiliation'))) { if (_.contains(['owner', 'admin', 'member'], occupant.get('affiliation'))) {
...@@ -1156,17 +1164,20 @@ ...@@ -1156,17 +1164,20 @@
}, },
updateOccupantsOnMembersList: function (iq) { updateOccupantsOnMembersList: function (iq) {
/* <iq from='coven@chat.shakespeare.lit' /* Create occupants based upon a received IQ stanza
id='member3' * containing a member-list.
to='crone1@shakespeare.lit/desktop' *
type='result'> * <iq from='coven@chat.shakespeare.lit'
<query xmlns='http://jabber.org/protocol/muc#admin'> * id='member3'
<item affiliation='member' * to='crone1@shakespeare.lit/desktop'
jid='hag66@shakespeare.lit' * type='result'>
nick='thirdwitch' * <query xmlns='http://jabber.org/protocol/muc#admin'>
role='participant'/> * <item affiliation='member'
</query> * jid='hag66@shakespeare.lit'
</iq> * nick='thirdwitch'
* role='participant'/>
* </query>
* </iq>
*/ */
_.each($(iq).find('query item'), function (item) { _.each($(iq).find('query item'), function (item) {
var jid = item.getAttribute('jid'); var jid = item.getAttribute('jid');
......
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