Sort left pane via receivedAt/receivedAtMs, even via edits

This commit is contained in:
Scott Nonnenberg 2024-03-25 12:21:14 -07:00 committed by GitHub
parent a39e46db5c
commit 6bc6cc64c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 55 additions and 11 deletions

View file

@ -282,6 +282,8 @@ export type ConversationType = ReadonlyDeep<
isVerified?: boolean;
activeAt?: number;
timestamp?: number;
lastMessageReceivedAt?: number;
lastMessageReceivedAtMs?: number;
inboxPosition?: number;
left?: boolean;
lastMessage?: LastMessageType;

View file

@ -303,8 +303,9 @@ const collator = new Intl.Collator();
// phone numbers and contacts from scratch here again.
export const _getConversationComparator = () => {
return (left: ConversationType, right: ConversationType): number => {
const leftTimestamp = left.timestamp;
const rightTimestamp = right.timestamp;
// These two fields can be sorted with each other; they are timestamps
const leftTimestamp = left.lastMessageReceivedAtMs || left.timestamp;
const rightTimestamp = right.lastMessageReceivedAtMs || right.timestamp;
if (leftTimestamp && !rightTimestamp) {
return -1;
}
@ -315,6 +316,19 @@ export const _getConversationComparator = () => {
return rightTimestamp - leftTimestamp;
}
// This field looks like a timestamp, but is actually a counter
const leftCounter = left.lastMessageReceivedAt;
const rightCounter = right.lastMessageReceivedAt;
if (leftCounter && !rightCounter) {
return -1;
}
if (rightCounter && !leftCounter) {
return 1;
}
if (leftCounter && rightCounter && leftCounter !== rightCounter) {
return rightCounter - leftCounter;
}
if (
typeof left.inboxPosition === 'number' &&
typeof right.inboxPosition === 'number'