From ceb88f3d00c9cdf2f9993be07674271b402382dc Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 1 Oct 2021 16:29:02 +1000 Subject: [PATCH] prevent disappearing message affecting the order of conversations --- SessionMessagingKit/Database/TSDatabaseView.m | 11 ++--------- SessionMessagingKit/Threads/TSThread.h | 1 + SessionMessagingKit/Threads/TSThread.m | 3 +++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/SessionMessagingKit/Database/TSDatabaseView.m b/SessionMessagingKit/Database/TSDatabaseView.m index 9d1073fc3..42be55700 100644 --- a/SessionMessagingKit/Database/TSDatabaseView.m +++ b/SessionMessagingKit/Database/TSDatabaseView.m @@ -278,15 +278,8 @@ NSString *const TSLazyRestoreAttachmentsGroup = @"TSLazyRestoreAttachmentsGroup" TSThread *thread1 = (TSThread *)object1; TSThread *thread2 = (TSThread *)object2; if ([group isEqualToString:TSArchiveGroup] || [group isEqualToString:TSInboxGroup]) { - - TSInteraction *_Nullable lastInteractionForInbox1 = - [thread1 lastInteractionForInboxWithTransaction:transaction]; - NSDate *date1 = lastInteractionForInbox1 ? lastInteractionForInbox1.receivedAtDate : thread1.creationDate; - - TSInteraction *_Nullable lastInteractionForInbox2 = - [thread2 lastInteractionForInboxWithTransaction:transaction]; - NSDate *date2 = lastInteractionForInbox2 ? lastInteractionForInbox2.receivedAtDate : thread2.creationDate; - + NSDate *date1 = thread1.lastInteractionDate ?: thread1.creationDate; + NSDate *date2 = thread2.lastInteractionDate ?: thread2.creationDate; return [date1 compare:date2]; } diff --git a/SessionMessagingKit/Threads/TSThread.h b/SessionMessagingKit/Threads/TSThread.h index 7ed517919..aa333d245 100644 --- a/SessionMessagingKit/Threads/TSThread.h +++ b/SessionMessagingKit/Threads/TSThread.h @@ -18,6 +18,7 @@ BOOL IsNoteToSelfEnabled(void); @property (nonatomic) BOOL shouldBeVisible; @property (nonatomic, readonly) NSDate *creationDate; +@property (nonatomic, readonly, nullable) NSDate *lastInteractionDate; @property (nonatomic, readonly) TSInteraction *lastInteraction; @property (atomic, readonly) BOOL isMuted; @property (atomic, readonly, nullable) NSDate *mutedUntilDate; diff --git a/SessionMessagingKit/Threads/TSThread.m b/SessionMessagingKit/Threads/TSThread.m index dbfa1ecd4..8d4b81770 100644 --- a/SessionMessagingKit/Threads/TSThread.m +++ b/SessionMessagingKit/Threads/TSThread.m @@ -21,6 +21,7 @@ BOOL IsNoteToSelfEnabled(void) @interface TSThread () @property (nonatomic) NSDate *creationDate; +@property (nonatomic, nullable) NSDate *lastInteractionDate; @property (nonatomic, nullable) NSNumber *archivedAsOfMessageSortId; @property (nonatomic, copy, nullable) NSString *messageDraft; @property (atomic, nullable) NSDate *mutedUntilDate; @@ -355,6 +356,8 @@ BOOL IsNoteToSelfEnabled(void) if (![self.class shouldInteractionAppearInInbox:lastMessage]) { return; } + + _lastInteractionDate = lastMessage.receivedAtDate; if (!self.shouldBeVisible) { self.shouldBeVisible = YES;