Merge pull request #241 from RyanRory/notification-bugs

Fix notification bugs
This commit is contained in:
Niels Andriesse 2020-08-03 10:26:02 +10:00 committed by GitHub
commit f9a8ce7fd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 5 deletions

View File

@ -16,6 +16,14 @@ final class NotificationServiceExtension : UNNotificationServiceExtension {
self.contentHandler = contentHandler
notificationContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
var isMainAppActive = false
if let sharedUserDefaults = UserDefaults(suiteName: "group.com.loki-project.loki-messenger") {
isMainAppActive = sharedUserDefaults.bool(forKey: "isMainAppActive")
}
print("[Ryan debug] isMainAppActive \(isMainAppActive)")
// If the main app is running, skip the whole process
guard !isMainAppActive else { return self.completeWithFailure(content: notificationContent!) }
// The code using DispatchQueue.main.async { self.setUpIfNecessary() { Modify the notification content } } will somehow cause a freeze when a second PN comes
DispatchQueue.main.sync { self.setUpIfNecessary() {} }

View File

@ -5,9 +5,9 @@
<key>BuildDetails</key>
<dict>
<key>CarthageVersion</key>
<string>0.34.0</string>
<string>0.35.0</string>
<key>OSXVersion</key>
<string>10.15.5</string>
<string>10.15.6</string>
<key>WebRTCCommit</key>
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
</dict>

View File

@ -306,6 +306,10 @@ static NSTimeInterval launchStartedAt;
if (CurrentAppContext().isRunningTests) {
return;
}
NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.loki-project.loki-messenger"];
[sharedUserDefaults setBool:true forKey:@"isMainAppActive"];
[sharedUserDefaults synchronize];
[self ensureRootViewController];
@ -333,6 +337,10 @@ static NSTimeInterval launchStartedAt;
}
[self clearAllNotificationsAndRestoreBadgeCount];
NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.loki-project.loki-messenger"];
[sharedUserDefaults setBool:false forKey:@"isMainAppActive"];
[sharedUserDefaults synchronize];
[DDLog flushLog];
}

View File

@ -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)
@ -275,6 +280,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, UIScrol
@objc private func handleApplicationDidBecomeActiveNotification(_ notification: Notification) {
updateIsObservingDatabase()
if (hasDatabaseModifiedNotificationWhenInvisible) {
reload()
hasDatabaseModifiedNotificationWhenInvisible = false
}
}
@objc private func handleApplicationWillResignActiveNotification(_ notification: Notification) {

View File

@ -842,6 +842,8 @@ typedef enum : NSUInteger {
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
[self startReadTimer];
[self.conversationViewModel viewDidLoad];
[self.conversationViewModel loadAnotherPageOfMessages];
}
- (void)dismissPresentedViewControllerIfNecessary

View File

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

View File

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