reload ThreadDetails ViewItem whenever its present

This commit is contained in:
Michael Kirk 2019-08-21 10:57:53 -06:00
parent 952fa2823f
commit 8e73133ffe
2 changed files with 28 additions and 8 deletions

View File

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

View File

@ -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<NSString *> *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];
}