Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Conversation Screen Updating Bug #395

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions Session/Conversations/ConversationViewModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ @interface ConversationViewModel ()
@property (nonatomic) NSArray<id<ConversationViewItem>> *persistedViewItems;
@property (nonatomic) NSArray<TSOutgoingMessage *> *unsavedOutgoingMessages;

@property (nonatomic) BOOL hasUiDatabaseUpdatedExternally;

@end

#pragma mark -
Expand Down Expand Up @@ -551,9 +553,14 @@ - (void)clearUnreadMessagesIndicator
- (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
Expand All @@ -571,10 +578,12 @@ - (void)uiDatabaseDidUpdate:(NSNotification *)notification
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) {
Expand Down