Serialize sending and adding messages to a convo
Previously, if a message was sent in between the receive time of an incoming message and the time it is actually added to the conversation's message collection (which only occurs later after several async callbacks), the incoming message would be inserted not-at-the-end of the collection since it is ordered by receive time. This tricked the front end into assuming the message was an older message instead of a new one. Fixes #490 // FREEBIE
This commit is contained in:
parent
f9a3c7817e
commit
762cb68721
2 changed files with 128 additions and 108 deletions
|
@ -112,7 +112,21 @@
|
|||
this.set({tokens: tokens});
|
||||
},
|
||||
|
||||
queueJob: function(callback) {
|
||||
var previous = this.pending || Promise.resolve();
|
||||
var current = this.pending = previous.then(callback, callback);
|
||||
|
||||
current.then(function() {
|
||||
if (this.pending === current) {
|
||||
delete this.pending;
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
return current;
|
||||
},
|
||||
|
||||
sendMessage: function(body, attachments) {
|
||||
this.queueJob(function() {
|
||||
var now = Date.now();
|
||||
var message = this.messageCollection.add({
|
||||
body : body,
|
||||
|
@ -142,6 +156,7 @@
|
|||
sendFunc = textsecure.messaging.sendMessageToGroup;
|
||||
}
|
||||
message.send(sendFunc(this.get('id'), body, attachments, now));
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
isSearchable: function() {
|
||||
|
|
|
@ -267,6 +267,8 @@
|
|||
conversationId = dataMessage.group.id;
|
||||
}
|
||||
var conversation = ConversationController.create({id: conversationId});
|
||||
conversation.queueJob(function() {
|
||||
return new Promise(function(resolve) {
|
||||
conversation.fetch().always(function() {
|
||||
var now = new Date().getTime();
|
||||
var attributes = { type: 'private' };
|
||||
|
@ -353,6 +355,9 @@
|
|||
conversation.save().then(function() {
|
||||
conversation.trigger('newmessage', message);
|
||||
conversation.notify(message);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue