Skip to content

Commit

Permalink
Set receivedAt after decrypt, sort by received then sent
Browse files Browse the repository at this point in the history
FREEBIE
  • Loading branch information
scottnonnenberg committed Aug 14, 2017
1 parent 4c7b174 commit 7e9ed14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 7 additions & 1 deletion js/models/messages.js
Expand Up @@ -589,7 +589,13 @@
model : Message,
database : Whisper.Database,
storeName : 'messages',
comparator : 'received_at',
comparator : function(left, right) {
if (left.get('received_at') === right.get('received_at')) {
return (left.get('sent_at') || 0) - (right.get('sent_at') || 0);
}

return (left.get('received_at') || 0) - (right.get('received_at') || 0);
},
initialize : function(models, options) {
if (options) {
this.conversation = options.conversation;
Expand Down
3 changes: 0 additions & 3 deletions libtextsecure/message_receiver.js
Expand Up @@ -81,7 +81,6 @@ MessageReceiver.prototype.extend({
}
return;
}
var receivedAt = Date.now();

this.incoming.push(textsecure.crypto.decryptWebsocketMessage(request.body, this.signalingKey).then(function(plaintext) {
var envelope = textsecure.protobuf.Envelope.decode(plaintext);
Expand All @@ -93,8 +92,6 @@ MessageReceiver.prototype.extend({
return request.respond(200, 'OK');
}

envelope.receivedAt = receivedAt;

return this.addToCache(envelope, plaintext).then(function() {
request.respond(200, 'OK');
this.queueEnvelope(envelope);
Expand Down

0 comments on commit 7e9ed14

Please sign in to comment.