From f51651ce8ea039a4cecf1fdf34d95b4c280aa382 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 5 Oct 2021 15:09:11 +1100 Subject: [PATCH] minor fix on conversation ordering --- SessionMessagingKit/Database/TSDatabaseView.m | 14 ++++++++++++-- SessionMessagingKit/Threads/TSThread.m | 4 +++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/SessionMessagingKit/Database/TSDatabaseView.m b/SessionMessagingKit/Database/TSDatabaseView.m index 42be55700..4668aeb44 100644 --- a/SessionMessagingKit/Database/TSDatabaseView.m +++ b/SessionMessagingKit/Database/TSDatabaseView.m @@ -278,8 +278,18 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" TSThread *thread1 = (TSThread *)object1; TSThread *thread2 = (TSThread *)object2; if ([group isEqualToString:TSArchiveGroup] || [group isEqualToString:TSInboxGroup]) { - NSDate *date1 = thread1.lastInteractionDate ?: thread1.creationDate; - NSDate *date2 = thread2.lastInteractionDate ?: thread2.creationDate; + + TSInteraction *_Nullable lastInteractionForInbox1 = + [thread1 lastInteractionForInboxWithTransaction:transaction]; + NSDate *lastInteractionForInboxDate1 = lastInteractionForInbox1 ? lastInteractionForInbox1.receivedAtDate : thread1.creationDate; + + TSInteraction *_Nullable lastInteractionForInbox2 = + [thread2 lastInteractionForInboxWithTransaction:transaction]; + NSDate *lastInteractionForInboxDate2 = lastInteractionForInbox2 ? lastInteractionForInbox2.receivedAtDate : thread2.creationDate; + + + NSDate *date1 = thread1.lastInteractionDate ?: lastInteractionForInboxDate1 ?: thread1.creationDate; + NSDate *date2 = thread2.lastInteractionDate ?: lastInteractionForInboxDate2 ?: thread2.creationDate; return [date1 compare:date2]; } diff --git a/SessionMessagingKit/Threads/TSThread.m b/SessionMessagingKit/Threads/TSThread.m index 8d4b81770..943709c2a 100644 --- a/SessionMessagingKit/Threads/TSThread.m +++ b/SessionMessagingKit/Threads/TSThread.m @@ -357,7 +357,9 @@ BOOL IsNoteToSelfEnabled(void) return; } - _lastInteractionDate = lastMessage.receivedAtDate; + if ([_lastInteractionDate compare: lastMessage.receivedAtDate] == NSOrderedAscending) { + _lastInteractionDate = lastMessage.receivedAtDate; + } if (!self.shouldBeVisible) { self.shouldBeVisible = YES;