From 010297f4c55f23fc19c45f4cfe3b3779ad6dd538 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 11 Feb 2016 14:12:09 -0800 Subject: [PATCH] Track groups I've left // FREEBIE --- js/background.js | 8 +++-- js/libtextsecure.js | 42 ++++++++++++++------------ js/models/conversations.js | 1 + libtextsecure/message_receiver.js | 42 ++++++++++++++------------ protos/IncomingPushMessageSignal.proto | 1 + 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/js/background.js b/js/background.js index 56a59a04..44225cef 100644 --- a/js/background.js +++ b/js/background.js @@ -131,13 +131,17 @@ function onGroupReceived(ev) { var groupDetails = ev.groupDetails; - ConversationController.create({ + var conversation = ConversationController.create({ id: groupDetails.id, name: groupDetails.name, members: groupDetails.members, avatar: groupDetails.avatar, type: 'group', - }).save(); + }); + if (!groupDetails.active) { + conversation.set({left: true}); + } + conversation.save(); } function onMessageReceived(ev) { diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 9586e47c..85c98434 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37077,25 +37077,29 @@ MessageReceiver.prototype.extend({ while (groupDetails !== undefined) { var promise = (function(groupDetails) { groupDetails.id = getString(groupDetails.id); - return textsecure.storage.groups.getGroup(groupDetails.id). - then(function(existingGroup) { - if (existingGroup === undefined) { - return textsecure.storage.groups.createNewGroup( - groupDetails.members, groupDetails.id - ); - } else { - return textsecure.storage.groups.updateNumbers( - groupDetails.id, groupDetails.members - ); - } - }).then(function() { - var ev = new Event('group'); - ev.groupDetails = groupDetails; - eventTarget.dispatchEvent(ev); - }).catch(function(e) { - console.log('error processing group', groupDetails.id, e); - }); - })(groupDetails); + if (groupDetails.active) { + return textsecure.storage.groups.getGroup(groupDetails.id). + then(function(existingGroup) { + if (existingGroup === undefined) { + return textsecure.storage.groups.createNewGroup( + groupDetails.members, groupDetails.id + ); + } else { + return textsecure.storage.groups.updateNumbers( + groupDetails.id, groupDetails.members + ); + } + }).then(function() { return groupDetails }); + } else { + return Promise.resolve(groupDetails); + } + })(groupDetails).then(function(groupDetails) { + var ev = new Event('group'); + ev.groupDetails = groupDetails; + eventTarget.dispatchEvent(ev); + }).catch(function(e) { + console.log('error processing group', e); + }); groupDetails = groupBuffer.next(); promises.push(promise); } diff --git a/js/models/conversations.js b/js/models/conversations.js index 681974a9..7644aed3 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -164,6 +164,7 @@ leaveGroup: function() { var now = Date.now(); if (this.get('type') === 'group') { + this.save({left: true}); var message = this.messageCollection.create({ group_update: { left: 'You' }, conversationId : this.id, diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index 050d75a0..dd8c8a7a 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -241,25 +241,29 @@ MessageReceiver.prototype.extend({ while (groupDetails !== undefined) { var promise = (function(groupDetails) { groupDetails.id = getString(groupDetails.id); - return textsecure.storage.groups.getGroup(groupDetails.id). - then(function(existingGroup) { - if (existingGroup === undefined) { - return textsecure.storage.groups.createNewGroup( - groupDetails.members, groupDetails.id - ); - } else { - return textsecure.storage.groups.updateNumbers( - groupDetails.id, groupDetails.members - ); - } - }).then(function() { - var ev = new Event('group'); - ev.groupDetails = groupDetails; - eventTarget.dispatchEvent(ev); - }).catch(function(e) { - console.log('error processing group', groupDetails.id, e); - }); - })(groupDetails); + if (groupDetails.active) { + return textsecure.storage.groups.getGroup(groupDetails.id). + then(function(existingGroup) { + if (existingGroup === undefined) { + return textsecure.storage.groups.createNewGroup( + groupDetails.members, groupDetails.id + ); + } else { + return textsecure.storage.groups.updateNumbers( + groupDetails.id, groupDetails.members + ); + } + }).then(function() { return groupDetails }); + } else { + return Promise.resolve(groupDetails); + } + })(groupDetails).then(function(groupDetails) { + var ev = new Event('group'); + ev.groupDetails = groupDetails; + eventTarget.dispatchEvent(ev); + }).catch(function(e) { + console.log('error processing group', e); + }); groupDetails = groupBuffer.next(); promises.push(promise); } diff --git a/protos/IncomingPushMessageSignal.proto b/protos/IncomingPushMessageSignal.proto index e8a7b42c..0c1df06f 100644 --- a/protos/IncomingPushMessageSignal.proto +++ b/protos/IncomingPushMessageSignal.proto @@ -97,6 +97,7 @@ message GroupDetails { optional string name = 2; repeated string members = 3; optional Avatar avatar = 4; + optional bool active = 5 [default = true]; } message ContactDetails {