diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 95784c316..4caedb50a 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -801,13 +801,13 @@ FD848B9628422A2A000E298B /* MessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD848B86283B844B000E298B /* MessageViewModel.swift */; }; FD848B9828422F1A000E298B /* Date+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD848B9728422F1A000E298B /* Date+Utilities.swift */; }; FD848B9A28442CE6000E298B /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD848B9928442CE6000E298B /* StorageError.swift */; }; - FD860CBC2D6E7A9F00BBE29C /* _024_FixBustedInteractionVariant.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CBB2D6E7A9400BBE29C /* _024_FixBustedInteractionVariant.swift */; }; - FD860CBE2D6E7DAA00BBE29C /* DeveloperSettingsViewModel+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CBD2D6E7DA000BBE29C /* DeveloperSettingsViewModel+Testing.swift */; }; - FD860CC92D6ED2ED00BBE29C /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = FD860CC82D6ED2ED00BBE29C /* DifferenceKit */; }; FD860CB42D668FD300BBE29C /* AppearanceViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CB32D668FD000BBE29C /* AppearanceViewModel.swift */; }; FD860CB62D66913F00BBE29C /* ThemePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CB52D66913B00BBE29C /* ThemePreviewView.swift */; }; FD860CB82D66BC9900BBE29C /* AppIconViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CB72D66BC9500BBE29C /* AppIconViewModel.swift */; }; FD860CBA2D66BF2A00BBE29C /* AppIconGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CB92D66BF2300BBE29C /* AppIconGridView.swift */; }; + FD860CBC2D6E7A9F00BBE29C /* _024_FixBustedInteractionVariant.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CBB2D6E7A9400BBE29C /* _024_FixBustedInteractionVariant.swift */; }; + FD860CBE2D6E7DAA00BBE29C /* DeveloperSettingsViewModel+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD860CBD2D6E7DA000BBE29C /* DeveloperSettingsViewModel+Testing.swift */; }; + FD860CC92D6ED2ED00BBE29C /* DifferenceKit in Frameworks */ = {isa = PBXBuildFile; productRef = FD860CC82D6ED2ED00BBE29C /* DifferenceKit */; }; FD86FDA32BC5020600EC251B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = FD86FDA22BC5020600EC251B /* PrivacyInfo.xcprivacy */; }; FD86FDA42BC51C5400EC251B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = FD86FDA22BC5020600EC251B /* PrivacyInfo.xcprivacy */; }; FD86FDA52BC51C5500EC251B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = FD86FDA22BC5020600EC251B /* PrivacyInfo.xcprivacy */; }; @@ -1990,12 +1990,12 @@ FD859EEF27BF207700510D0C /* SessionProtos.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = SessionProtos.proto; sourceTree = ""; }; FD859EF027BF207C00510D0C /* WebSocketResources.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = WebSocketResources.proto; sourceTree = ""; }; FD859EF127BF6BA200510D0C /* Data+Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Utilities.swift"; sourceTree = ""; }; - FD860CBB2D6E7A9400BBE29C /* _024_FixBustedInteractionVariant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _024_FixBustedInteractionVariant.swift; sourceTree = ""; }; - FD860CBD2D6E7DA000BBE29C /* DeveloperSettingsViewModel+Testing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DeveloperSettingsViewModel+Testing.swift"; sourceTree = ""; }; FD860CB32D668FD000BBE29C /* AppearanceViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceViewModel.swift; sourceTree = ""; }; FD860CB52D66913B00BBE29C /* ThemePreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemePreviewView.swift; sourceTree = ""; }; FD860CB72D66BC9500BBE29C /* AppIconViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconViewModel.swift; sourceTree = ""; }; FD860CB92D66BF2300BBE29C /* AppIconGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconGridView.swift; sourceTree = ""; }; + FD860CBB2D6E7A9400BBE29C /* _024_FixBustedInteractionVariant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _024_FixBustedInteractionVariant.swift; sourceTree = ""; }; + FD860CBD2D6E7DA000BBE29C /* DeveloperSettingsViewModel+Testing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DeveloperSettingsViewModel+Testing.swift"; sourceTree = ""; }; FD86FDA22BC5020600EC251B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; FD87DCF928B74DB300AF0F98 /* ConversationSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationSettingsViewModel.swift; sourceTree = ""; }; FD87DCFD28B7582C00AF0F98 /* BlockedContactsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockedContactsViewModel.swift; sourceTree = ""; }; @@ -6887,7 +6887,6 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 2.9.1; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -6957,7 +6956,6 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 2.9.1; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.ShareExtension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -7008,7 +7006,6 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 2.9.1; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -7081,7 +7078,6 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 2.9.1; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.NotificationServiceExtension"; @@ -7814,7 +7810,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; COMPILE_LIB_SESSION = ""; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 563; + CURRENT_PROJECT_VERSION = 567; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -7854,7 +7850,7 @@ HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include/**"; IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.2; + MARKETING_VERSION = 2.10.0; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-Werror=protocol"; OTHER_SWIFT_FLAGS = "-D DEBUG -Xfrontend -warn-long-expression-type-checking=100"; @@ -7894,7 +7890,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; COMPILE_LIB_SESSION = ""; - CURRENT_PROJECT_VERSION = 563; + CURRENT_PROJECT_VERSION = 567; ENABLE_BITCODE = NO; ENABLE_MODULE_VERIFIER = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -7929,7 +7925,7 @@ HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include/**"; IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.2; + MARKETING_VERSION = 2.10.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1", @@ -7959,7 +7955,6 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 566; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -8024,7 +8019,6 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 566; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -8419,7 +8413,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; COMPILE_LIB_SESSION = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 563; + CURRENT_PROJECT_VERSION = 567; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -8461,7 +8455,7 @@ ); IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.2; + MARKETING_VERSION = 2.10.0; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = ( "-fobjc-arc-exceptions", @@ -8490,7 +8484,6 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 488; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -9058,7 +9051,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; COMPILE_LIB_SESSION = YES; - CURRENT_PROJECT_VERSION = 563; + CURRENT_PROJECT_VERSION = 567; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_NO_COMMON_BLOCKS = YES; @@ -9094,7 +9087,7 @@ ); IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.2; + MARKETING_VERSION = 2.10.0; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1", @@ -9122,7 +9115,6 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 488; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -10063,7 +10055,7 @@ repositoryURL = "https://github.com/session-foundation/libsession-util-spm"; requirement = { kind = exactVersion; - version = 1.2.1; + version = 1.3.0; }; }; FD6A38E72C2A630E00762359 /* XCRemoteSwiftPackageReference "CocoaLumberjack" */ = { diff --git a/Session.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Session.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index bf1dbacc9..8d90dc6d3 100644 --- a/Session.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Session.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -51,8 +51,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/session-foundation/libsession-util-spm", "state" : { - "revision" : "dfa9ad8df694cde779323ffcd9c2426d71eb6bdc", - "version" : "1.2.1" + "revision" : "51580552aef35e52a3ae99ec72df2d70026ef415", + "version" : "1.3.0" } }, { diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 28abcc310..e47dd0eca 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -400,13 +400,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD // Immediately cancel the timer to prevent the timeout being triggered timer.cancel() - // Update the unread count badge - let unreadCount: Int = dependencies[singleton: .storage] - .read { db in try Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) } - .defaulting(to: 0) - - DispatchQueue.main.async(using: dependencies) { - UIApplication.shared.applicationIconBadgeNumber = unreadCount + // Update the app badge in case the unread count changed + if + let unreadCount: Int = dependencies[singleton: .storage].read({ db in + try Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) + }) + { + DispatchQueue.main.async(using: dependencies) { + UIApplication.shared.applicationIconBadgeNumber = unreadCount + } } // If we are still running in the background then suspend the network & database @@ -801,9 +803,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD /// read pools (up to a few seconds), since this read is blocking we want to dispatch it to run async to ensure /// we don't block user interaction while it's running DispatchQueue.global(qos: .default).async { - let unreadCount: Int = dependencies[singleton: .storage] - .read { db in try Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) } - .defaulting(to: 0) + guard + let unreadCount: Int = dependencies[singleton: .storage].read({ db in try + Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) + }) + else { return } DispatchQueue.main.async(using: dependencies) { UIApplication.shared.applicationIconBadgeNumber = unreadCount diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index cba6af01a..8073ca13e 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -354,7 +354,7 @@ public extension Message { return variant.messageType.fromProto(proto, sender: sender, using: dependencies) } - return try decodedMessage ?? { throw MessageReceiverError.unknownMessage }() + return try decodedMessage ?? { throw MessageReceiverError.unknownMessage(proto) }() } static func requiresExistingConversation(message: Message, threadVariant: SessionThread.Variant) -> Bool { diff --git a/SessionMessagingKit/Sending & Receiving/Errors/MessageReceiverError.swift b/SessionMessagingKit/Sending & Receiving/Errors/MessageReceiverError.swift index aa6376066..f4fbc0708 100644 --- a/SessionMessagingKit/Sending & Receiving/Errors/MessageReceiverError.swift +++ b/SessionMessagingKit/Sending & Receiving/Errors/MessageReceiverError.swift @@ -4,13 +4,13 @@ import Foundation -public enum MessageReceiverError: LocalizedError { +public enum MessageReceiverError: Error, CustomStringConvertible { case duplicateMessage case duplicateMessageNewSnode case duplicateControlMessage case invalidMessage case invalidSender - case unknownMessage + case unknownMessage(SNProtoContent?) case unknownEnvelopeType case noUserX25519KeyPair case noUserED25519KeyPair @@ -55,14 +55,49 @@ public enum MessageReceiverError: LocalizedError { } } - public var errorDescription: String? { + public var description: String { switch self { case .duplicateMessage: return "Duplicate message." case .duplicateMessageNewSnode: return "Duplicate message from different service node." case .duplicateControlMessage: return "Duplicate control message." case .invalidMessage: return "Invalid message." case .invalidSender: return "Invalid sender." - case .unknownMessage: return "Unknown message type." + case .unknownMessage(let content): + switch content { + case .none: return "Unknown message type (no content)." + case .some(let content): + let protoInfo: [(String, Bool)] = [ + ("hasDataMessage", (content.dataMessage != nil)), + ("hasProfile", (content.dataMessage?.profile != nil)), + ("hasBody", (content.dataMessage?.hasBody == true)), + ("hasAttachments", (content.dataMessage?.attachments.isEmpty == false)), + ("hasReaction", (content.dataMessage?.reaction != nil)), + ("hasQuote", (content.dataMessage?.quote != nil)), + ("hasLinkPreview", (content.dataMessage?.preview != nil)), + ("hasOpenGroupInvitation", (content.dataMessage?.openGroupInvitation != nil)), + ("hasLegacyGroupControlMessage", (content.dataMessage?.closedGroupControlMessage != nil)), + ("hasGroupV2ControlMessage", (content.dataMessage?.groupUpdateMessage != nil)), + ("hasTimestamp", (content.dataMessage?.hasTimestamp == true)), + ("hasSyncTarget", (content.dataMessage?.hasSyncTarget == true)), + ("hasBlocksCommunityMessageRequests", (content.dataMessage?.hasBlocksCommunityMessageRequests == true)), + ("hasCallMessage", (content.callMessage != nil)), + ("hasReceiptMessage", (content.receiptMessage != nil)), + ("hasTypingMessage", (content.typingMessage != nil)), + ("hasDataExtractionMessage", (content.dataExtractionNotification != nil)), + ("hasUnsendRequest", (content.unsendRequest != nil)), + ("hasMessageRequestResponse", (content.messageRequestResponse != nil)), + ("hasExpirationTimer", (content.hasExpirationTimer == true)), + ("hasExpirationType", (content.hasExpirationType == true)), + ("hasSigTimestamp", (content.hasSigTimestamp == true)) + ] + + let protoInfoString: String = protoInfo + .filter { _, val in val } + .map { name, _ in name } + .joined(separator: ", ") + return "Unknown message type (\(protoInfoString))." + } + case .unknownEnvelopeType: return "Unknown envelope type." case .noUserX25519KeyPair: return "Couldn't find user X25519 key pair." case .noUserED25519KeyPair: return "Couldn't find user ED25519 key pair." diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index cf1eef906..a7dd2e1fa 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -234,7 +234,7 @@ public enum MessageReceiver { case .all, .unknown: Log.warn(.messageReceiver, "Couldn't process message due to invalid namespace.") - throw MessageReceiverError.unknownMessage + throw MessageReceiverError.unknownMessage(nil) } } @@ -440,7 +440,7 @@ public enum MessageReceiver { using: dependencies ) - default: throw MessageReceiverError.unknownMessage + default: throw MessageReceiverError.unknownMessage(proto) } // Perform any required post-handling logic diff --git a/SessionNotificationServiceExtension/NSENotificationPresenter.swift b/SessionNotificationServiceExtension/NSENotificationPresenter.swift index 94f820907..f0741a19c 100644 --- a/SessionNotificationServiceExtension/NSENotificationPresenter.swift +++ b/SessionNotificationServiceExtension/NSENotificationPresenter.swift @@ -89,9 +89,11 @@ public class NSENotificationPresenter: NotificationsManagerType { notificationContent.sound = thread.notificationSound .defaulting(to: db[.defaultNotificationSound] ?? Preferences.Sound.defaultNotificationSound) .notificationSound(isQuiet: false) - notificationContent.badge = (try? Interaction.fetchAppBadgeUnreadCount(db, using: dependencies)) - .map { NSNumber(value: $0) } - .defaulting(to: NSNumber(value: 0)) + + /// Update the app badge in case the unread count changed + if let unreadCount: Int = try? Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) { + notificationContent.badge = NSNumber(value: unreadCount) + } // Title & body let previewType: Preferences.NotificationPreviewType = db[.preferencesNotificationPreviewType] @@ -198,9 +200,11 @@ public class NSENotificationPresenter: NotificationsManagerType { notificationContent.sound = thread.notificationSound .defaulting(to: db[.defaultNotificationSound] ?? Preferences.Sound.defaultNotificationSound) .notificationSound(isQuiet: false) - notificationContent.badge = (try? Interaction.fetchAppBadgeUnreadCount(db, using: dependencies)) - .map { NSNumber(value: $0) } - .defaulting(to: NSNumber(value: 0)) + + /// Update the app badge in case the unread count changed + if let unreadCount: Int = try? Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) { + notificationContent.badge = NSNumber(value: unreadCount) + } notificationContent.title = Constants.app_name notificationContent.body = "" diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 265d72cad..8603da1bf 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -478,10 +478,15 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension switch resolution { case .ignoreDueToMainAppRunning: break default: - silentContent.badge = dependencies[singleton: .storage] - .read { [dependencies] db in try Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) } - .map { NSNumber(value: $0) } - .defaulting(to: NSNumber(value: 0)) + /// Update the app badge in case the unread count changed + if + let unreadCount: Int = dependencies[singleton: .storage].read({ [dependencies] db in + try Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) + }) + { + silentContent.badge = NSNumber(value: unreadCount) + } + dependencies[singleton: .storage].suspendDatabaseAccess() } @@ -545,9 +550,11 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension let notificationContent = UNMutableNotificationContent() notificationContent.userInfo = [ NotificationServiceExtension.isFromRemoteKey : true ] notificationContent.title = Constants.app_name - notificationContent.badge = (try? Interaction.fetchAppBadgeUnreadCount(db, using: dependencies)) - .map { NSNumber(value: $0) } - .defaulting(to: NSNumber(value: 0)) + + /// Update the app badge in case the unread count changed + if let unreadCount: Int = try? Interaction.fetchAppBadgeUnreadCount(db, using: dependencies) { + notificationContent.badge = NSNumber(value: unreadCount) + } if let sender: String = callMessage.sender { let senderDisplayName: String = Profile.displayName(db, id: sender, threadVariant: .contact, using: dependencies) diff --git a/SessionSnodeKit/Types/BatchResponse.swift b/SessionSnodeKit/Types/BatchResponse.swift index cc2919571..e9af2affd 100644 --- a/SessionSnodeKit/Types/BatchResponse.swift +++ b/SessionSnodeKit/Types/BatchResponse.swift @@ -150,6 +150,7 @@ extension Network.BatchSubResponse: Decodable { // MARK: - ErasedBatchSubResponse public protocol ErasedBatchSubResponse: ResponseInfoType { + var code: Int { get } var erasedBody: Any? { get } var failedToParseBody: Bool { get } } diff --git a/SessionUtilitiesKit/Database/Storage.swift b/SessionUtilitiesKit/Database/Storage.swift index 6bd11ded3..fa4a9e3da 100644 --- a/SessionUtilitiesKit/Database/Storage.swift +++ b/SessionUtilitiesKit/Database/Storage.swift @@ -578,7 +578,10 @@ open class Storage { switch error { case DatabaseError.SQLITE_ABORT, DatabaseError.SQLITE_INTERRUPT, DatabaseError.SQLITE_ERROR: let message: String = ((error as? DatabaseError)?.message ?? "Unknown") - Log.error(.storage, "Database \(action) failed due to error: \(message) - [ \(info.callInfo) ]") + Log.error(.storage, "Database \(action) failed due to error: \(message)") + + case StorageError.databaseInvalid: + Log.error(.storage, "Database \(action) failed as the database is invalid.") case StorageError.databaseInvalid: Log.error(.storage, "Database \(action) failed as the database is invalid - [ \(info.callInfo) ]")