diff --git a/Signal/src/Loki/View Controllers/HomeVC.swift b/Signal/src/Loki/View Controllers/HomeVC.swift index 39f913d70..69897504a 100644 --- a/Signal/src/Loki/View Controllers/HomeVC.swift +++ b/Signal/src/Loki/View Controllers/HomeVC.swift @@ -5,6 +5,8 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol private var isViewVisible = false { didSet { updateIsObservingDatabase() } } private var tableViewTopConstraint: NSLayoutConstraint! + private var hasDatabaseModifiedNotificationWhenInvisible = false + private var threads: YapDatabaseViewMappings = { let result = YapDatabaseViewMappings(groups: [ TSInboxGroup ], view: TSThreadDatabaseViewExtensionName) result.setIsReversed(true, forGroup: TSInboxGroup) @@ -229,10 +231,13 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol @objc private func handleYapDatabaseModifiedNotification(_ notification: Notification) { AssertIsOnMainThread() - guard isObservingDatabase else { return } let notifications = uiDatabaseConnection.beginLongLivedReadTransaction() let ext = uiDatabaseConnection.ext(TSThreadDatabaseViewExtensionName) as! YapDatabaseViewConnection let hasChanges = ext.hasChanges(forGroup: TSInboxGroup, in: notifications) + guard isObservingDatabase else { + hasDatabaseModifiedNotificationWhenInvisible = hasChanges + return + } guard hasChanges else { uiDatabaseConnection.read { transaction in self.threads.update(with: transaction) @@ -279,7 +284,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol @objc private func handleApplicationDidBecomeActiveNotification(_ notification: Notification) { updateIsObservingDatabase() - updateYDBThreadMapping() + if (hasDatabaseModifiedNotificationWhenInvisible) { + reload() + hasDatabaseModifiedNotificationWhenInvisible = false + } } @objc private func handleApplicationWillResignActiveNotification(_ notification: Notification) { diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index 4806bc202..22e717d35 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -193,6 +193,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess quotedMessage:[quotedReplyModel buildQuotedMessageForSending] contactShare:nil linkPreview:nil]; + [message save]; [BenchManager benchAsyncWithTitle:@"Saving outgoing message" @@ -200,7 +201,6 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess // To avoid blocking the send flow, we dispatch an async write from within this read // transaction [LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull writeTransaction) { - [message saveWithTransaction:writeTransaction]; OWSLinkPreview *_Nullable linkPreview = [self linkPreviewForLinkPreviewDraft:linkPreviewDraft diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index dd72453fe..1c97dc5ba 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1614,7 +1614,7 @@ NS_ASSUME_NONNULL_BEGIN // Update thread preview in inbox [masterThread touchWithTransaction:transaction]; - if (CurrentAppContext().isMainAppAndActive) { + if (CurrentAppContext().isMainApp) { [SSKEnvironment.shared.notificationsManager notifyUserForIncomingMessage:incomingMessage inThread:masterThread transaction:transaction]; }