WIP: fix notification bugs

pull/241/head
Ryan ZHAO 5 years ago
parent 24a6b69ed8
commit 4daac36a3f

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

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

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

Loading…
Cancel
Save