From 85bec04010a3233ce085b984a0a5ea6f4f1470f2 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 16 Feb 2015 12:47:36 -0800 Subject: [PATCH] Render leave-group messages correctly --- js/background.js | 32 +++++++++++++++++++------------- js/views/group_update_view.js | 5 +++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/js/background.js b/js/background.js index 0619b878..44d2b539 100644 --- a/js/background.js +++ b/js/background.js @@ -148,20 +148,26 @@ var conversation = new Whisper.Conversation({id: conversationId}); var attributes = {}; conversation.fetch().always(function() { - if (pushMessageContent.group && - pushMessageContent.group.type === textsecure.protobuf.PushMessageContent.GroupContext.Type.UPDATE) { - attributes = { - type : 'group', - groupId : pushMessageContent.group.id, - name : pushMessageContent.group.name, - avatar : pushMessageContent.group.avatar, - members : pushMessageContent.group.members, - }; - var group_update = conversation.changedAttributes(_.pick(pushMessageContent.group, 'name', 'avatar')); - var difference = _.difference(pushMessageContent.group.members, conversation.get('members')); - if (difference.length > 0) { - group_update.joined = difference; + if (pushMessageContent.group) { + if (pushMessageContent.group.type === textsecure.protobuf.PushMessageContent.GroupContext.Type.UPDATE) { + attributes = { + type : 'group', + groupId : pushMessageContent.group.id, + name : pushMessageContent.group.name, + avatar : pushMessageContent.group.avatar, + members : pushMessageContent.group.members, + }; + var group_update = conversation.changedAttributes(_.pick(pushMessageContent.group, 'name', 'avatar')); + var difference = _.difference(pushMessageContent.group.members, conversation.get('members')); + if (difference.length > 0) { + group_update.joined = difference; + } } + else if (pushMessageContent.group.type === textsecure.protobuf.PushMessageContent.GroupContext.Type.QUIT) { + var group_update = { left: source }; + attributes = { members: _.without(conversation.get('members'), source) }; + } + if (_.keys(group_update).length > 0) { message.set({group_update: group_update}); } diff --git a/js/views/group_update_view.js b/js/views/group_update_view.js index ec0d51a5..429a9699 100644 --- a/js/views/group_update_view.js +++ b/js/views/group_update_view.js @@ -23,6 +23,11 @@ className: "group-update", render: function() { //TODO l10n + if (this.model.left) { + this.$el.text(this.model.left + ' left the group'); + return this; + } + var messages = ['Updated the group.']; if (this.model.name) { messages.push("Title is now '" + this.model.name + "'.");