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