Skip to content

Commit

Permalink
Merge pull request #395 from RyanRory/conversation-screen-update
Browse files Browse the repository at this point in the history
Fix Conversation Screen Updating Bug
  • Loading branch information
nielsandriesse committed Apr 20, 2021
2 parents 766c351 + 4c822f7 commit f09b02a
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit f09b02a

Please sign in to comment.