From 112c8c612e06e0cbe49e4a442007c78412071e97 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 6 Mar 2013 11:42:53 +0200 Subject: [PATCH] More presencing and chat status fixes. - Try to clear up the confusion between presence_type (i.e type attr) and chat_status (i.e element). - Properly set chat status and custom status message. --- converse.js | 138 +++++++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 65 deletions(-) diff --git a/converse.js b/converse.js index d8a15b418..2290e9269 100644 --- a/converse.js +++ b/converse.js @@ -551,17 +551,17 @@ xmppchat.roster.on('change', function (item, changed) { var fullname = this.model.get('fullname'), - presence_type = item.get('presence_type'); + chat_status = item.get('chat_status'); if (item.get('jid') === this.model.get('jid')) { - if (_.has(changed.changes, 'presence_type')) { + if (_.has(changed.changes, 'chat_status')) { if (this.$el.is(':visible')) { - if (presence_type === 'offline') { + if (chat_status === 'offline') { this.insertStatusNotification(fullname+' '+'has gone offline'); - } else if (presence_type === 'away') { + } else if (chat_status === 'away') { this.insertStatusNotification(fullname+' '+'has gone away'); - } else if ((presence_type === 'dnd')) { + } else if ((chat_status === 'dnd')) { this.insertStatusNotification(fullname+' '+'is busy'); - } else if (presence_type === 'online') { + } else if (chat_status === 'online') { this.$el.find('div.chat-event').remove(); } } @@ -1273,7 +1273,7 @@ 'image_type': img_type, 'url': url, 'resources': [], - 'presence_type': 'offline', + 'chat_status': 'offline', 'status': 'offline' }, {'silent': true}); } @@ -1365,7 +1365,7 @@ var item = this.model, ask = item.get('ask'), subscription = item.get('subscription'); - this.$el.addClass(item.get('presence_type')); + this.$el.addClass(item.get('chat_status')); if (ask === 'subscribe') { this.$el.addClass('pending-xmpp-contact'); @@ -1384,8 +1384,8 @@ initialize: function () { this.options.model.on('change', function (item, changed) { - if (_.has(changed.changes, 'presence_type')) { - this.$el.attr('class', item.changed.presence_type); + if (_.has(changed.changes, 'chat_status')) { + this.$el.attr('class', item.changed.chat_status); } }, this); } @@ -1410,9 +1410,9 @@ }, comparator : function (rosteritem) { - var presence_type = rosteritem.get('presence_type'), + var chat_status = rosteritem.get('chat_status'), rank = 4; - switch(presence_type) { + switch(chat_status) { case 'offline': rank = 0; break; @@ -1525,12 +1525,20 @@ } }, + unsubscribe: function (jid) { + xmppchat.xmppstatus.sendPresence('unsubscribe'); + if (xmppchat.connection.roster.findItem(jid)) { + xmppchat.chatboxesview.controlbox.roster.remove(jid); + xmppchat.connection.roster.remove(jid); + } + }, + getNumOnlineContacts: function () { var count = 0, models = this.models, models_length = models.length; for (var i=0; i' + - '' + + '' + '{{ status_message }} {{ status_message }}' + '' + '' + @@ -1866,15 +1861,28 @@ this.$el.find(".dropdown dd ul").hide(); }, + getPrettyStatus: function (stat) { + if (stat === 'chat') { + pretty_status = 'online'; + } else if (stat === 'dnd') { + pretty_status = 'busy'; + } else if (stat === 'xa') { + pretty_status = 'away for long'; + } else { + pretty_status = stat || 'online'; + } + return pretty_status + }, + updateStatusUI: function (ev) { - var stat = ev.get('status'), - status_message = ev.get('status_message') || "I am " + stat; + var stat = ev.get('status'), + status_message; + status_message = ev.get('status_message') || "I am " + this.getPrettyStatus(stat); this.$el.find('#fancy-xmpp-status-select').html( this.status_template({ - 'presence_type': stat, + 'chat_status': stat, 'status_message': status_message })); - }, choose_template: _.template( @@ -1895,7 +1903,7 @@ // Replace the default dropdown with something nicer // ------------------------------------------------- var $select = this.$el.find('select#select-xmpp-status'), - presence_type = this.model.getStatus() || 'offline', + chat_status = this.model.getStatus() || 'offline', options = $('option', $select), $options_target, options_list = [], @@ -1903,8 +1911,8 @@ this.$el.html(this.choose_template()); this.$el.find('#fancy-xmpp-status-select') .html(this.status_template({ - 'status_message': "I am " + presence_type, - 'presence_type': presence_type + 'status_message': "I am " + this.getPrettyStatus(chat_status), + 'chat_status': chat_status })); // iterate through all the