Commit 4e7de9e5 authored by JC Brand's avatar JC Brand

Handle case where groups are added from browser storage.

update #83
parent 6a28420d
...@@ -3369,11 +3369,11 @@ ...@@ -3369,11 +3369,11 @@
this.registerRosterHandler(); this.registerRosterHandler();
this.registerRosterXHandler(); this.registerRosterXHandler();
this.registerPresenceHandler(); this.registerPresenceHandler();
converse.roster.on("add", this.onContactAdd, this);
converse.roster.on("add", this.onAdd, this); converse.roster.on('change', this.onContactChange, this);
converse.roster.on('change', this.onChange, this);
converse.roster.on("remove", this.update, this);
converse.roster.on("destroy", this.update, this); converse.roster.on("destroy", this.update, this);
converse.roster.on("remove", this.update, this);
this.model.on("add", this.onGroupAdd, this);
this.model.on("reset", this.reset, this); this.model.on("reset", this.reset, this);
this.render(); this.render();
this.model.fetch({add: true}); this.model.fetch({add: true});
...@@ -3423,7 +3423,13 @@ ...@@ -3423,7 +3423,13 @@
}, this), null, 'presence', null); }, this), null, 'presence', null);
}, },
onAdd: function (contact) { onGroupAdd: function (group) {
var view = new converse.RosterGroupView({model: group});
this.add(group.get('name'), view);
this.positionGroup(view);
},
onContactAdd: function (contact) {
this.addRosterContact(contact).update(); this.addRosterContact(contact).update();
if (!contact.get('vcard_updated')) { if (!contact.get('vcard_updated')) {
// This will update the vcard, which triggers a change // This will update the vcard, which triggers a change
...@@ -3432,7 +3438,7 @@ ...@@ -3432,7 +3438,7 @@
} }
}, },
onChange: function (contact) { onContactChange: function (contact) {
this.updateChatBox(contact).update(); this.updateChatBox(contact).update();
}, },
...@@ -3464,27 +3470,21 @@ ...@@ -3464,27 +3470,21 @@
} else { } else {
$(this.$('.roster-group').eq(index)).before(view.$el); $(this.$('.roster-group').eq(index)).before(view.$el);
} }
return view;
}, },
getGroup: function (name) { getGroup: function (name) {
/* Returns the group view as specified by name. /* Returns the group as specified by name.
* Creates the view if it doesn't exist. * Creates the group if it doesn't exist.
*/ */
var view = this.get(name); var view = this.get(name);
if (view) { if (view) {
return view; return view.model;
} }
view = new converse.RosterGroupView({ return this.model.create({name: name, id: b64_sha1(name)});
model: this.model.create({name: name, id: b64_sha1(name)}),
});
this.add(name, view);
return this.positionGroup(view);
}, },
addContactToGroup: function (contact, name) { addContactToGroup: function (contact, name) {
var group = this.getGroup(name); this.getGroup(name).contacts.add(contact);
group.model.contacts.add(contact);
}, },
addCurrentContact: function (contact) { addCurrentContact: function (contact) {
......
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