Sort messages by sent_at

pull/718/head
Maxim Shishmarev 5 years ago
parent 5710c410c7
commit 033492a200

@ -2339,6 +2339,7 @@ async function getUnreadByConversation(conversationId) {
return map(rows, row => jsonToObject(row.json)); return map(rows, row => jsonToObject(row.json));
} }
// Note: Sorting here is necessary for getting the last message (with limit 1)
async function getMessagesByConversation( async function getMessagesByConversation(
conversationId, conversationId,
{ limit = 100, receivedAt = Number.MAX_VALUE, type = '%' } = {} { limit = 100, receivedAt = Number.MAX_VALUE, type = '%' } = {}
@ -2349,7 +2350,7 @@ async function getMessagesByConversation(
conversationId = $conversationId AND conversationId = $conversationId AND
received_at < $received_at AND received_at < $received_at AND
type LIKE $type type LIKE $type
ORDER BY received_at DESC ORDER BY sent_at DESC
LIMIT $limit; LIMIT $limit;
`, `,
{ {

@ -2514,11 +2514,11 @@
Whisper.MessageCollection = Backbone.Collection.extend({ Whisper.MessageCollection = Backbone.Collection.extend({
model: Whisper.Message, model: Whisper.Message,
comparator(left, right) { comparator(left, right) {
if (left.get('received_at') === right.get('received_at')) { if (left.get('sent_at') === right.get('sent_at')) {
return (left.get('sent_at') || 0) - (right.get('sent_at') || 0); 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) { initialize(models, options) {
if (options) { if (options) {

@ -226,9 +226,12 @@
// Send // Send
const options = { messageType: 'pairing-request' }; const options = { messageType: 'pairing-request' };
const p = new Promise((resolve, reject) => { const p = new Promise((resolve, reject) => {
const timestamp = Date.now();
const outgoingMessage = new textsecure.OutgoingMessage( const outgoingMessage = new textsecure.OutgoingMessage(
null, // server null, // server
Date.now(), // timestamp, timestamp,
[recipientPubKey], // numbers [recipientPubKey], // numbers
content, // message content, // message
true, // silent true, // silent

Loading…
Cancel
Save