add logs & fix PN
This commit is contained in:
parent
7fb6726d43
commit
8652268557
|
@ -106,6 +106,9 @@ class BaseVC : UIViewController {
|
|||
}
|
||||
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
if #available(iOS 13.0, *) {
|
||||
SNLog("Current trait collection: \(UITraitCollection.current), previous trait collection: \(previousTraitCollection)")
|
||||
}
|
||||
if LKAppModeUtilities.isSystemDefault {
|
||||
NotificationCenter.default.post(name: .appModeChanged, object: nil)
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ public final class OpenGroupPollerV2 : NSObject {
|
|||
guard let self = self else { return }
|
||||
self.isPolling = false
|
||||
bodies.forEach { self.handleCompactPollBody($0, isBackgroundPoll: isBackgroundPoll) }
|
||||
SNLog("Open group polling finished for \(self.server).")
|
||||
seal.fulfill(())
|
||||
}.catch(on: OpenGroupAPIV2.workQueue) { error in
|
||||
SNLog("Open group polling failed due to error: \(error).")
|
||||
|
|
|
@ -13,14 +13,14 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
|
|||
// to check if this is the only message request thread (group threads can't be message requests
|
||||
// so just ignore those and if the user has hidden message requests then we want to show the
|
||||
// notification regardless of how many message requests there are)
|
||||
if !thread.isGroupThread() && thread.isMessageRequest() && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
|
||||
if !thread.isGroupThread() && thread.isMessageRequest(using: transaction) && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
|
||||
let threads = transaction.ext(TSThreadDatabaseViewExtensionName) as! YapDatabaseViewTransaction
|
||||
let numMessageRequests = threads.numberOfItems(inGroup: TSMessageRequestGroup)
|
||||
|
||||
// Allow this to show a notification if there are no message requests (ie. this is the first one)
|
||||
guard numMessageRequests == 0 else { return }
|
||||
}
|
||||
else if thread.isMessageRequest() && CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
|
||||
else if thread.isMessageRequest(using: transaction) && CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
|
||||
// If there are other interactions on this thread already then don't show the notification
|
||||
if thread.numberOfInteractions(with: transaction) > 1 { return }
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
|
|||
}
|
||||
|
||||
let context = Contact.context(for: thread)
|
||||
let senderName = Storage.shared.getContact(with: senderPublicKey)?.displayName(for: context) ?? senderPublicKey
|
||||
let senderName = Storage.shared.getContact(with: senderPublicKey, using: transaction)?.displayName(for: context) ?? senderPublicKey
|
||||
|
||||
var notificationTitle = senderName
|
||||
if let group = thread as? TSGroupThread {
|
||||
|
@ -85,7 +85,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
|
|||
|
||||
// If it's a message request then overwrite the body to be something generic (only show a notification
|
||||
// when receiving a new message request if there aren't any others or the user had hidden them)
|
||||
if thread.isMessageRequest() {
|
||||
if thread.isMessageRequest(using: transaction) {
|
||||
notificationContent.title = "Session"
|
||||
notificationContent.body = "MESSAGE_REQUESTS_NOTIFICATION".localized()
|
||||
}
|
||||
|
@ -93,8 +93,16 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
|
|||
// Add request
|
||||
let identifier = incomingMessage.notificationIdentifier ?? UUID().uuidString
|
||||
let request = UNNotificationRequest(identifier: identifier, content: notificationContent, trigger: nil)
|
||||
SNLog("Add remote notification request")
|
||||
UNUserNotificationCenter.current().add(request)
|
||||
SNLog("Add remote notification request: \(notificationContent.body)")
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
UNUserNotificationCenter.current().add(request) { error in
|
||||
if let error = error {
|
||||
SNLog("Failed to add notification request due to error:\(error)")
|
||||
}
|
||||
semaphore.signal()
|
||||
}
|
||||
semaphore.wait()
|
||||
SNLog("Finish adding remote notification request")
|
||||
}
|
||||
|
||||
public func cancelNotification(_ identifier: String) {
|
||||
|
|
|
@ -41,7 +41,10 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension
|
|||
let envelope = try? MessageWrapper.unwrap(data: data), let envelopeAsData = try? envelope.serializedData() else {
|
||||
return self.handleFailure(for: notificationContent)
|
||||
}
|
||||
Storage.write { transaction in // Intentionally capture self
|
||||
// HACK: It is important to use writeSync() here to avoid a race condition
|
||||
// where the completeSilenty() is called before the local notification request
|
||||
// is added to notification center.
|
||||
Storage.writeSync { transaction in // Intentionally capture self
|
||||
do {
|
||||
let (message, proto) = try MessageReceiver.parse(envelopeAsData, openGroupMessageServerID: nil, using: transaction)
|
||||
switch message {
|
||||
|
|
Loading…
Reference in New Issue