From 3bb11aeac10a08262dbd862e0208ff0fdd90d549 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 21 Nov 2023 12:46:44 +1100 Subject: [PATCH] Fixed the broken legacy group push notifications & CI tweaks Fixed the broken legacy group push notifications Reset and close the simulators before/after the tests are run on the CI --- .drone.jsonnet | 11 +++++ LibSession-Util | 2 +- SessionMessagingKit/Messages/Message.swift | 8 ++-- .../Sending & Receiving/MessageReceiver.swift | 2 +- .../Models/NotificationMetadata.swift | 44 ++++++++++++++----- .../Notifications/PushNotificationAPI.swift | 5 ++- .../Sending & Receiving/Pollers/Poller.swift | 3 +- .../NotificationServiceExtension.swift | 10 ++--- 8 files changed, 59 insertions(+), 26 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index b2546206e..f95775934 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -81,6 +81,13 @@ local update_cocoapods_cache = { clone_submodules, load_cocoapods_cache, install_cocoapods, + { + name: 'Reset Simulators', + commands: [ + 'xcrun simctl shutdown all', + 'xcrun simctl erase all' + ], + }, { name: 'Run Unit Tests', commands: [ @@ -88,6 +95,10 @@ local update_cocoapods_cache = { 'NSUnbufferedIO=YES set -o pipefail && xcodebuild test -workspace Session.xcworkspace -scheme Session -derivedDataPath ./build/derivedData -destination "platform=iOS Simulator,name=iPhone 14" -destination "platform=iOS Simulator,name=iPhone 14 Pro Max" -parallel-testing-enabled YES -test-timeouts-enabled YES -maximum-test-execution-time-allowance 2 -collect-test-diagnostics never 2>&1 | ./Pods/xcbeautify/xcbeautify --is-ci --report junit --report-path ./build/reports --junit-report-filename junit2.xml' ], }, + { + name: 'Sutdown Simulators', + commands: [ 'xcrun simctl shutdown all' ], + }, update_cocoapods_cache ], }, diff --git a/LibSession-Util b/LibSession-Util index aa6d67b3f..73c22f2ce 160000 --- a/LibSession-Util +++ b/LibSession-Util @@ -1 +1 @@ -Subproject commit aa6d67b3f48d0ddb98fcf678e9aab0803ba388af +Subproject commit 73c22f2ce5ca0b8fb8b94a2eb6acf0bea8084b2f diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index 1a9a3fe88..32d822b0f 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -359,7 +359,7 @@ public extension Message { _ db: Database, rawMessage: SnodeReceivedMessage, publicKey: String, - using dependencies: Dependencies = Dependencies() + using dependencies: Dependencies ) throws -> ProcessedMessage { do { let processedMessage: ProcessedMessage = try processRawReceivedMessage( @@ -423,7 +423,7 @@ public extension Message { _ db: Database, data: Data, metadata: PushNotificationAPI.NotificationMetadata, - using dependencies: Dependencies = Dependencies() + using dependencies: Dependencies ) throws -> ProcessedMessage? { let processedMessage: ProcessedMessage? = try processRawReceivedMessage( db, @@ -475,7 +475,7 @@ public extension Message { data: Data, isOutgoing: Bool, otherBlindedPublicKey: String, - using dependencies: Dependencies = Dependencies() + using dependencies: Dependencies ) throws -> ProcessedMessage? { return try processRawReceivedMessage( db, @@ -496,7 +496,7 @@ public extension Message { openGroupId: String, message: OpenGroupAPI.Message, associatedPendingChanges: [OpenGroupAPI.PendingChange], - using dependencies: Dependencies = Dependencies() + using dependencies: Dependencies ) -> [Reaction] { guard let reactions: [String: OpenGroupAPI.Message.Reaction] = message.reactions else { return [] } diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift index 42675c0f7..4b65d1d9d 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver.swift @@ -14,7 +14,7 @@ public enum MessageReceiver { _ db: Database, data: Data, origin: Message.Origin, - using dependencies: Dependencies = Dependencies() + using dependencies: Dependencies ) throws -> ProcessedMessage { let userSessionId: SessionId = getUserSessionId(db, using: dependencies) var plaintext: Data diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/Models/NotificationMetadata.swift b/SessionMessagingKit/Sending & Receiving/Notifications/Models/NotificationMetadata.swift index 8a477635d..97ca60735 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/Models/NotificationMetadata.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/Models/NotificationMetadata.swift @@ -41,19 +41,9 @@ extension PushNotificationAPI { } } +// MARK: - Decodable + extension PushNotificationAPI.NotificationMetadata { - static var invalid: PushNotificationAPI.NotificationMetadata { - PushNotificationAPI.NotificationMetadata( - accountId: "", - hash: "", - namespace: .unknown, - createdTimestampMs: 0, - expirationTimestampMs: 0, - dataLength: 0, - dataTooLong: false - ) - } - public init(from decoder: Decoder) throws { let container: KeyedDecodingContainer = try decoder.container(keyedBy: CodingKeys.self) @@ -72,3 +62,33 @@ extension PushNotificationAPI.NotificationMetadata { ) } } + +// MARK: - Convenience + +extension PushNotificationAPI.NotificationMetadata { + static var invalid: PushNotificationAPI.NotificationMetadata { + PushNotificationAPI.NotificationMetadata( + accountId: "", + hash: "", + namespace: .unknown, + createdTimestampMs: 0, + expirationTimestampMs: 0, + dataLength: 0, + dataTooLong: false + ) + } + + static func legacyGroupMessage(envelope: SNProtoEnvelope) throws -> PushNotificationAPI.NotificationMetadata { + guard let publicKey: String = envelope.source else { throw MessageReceiverError.invalidMessage } + + return PushNotificationAPI.NotificationMetadata( + accountId: publicKey, + hash: "", + namespace: .legacyClosedGroup, + createdTimestampMs: 0, + expirationTimestampMs: 0, + dataLength: 0, + dataTooLong: false + ) + } +} diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index e9c49ab7a..4fb691240 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -458,10 +458,11 @@ public enum PushNotificationAPI { // We only support legacy notifications for legacy group conversations guard let envelope: SNProtoEnvelope = try? MessageWrapper.unwrap(data: data), - envelope.type == .closedGroupMessage + envelope.type == .closedGroupMessage, + let metadata: NotificationMetadata = try? .legacyGroupMessage(envelope: envelope) else { return (data, .invalid, .legacyForceSilent) } - return (data, .invalid, .legacySuccess) + return (data, metadata, .legacySuccess) } guard let base64EncodedEncString: String = notificationContent.userInfo["enc_payload"] as? String else { diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift index 4ff33a177..cc99fb04f 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/Poller.swift @@ -277,7 +277,8 @@ public class Poller: PollerType { return try Message.processRawReceivedMessage( db, rawMessage: message, - publicKey: publicKey + publicKey: publicKey, + using: dependencies ) } catch { diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 1557baf5c..c760c5376 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -17,10 +17,10 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension private var request: UNNotificationRequest? private var openGroupPollCancellable: AnyCancellable? - public static let isFromRemoteKey = "remote" - public static let threadIdKey = "Signal.AppNotificationsUserInfoKey.threadId" - public static let threadVariantRaw = "Signal.AppNotificationsUserInfoKey.threadVariantRaw" - public static let threadNotificationCounter = "Session.AppNotificationsUserInfoKey.threadNotificationCounter" + public static let isFromRemoteKey = "remote" // stringlint:disable + public static let threadIdKey = "Signal.AppNotificationsUserInfoKey.threadId" // stringlint:disable + public static let threadVariantRaw = "Signal.AppNotificationsUserInfoKey.threadVariantRaw" // stringlint:disable + public static let threadNotificationCounter = "Session.AppNotificationsUserInfoKey.threadNotificationCounter" // stringlint:disable private static let callPreOfferLargeNotificationSupressionDuration: TimeInterval = 30 // MARK: Did receive a remote push notification request @@ -103,7 +103,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension // is added to notification center dependencies[singleton: .storage].write { db in do { - guard let processedMessage: ProcessedMessage = try Message.processRawReceivedMessageAsNotification(db, data: data, metadata: metadata) else { + guard let processedMessage: ProcessedMessage = try Message.processRawReceivedMessageAsNotification(db, data: data, metadata: metadata, using: dependencies) else { self.handleFailure(for: notificationContent, error: .messageProcessing) return }