diff --git a/LokiPushNotificationService/NotificationServiceExtension.swift b/LokiPushNotificationService/NotificationServiceExtension.swift
index f5aa06a9e..fe2e628dd 100644
--- a/LokiPushNotificationService/NotificationServiceExtension.swift
+++ b/LokiPushNotificationService/NotificationServiceExtension.swift
@@ -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() {} }
diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist
index b91d44ca3..af121ada0 100644
--- a/Signal/Signal-Info.plist
+++ b/Signal/Signal-Info.plist
@@ -5,9 +5,9 @@
BuildDetails
CarthageVersion
- 0.34.0
+ 0.35.0
OSXVersion
- 10.15.5
+ 10.15.6
WebRTCCommit
1445d719bf05280270e9f77576f80f973fd847f8 M73
diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m
index d00367ab4..7641580f4 100644
--- a/Signal/src/AppDelegate.m
+++ b/Signal/src/AppDelegate.m
@@ -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];
}
diff --git a/Signal/src/Loki/View Controllers/HomeVC.swift b/Signal/src/Loki/View Controllers/HomeVC.swift
index dfa9c5553..93df55a85 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)
@@ -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) {
diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m
index 51b7d009e..33f3667f4 100644
--- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m
+++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m
@@ -842,6 +842,8 @@ typedef enum : NSUInteger {
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
[self startReadTimer];
+ [self.conversationViewModel viewDidLoad];
+ [self.conversationViewModel loadAnotherPageOfMessages];
}
- (void)dismissPresentedViewControllerIfNecessary
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];
}