Commit 1810e809 authored by JC Brand's avatar JC Brand

Some cleanup. Remove unused methods, renamed certain vars

parent 219d5c8a
...@@ -2788,7 +2788,6 @@ ...@@ -2788,7 +2788,6 @@
'groups': [], 'groups': [],
'status': '' 'status': ''
}, attributes); }, attributes);
attrs.sorted = false;
attrs.chat_status = 'offline'; attrs.chat_status = 'offline';
this.set(attrs); this.set(attrs);
} }
...@@ -3077,7 +3076,6 @@ ...@@ -3077,7 +3076,6 @@
ask: item.ask, ask: item.ask,
fullname: item.name || item.jid, fullname: item.name || item.jid,
groups: item.groups, groups: item.groups,
is_last: is_last,
jid: item.jid, jid: item.jid,
subscription: item.subscription subscription: item.subscription
}); });
...@@ -3143,8 +3141,7 @@ ...@@ -3143,8 +3141,7 @@
image: img, image: img,
image_type: img_type, image_type: img_type,
url: url, url: url,
vcard_updated: moment().format(), vcard_updated: moment().format()
is_last: true
}); });
}, this), }, this),
$.proxy(function (jid, fullname, img, img_type, url) { $.proxy(function (jid, fullname, img, img_type, url) {
...@@ -3155,8 +3152,7 @@ ...@@ -3155,8 +3152,7 @@
subscription: 'none', subscription: 'none',
ask: null, ask: null,
requesting: true, requesting: true,
fullname: jid, fullname: jid
is_last: true
}); });
}, this) }, this)
); );
...@@ -3180,7 +3176,7 @@ ...@@ -3180,7 +3176,7 @@
$show = $presence.find('show'), $show = $presence.find('show'),
chat_status = $show.text() || 'online', chat_status = $show.text() || 'online',
status_message = $presence.find('status'), status_message = $presence.find('status'),
item; contact;
if (this.isSelf(bare_jid)) { if (this.isSelf(bare_jid)) {
if ((converse.connection.jid !== jid)&&(presence_type !== 'unavailable')) { if ((converse.connection.jid !== jid)&&(presence_type !== 'unavailable')) {
...@@ -3191,9 +3187,9 @@ ...@@ -3191,9 +3187,9 @@
} else if (($presence.find('x').attr('xmlns') || '').indexOf(Strophe.NS.MUC) === 0) { } else if (($presence.find('x').attr('xmlns') || '').indexOf(Strophe.NS.MUC) === 0) {
return true; // Ignore MUC return true; // Ignore MUC
} }
item = this.get(bare_jid); contact = this.get(bare_jid);
if (item && (status_message.text() != item.get('status'))) { if (contact && (status_message.text() != contact.get('status'))) {
item.save({'status': status_message.text()}); contact.save({'status': status_message.text()});
} }
if ((presence_type === 'subscribed') || (presence_type === 'unsubscribe')) { if ((presence_type === 'subscribed') || (presence_type === 'unsubscribe')) {
return true; return true;
...@@ -3203,14 +3199,14 @@ ...@@ -3203,14 +3199,14 @@
this.unsubscribe(bare_jid); this.unsubscribe(bare_jid);
} else if (presence_type === 'unavailable') { } else if (presence_type === 'unavailable') {
if (this.removeResource(bare_jid, resource) === 0) { if (this.removeResource(bare_jid, resource) === 0) {
if (item) { if (contact) {
item.save({'chat_status': 'offline'}); contact.save({'chat_status': 'offline'});
} }
} }
} else if (item) { } else if (contact) {
// presence_type is undefined // presence_type is undefined
this.addResource(bare_jid, resource); this.addResource(bare_jid, resource);
item.save({'chat_status': chat_status}); contact.save({'chat_status': chat_status});
} }
return true; return true;
} }
...@@ -3349,7 +3345,6 @@ ...@@ -3349,7 +3345,6 @@
}); });
this.GroupViews = Backbone.Overview.extend({ this.GroupViews = Backbone.Overview.extend({
initialize: function () { initialize: function () {
this.model.on("add", this.onGroupAdd, this); this.model.on("add", this.onGroupAdd, this);
}, },
...@@ -3387,7 +3382,7 @@ ...@@ -3387,7 +3382,7 @@
return this; return this;
}, },
update: function (item) { update: function () {
// XXX: Is this still being used/valid? // XXX: Is this still being used/valid?
var $count = $('#online-count'); var $count = $('#online-count');
$count.text('('+this.roster.getNumOnlineContacts()+')'); $count.text('('+this.roster.getNumOnlineContacts()+')');
...@@ -3425,71 +3420,46 @@ ...@@ -3425,71 +3420,46 @@
}, this), null, 'presence', null); }, this), null, 'presence', null);
}, },
insertRosterFragment: function () { onAdd: function (contact) {
if (this.$fragment) { this.addRosterContact(contact).update();
this.$el.html(this.$fragment.contents()) if (!contact.get('vcard_updated')) {
delete this.$fragment;
}
return this;
},
onAdd: function (item) {
this.addRosterContact(item);
if (item.get('is_last')) {
this.update();
}
if (!item.get('vcard_updated')) {
// This will update the vcard, which triggers a change // This will update the vcard, which triggers a change
// request which will rerender the roster item. // request which will rerender the roster contact.
converse.getVCard(item.get('jid')); converse.getVCard(contact.get('jid'));
} }
}, },
onChange: function (item) { onChange: function (contact) {
if ((_.size(item.changed) === 1) && _.contains(_.keys(item.changed), 'sorted')) { this.updateChatBox(contact).update();
return;
}
this.updateChatBox(item).update();
}, },
updateChatBox: function (item, changed) { updateChatBox: function (contact, changed) {
var chatbox = converse.chatboxes.get(item.get('jid')), var chatbox = converse.chatboxes.get(contact.get('jid')),
changes = {}; changes = {};
if (!chatbox) { if (!chatbox) {
return this; return this;
} }
if (_.has(item.changed, 'chat_status')) { if (_.has(contact.changed, 'chat_status')) {
changes.chat_status = item.get('chat_status'); changes.chat_status = contact.get('chat_status');
} }
if (_.has(item.changed, 'status')) { if (_.has(contact.changed, 'status')) {
changes.status = item.get('status'); changes.status = contact.get('status');
} }
chatbox.save(changes); chatbox.save(changes);
return this; return this;
}, },
getRoster: function () {
// TODO: see if _ensureElement can be used.
// Return the document fragment if it exists.
var $el;
if (this.$fragment) {
return this.$fragment;
} else {
return this.$el;
}
},
positionGroup: function (view) { positionGroup: function (view) {
/* Place the group's DOM element in the correct alphabetical /* Place the group's DOM element in the correct alphabetical
* position amongst the other groups in the roster. * position amongst the other groups in the roster.
*/ */
var index = this.model.indexOf(view.model); var index = this.model.indexOf(view.model);
if (index == 0) { if (index == 0) {
this.getRoster().prepend(view.$el); this.$el.prepend(view.$el);
} else if (index == (this.model.length-1)) { } else if (index == (this.model.length-1)) {
this.getRoster().find('.roster-group').last().siblings('dd').last().after(view.$el); this.$('.roster-group').last().siblings('dd').last().after(view.$el);
} else { } else {
$(this.getRoster().find('.roster-group').eq(index)).before(view.$el); $(this.$('.roster-group').eq(index)).before(view.$el);
} }
return view; return view;
}, },
...@@ -3514,10 +3484,10 @@ ...@@ -3514,10 +3484,10 @@
group.model.contacts.add(contact); group.model.contacts.add(contact);
}, },
addCurrentContact: function (item) { addCurrentContact: function (contact) {
var groups; var groups;
if (converse.roster_groups) { if (converse.roster_groups) {
groups = item.get('groups'); groups = contact.get('groups');
if (groups.length === 0) { if (groups.length === 0) {
groups = [HEADER_UNGROUPED]; groups = [HEADER_UNGROUPED];
} }
...@@ -3525,20 +3495,20 @@ ...@@ -3525,20 +3495,20 @@
groups = [HEADER_CURRENT_CONTACTS]; groups = [HEADER_CURRENT_CONTACTS];
} }
_.each(groups, $.proxy(function (name) { _.each(groups, $.proxy(function (name) {
this.addContactToGroup(item, name); this.addContactToGroup(contact, name);
}, this)); }, this));
}, },
addRosterContact: function (item) { addRosterContact: function (contact) {
var view; var view;
if (item.get('subscription') === 'both' || item.get('subscription') === 'to') { if (contact.get('subscription') === 'both' || contact.get('subscription') === 'to') {
this.addCurrentContact(item); this.addCurrentContact(contact);
} else { } else {
view = (new converse.RosterContactView({model: item})).render(); view = (new converse.RosterContactView({model: contact})).render();
if ((item.get('ask') === 'subscribe') || (item.get('subscription') === 'from')) { if ((contact.get('ask') === 'subscribe') || (contact.get('subscription') === 'from')) {
this.addContactToGroup(item, HEADER_PENDING_CONTACTS) this.addContactToGroup(contact, HEADER_PENDING_CONTACTS)
} else if (item.get('requesting') === true) { } else if (contact.get('requesting') === true) {
this.addContactToGroup(item, HEADER_REQUESTING_CONTACTS) this.addContactToGroup(contact, HEADER_REQUESTING_CONTACTS)
} }
} }
return this; return this;
......
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