From 4c822f7e550db1d7dbf6771b18820d86dad22d45 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO Date: Tue, 20 Apr 2021 15:12:14 +1000 Subject: [PATCH] fix the conversation screen doesn't update the messages from PN immediately. --- Session/Conversations/ConversationViewModel.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Session/Conversations/ConversationViewModel.m b/Session/Conversations/ConversationViewModel.m index 86ad1f5e7..590e91d15 100644 --- a/Session/Conversations/ConversationViewModel.m +++ b/Session/Conversations/ConversationViewModel.m @@ -196,6 +196,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic) NSArray> *persistedViewItems; @property (nonatomic) NSArray *unsavedOutgoingMessages; +@property (nonatomic) BOOL hasUiDatabaseUpdatedExternally; + @end #pragma mark - @@ -551,9 +553,14 @@ NS_ASSUME_NONNULL_BEGIN - (void)uiDatabaseDidUpdateExternally:(NSNotification *)notification { OWSAssertIsOnMainThread(); - // External database modifications (e.g. changes from another process such as the SAE) // are "flushed" using touchDbAsync when the app re-enters the foreground. + // NSE will trigger this when we receive a new message from remote PN, + // the touchDbAsync will trigger uiDatabaseDidUpdate but with a notification + // that does NOT include the recent update from NSE. + // This flag let the uiDatabaseDidUpdate know it needs to expect more update + // than those in the notification. + _hasUiDatabaseUpdatedExternally = true; } - (void)uiDatabaseWillUpdate:(NSNotification *)notification @@ -571,10 +578,12 @@ NS_ASSUME_NONNULL_BEGIN 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] && !_hasUiDatabaseUpdatedExternally) { [self.delegate conversationViewModelDidUpdate:ConversationUpdate.minorUpdate]; return; } + + _hasUiDatabaseUpdatedExternally = false; __block ConversationMessageMappingDiff *_Nullable diff = nil; [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {