From 42324b515d5cfc54e783a74ea92b78ab3d6271eb Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Fri, 11 Aug 2023 16:55:00 +0100 Subject: [PATCH] ios: only show "entity" notifications if the are enabled in the conversation (#2899) --- apps/ios/SimpleX NSE/NotificationService.swift | 6 +++++- apps/ios/SimpleXChat/ChatTypes.swift | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/ios/SimpleX NSE/NotificationService.swift b/apps/ios/SimpleX NSE/NotificationService.swift index 95050cae83..dc0af36981 100644 --- a/apps/ios/SimpleX NSE/NotificationService.swift +++ b/apps/ios/SimpleX NSE/NotificationService.swift @@ -127,7 +127,7 @@ class NotificationService: UNNotificationServiceExtension { logger.debug("NotificationService: receiveNtfMessages: apiGetNtfMessage \(String(describing: ntfMsgInfo), privacy: .public)") if let connEntity = ntfMsgInfo.connEntity { setBestAttemptNtf( - ntfMsgInfo.user.showNotifications + ntfMsgInfo.ntfsEnabled ? .nse(notification: createConnectionEventNtf(ntfMsgInfo.user, connEntity)) : .empty ) @@ -401,4 +401,8 @@ struct NtfMessages { var connEntity: ConnectionEntity? var msgTs: Date? var ntfMessages: [NtfMsgInfo] + + var ntfsEnabled: Bool { + user.showNotifications && (connEntity?.ntfsEnabled ?? false) + } } diff --git a/apps/ios/SimpleXChat/ChatTypes.swift b/apps/ios/SimpleXChat/ChatTypes.swift index 0e09d5ec8a..be8619395b 100644 --- a/apps/ios/SimpleXChat/ChatTypes.swift +++ b/apps/ios/SimpleXChat/ChatTypes.swift @@ -1466,6 +1466,8 @@ public struct SecurityCode: Decodable, Equatable { public struct UserContact: Decodable { public var userContactLinkId: Int64 +// public var connReqContact: String + public var groupId: Int64? public init(userContactLinkId: Int64) { self.userContactLinkId = userContactLinkId @@ -1927,6 +1929,16 @@ public enum ConnectionEntity: Decodable { return nil } } + + public var ntfsEnabled: Bool { + switch self { + case let .rcvDirectMsgConnection(contact): return contact?.chatSettings.enableNtfs ?? false + case let .rcvGroupMsgConnection(groupInfo, _): return groupInfo.chatSettings.enableNtfs + case .sndFileConnection: return false + case .rcvFileConnection: return false + case let .userContactConnection(userContact): return userContact.groupId == nil + } + } } public struct NtfMsgInfo: Decodable {