Sort messages by sent_at

This commit is contained in:
Maxim Shishmarev 2020-01-13 15:37:55 +11:00
parent 5710c410c7
commit 033492a200
3 changed files with 9 additions and 5 deletions

View File

@ -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;
`,
{

View File

@ -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) {

View File

@ -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