From 8e73133ffeeac213ffb47b520d89bd5d15f33e6c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 21 Aug 2019 10:57:53 -0600 Subject: [PATCH] reload ThreadDetails ViewItem whenever its present --- .../ConversationMessageMapping.swift | 16 +++++++++------ .../ConversationView/ConversationViewModel.m | 20 +++++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationMessageMapping.swift b/Signal/src/ViewControllers/ConversationView/ConversationMessageMapping.swift index 782624a86c..59378650c5 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationMessageMapping.swift +++ b/Signal/src/ViewControllers/ConversationView/ConversationMessageMapping.swift @@ -109,6 +109,11 @@ public class ConversationMessageMapping: NSObject { try update(transaction: transaction) } + @objc + var shouldShowThreadDetails: Bool { + return !canLoadMore && !isNoteToSelf + } + // This is the core method of the class. It updates the state to // reflect the latest database state & the current desired length. @objc @@ -152,20 +157,19 @@ public class ConversationMessageMapping: NSObject { beforePivotCount += 1 } } + self.canLoadMore = canLoadMore - if canLoadMore || isNoteToSelf { - // The items need to be reversed, since we load them in reverse order. - self.loadedInteractions = Array(newInteractions.reversed()) - } else { + if self.shouldShowThreadDetails { // We only show the thread details if we're at the start of the conversation let details = ThreadDetailsInteraction(thread: self.thread, timestamp: NSDate.ows_millisecondTimeStamp()) self.loadedInteractions = [details] + Array(newInteractions.reversed()) + } else { + // The items need to be reversed, since we load them in reverse order. + self.loadedInteractions = Array(newInteractions.reversed()) } - self.canLoadMore = canLoadMore - // Establish the pivot, if necessary and possible. // // Deserializing interactions is expensive. We only need to deserialize diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m index 656dbdb84e..3348f3521f 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m @@ -591,6 +591,14 @@ static const int kYapDatabaseRangeMaxLength = 25000; error:&updateError]; }]; + // If we have a thread details item, insert it into the updated items. We assume + // it always needs to update, because it's rarely actually loaded and can be changed + // by a large number of thread updates. + if (self.messageMapping.shouldShowThreadDetails) { + updatedInteractionIds = [updatedInteractionIds setByAddingObject:OWSThreadDetailsInteraction.ThreadDetailsId]; + } + + if (dbError || updateError || !updatedInteractionIds) { OWSFailDebug(@"failure: %@, %@", dbError, updateError); [self resetMappingWithSneakyTransaction]; @@ -629,13 +637,21 @@ static const int kYapDatabaseRangeMaxLength = 25000; YapDatabaseAutoViewConnection *messageDatabaseView = [self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName]; OWSAssertDebug([messageDatabaseView isKindOfClass:[YapDatabaseAutoViewConnection class]]); - if (![messageDatabaseView hasChangesForGroup:self.thread.uniqueId inNotifications:notifications]) { + if (![messageDatabaseView hasChangesForGroup:self.thread.uniqueId inNotifications:notifications] + && !self.messageMapping.shouldShowThreadDetails) { [self.delegate conversationViewModelDidUpdateWithSneakyTransaction:ConversationUpdate.minorUpdate]; return; } NSSet *updatedInteractionIds = [self.messageMapping updatedItemIdsFor:notifications]; + // If we have a thread details item, insert it into the updated items. We assume + // it always needs to update, because it's rarely actually loaded and can be changed + // by a large number of thread updates. + if (self.messageMapping.shouldShowThreadDetails) { + updatedInteractionIds = [updatedInteractionIds setByAddingObject:OWSThreadDetailsInteraction.ThreadDetailsId]; + } + [self anyDBDidUpdateWithUpdatedInteractionIds:updatedInteractionIds]; } @@ -1465,7 +1481,7 @@ static const int kYapDatabaseRangeMaxLength = 25000; if ([viewItem.interaction isKindOfClass:OWSThreadDetailsInteraction.class]) { // Thread details is not a persisted interaction. // It carries no mutable state, so there's no reason to reload it here. - interaction = interaction; + interaction = viewItem.interaction; } else { interaction = [TSInteraction anyFetchWithUniqueId:viewItem.interaction.uniqueId transaction:transaction]; }