From 033492a2009870d1c2a7d55f98040d65d91ab26c Mon Sep 17 00:00:00 2001 From: Maxim Shishmarev Date: Mon, 13 Jan 2020 15:37:55 +1100 Subject: [PATCH 1/2] Sort messages by sent_at --- app/sql.js | 3 ++- js/models/messages.js | 6 +++--- libloki/api.js | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/sql.js b/app/sql.js index 034028b5e..0ad34d171 100644 --- a/app/sql.js +++ b/app/sql.js @@ -2339,6 +2339,7 @@ async function getUnreadByConversation(conversationId) { return map(rows, row => jsonToObject(row.json)); } +// Note: Sorting here is necessary for getting the last message (with limit 1) async function getMessagesByConversation( conversationId, { limit = 100, receivedAt = Number.MAX_VALUE, type = '%' } = {} @@ -2349,7 +2350,7 @@ async function getMessagesByConversation( conversationId = $conversationId AND received_at < $received_at AND type LIKE $type - ORDER BY received_at DESC + ORDER BY sent_at DESC LIMIT $limit; `, { diff --git a/js/models/messages.js b/js/models/messages.js index 4bdf62f14..05a7e8e17 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -2514,11 +2514,11 @@ Whisper.MessageCollection = Backbone.Collection.extend({ model: Whisper.Message, comparator(left, right) { - if (left.get('received_at') === right.get('received_at')) { - return (left.get('sent_at') || 0) - (right.get('sent_at') || 0); + if (left.get('sent_at') === right.get('sent_at')) { + return (left.get('received_at') || 0) - (right.get('received_at') || 0); } - return (left.get('received_at') || 0) - (right.get('received_at') || 0); + return (left.get('sent_at') || 0) - (right.get('sent_at') || 0); }, initialize(models, options) { if (options) { diff --git a/libloki/api.js b/libloki/api.js index bd252b4b4..54a7a2100 100644 --- a/libloki/api.js +++ b/libloki/api.js @@ -226,9 +226,12 @@ // Send const options = { messageType: 'pairing-request' }; const p = new Promise((resolve, reject) => { + + const timestamp = Date.now(); + const outgoingMessage = new textsecure.OutgoingMessage( null, // server - Date.now(), // timestamp, + timestamp, [recipientPubKey], // numbers content, // message true, // silent From 7a02d296740fdf543d2cddc8d933bdd4a721a9ae Mon Sep 17 00:00:00 2001 From: Maxim Shishmarev Date: Tue, 14 Jan 2020 11:43:10 +1100 Subject: [PATCH 2/2] Add missing sent_at for group update messages --- js/background.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/background.js b/js/background.js index ec9eb3581..8f218012e 100644 --- a/js/background.js +++ b/js/background.js @@ -728,6 +728,7 @@ ev.data = { source: ourKey, + timestamp: Date.now(), message: { group: { id: groupId,