Skip to content

Commit

Permalink
Remove unregistered group members
Browse files Browse the repository at this point in the history
Locally remove unregistered users from group membership lists.

Fixes #989
Related to signalapp/Signal-Android#6175
Closes #1052

// FREEBIE
  • Loading branch information
haffenloher authored and liliakai committed Feb 9, 2017
1 parent d2ddfc7 commit a768b94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@
message.save().then(this.trigger.bind(this,'newmessage', message));
},

addMemberLeft: function(source) {
var timestamp = Date.now();
var message = new Whisper.Message({
conversationId : this.id,
source : source,
type : 'incoming',
sent_at : timestamp,
received_at : timestamp,
group_update : {left: source}
});
message.save().then(this.trigger.bind(this,'newmessage', message));
},

onReadMessage: function(message) {
if (this.messageCollection.get(message.id)) {
this.messageCollection.get(message.id).fetch();
Expand Down
19 changes: 17 additions & 2 deletions js/models/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,36 @@
this.sendSyncMessage();
}.bind(this)).catch(function(result) {
var now = Date.now();
var errors;
var conversation = this.getConversation();
this.trigger('done');
if (result.dataMessage) {
this.set({dataMessage: result.dataMessage});
}

if (result instanceof Error) {
this.saveErrors(result);
errors = [result];
this.saveErrors(errors);
} else {
this.saveErrors(result.errors);
errors = result.errors;
this.saveErrors(errors);
if (result.successfulNumbers.length > 0) {
this.set({sent: true, expirationStartTimestamp: now});
this.sendSyncMessage();
}
}

if (conversation.get('type') === 'group') {
errors.forEach(function(e) {
if (e.name === 'UnregisteredUserError') {
textsecure.storage.groups.removeNumber(conversation.id, e.number);
conversation.addMemberLeft(e.number);
conversation.set({
members: _.without(conversation.get('members'), e.number)
});
}
});
}
}.bind(this));
},

Expand Down

0 comments on commit a768b94

Please sign in to comment.