From dcffdf83b9fb6dee4594e15d1ed1309e21452711 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:53:09 +0100 Subject: [PATCH] ios: show local notification when checking messages having received background notification (#549) * ios: show local notification when checking messages having received background notification * Update apps/ios/Shared/Model/NtfManager.swift Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com> * Update apps/ios/Shared/Model/NtfManager.swift Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com> Co-authored-by: JRoberts <8711996+jr-simplex@users.noreply.github.com> --- apps/ios/Shared/AppDelegate.swift | 2 ++ apps/ios/Shared/Model/NtfManager.swift | 20 +++++++++++++++++++- apps/ios/Shared/Model/SimpleXAPI.swift | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/ios/Shared/AppDelegate.swift b/apps/ios/Shared/AppDelegate.swift index 3a64ce6042..aeaf6decf8 100644 --- a/apps/ios/Shared/AppDelegate.swift +++ b/apps/ios/Shared/AppDelegate.swift @@ -61,6 +61,8 @@ class AppDelegate: NSObject, UIApplicationDelegate { } else if let checkMessages = ntfData["checkMessages"] as? Bool, checkMessages { // TODO check if app in background logger.debug("AppDelegate: didReceiveRemoteNotification: checkMessages") + // TODO remove + NtfManager.shared.notifyCheckingMessages() receiveMessages(completionHandler) } else if let smpQueue = ntfData["checkMessage"] as? String { // TODO check if app in background diff --git a/apps/ios/Shared/Model/NtfManager.swift b/apps/ios/Shared/Model/NtfManager.swift index 8861968b2c..1040a80201 100644 --- a/apps/ios/Shared/Model/NtfManager.swift +++ b/apps/ios/Shared/Model/NtfManager.swift @@ -15,6 +15,8 @@ let ntfActionAccept = "NTF_ACT_ACCEPT" let ntfCategoryContactRequest = "NTF_CAT_CONTACT_REQUEST" let ntfCategoryContactConnected = "NTF_CAT_CONTACT_CONNECTED" let ntfCategoryMessageReceived = "NTF_CAT_MESSAGE_RECEIVED" +// TODO remove +let ntfCategoryCheckingMessages = "NTF_CAT_CHECKING_MESSAGES" let appNotificationId = "chat.simplex.app.notification" @@ -108,6 +110,13 @@ class NtfManager: NSObject, UNUserNotificationCenterDelegate, ObservableObject { actions: [], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: NSLocalizedString("New message", comment: "notifications") + ), + // TODO remove + UNNotificationCategory( + identifier: ntfCategoryCheckingMessages, + actions: [], + intentIdentifiers: [], + hiddenPreviewsBodyPlaceholder: NSLocalizedString("Checking new messages...", comment: "notifications") ) ]) } @@ -167,7 +176,16 @@ class NtfManager: NSObject, UNUserNotificationCenterDelegate, ObservableObject { // userInfo: ["chatId": cInfo.id, "chatItemId": cItem.id] ) } - + + // TODO remove + func notifyCheckingMessages() { + logger.debug("NtfManager.notifyCheckingMessages") + addNotification( + categoryIdentifier: ntfCategoryCheckingMessages, + title: NSLocalizedString("Checking new messages...", comment: "notification") + ) + } + func hideSecrets(_ cItem: ChatItem) -> String { if let md = cItem.formattedText { var res = "" diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index e62b7e6d21..5067cd4b0f 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -99,7 +99,7 @@ enum ChatCommand { case .apiUpdateChatItem: return "apiUpdateChatItem" case .apiDeleteChatItem: return "apiDeleteChatItem" case .apiRegisterToken: return "apiRegisterToken" - case .apiVerifyToken: return "apiRegisterToken" + case .apiVerifyToken: return "apiVerifyToken" case .apiIntervalNofication: return "apiIntervalNofication" case .apiDeleteToken: return "apiDeleteToken" case .getUserSMPServers: return "getUserSMPServers"