From 8e8bb7a3e7b77f8001f59dae43c7d40a72818bd5 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Thu, 22 Jun 2023 13:24:37 +0200 Subject: [PATCH] SDK Bump to 1.0.80 and push notifications filtering (#1131) * filtering nil notifications * updated the sdk --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 6 +++--- ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift | 6 +++--- NSE/Sources/NotificationServiceExtension.swift | 5 ++++- NSE/Sources/Other/NSEUserSession.swift | 6 ++++-- UnitTests/Sources/BugReportServiceTests.swift | 8 ++++++-- changelog.d/1114.feature | 1 + project.yml | 2 +- 8 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 changelog.d/1114.feature diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 7c66f1bb0..d1bc2bc40 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -5004,7 +5004,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = "1.0.79-alpha"; + version = "1.0.80-alpha"; }; }; 96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 9ca71ed95..2cfc666db 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -111,8 +111,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "59c10bfd0b2dee9b5bf41b536ffac472d4fc49db", - "version" : "1.0.79-alpha" + "revision" : "d34b870ed9e954b446a8f6db6afa7fa9d8f6c06a", + "version" : "1.0.80-alpha" } }, { @@ -181,7 +181,7 @@ { "identity" : "swift-snapshot-testing", "kind" : "remoteSourceControl", - "location" : "https://github.com/pointfreeco/swift-snapshot-testing.git", + "location" : "https://github.com/pointfreeco/swift-snapshot-testing", "state" : { "revision" : "cef5b3f6f11781dd4591bdd1dd0a3d22bd609334", "version" : "1.11.0" diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index f354ef895..aea507468 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -249,10 +249,10 @@ class SDKClientMock: SDKClientProtocol { } public var getNotificationItemRoomIdEventIdReceivedArguments: (`roomId`: String, `eventId`: String)? public var getNotificationItemRoomIdEventIdReceivedInvocations: [(`roomId`: String, `eventId`: String)] = [] - public var getNotificationItemRoomIdEventIdReturnValue: NotificationItem! - public var getNotificationItemRoomIdEventIdClosure: ((String, String) throws -> NotificationItem)? + public var getNotificationItemRoomIdEventIdReturnValue: NotificationItem? + public var getNotificationItemRoomIdEventIdClosure: ((String, String) throws -> NotificationItem?)? - public func `getNotificationItem`(`roomId`: String, `eventId`: String) throws -> NotificationItem { + public func `getNotificationItem`(`roomId`: String, `eventId`: String) throws -> NotificationItem? { if let error = getNotificationItemRoomIdEventIdThrowableError { throw error } diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index ba4236bdb..e111e9068 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -72,7 +72,10 @@ class NotificationServiceExtension: UNNotificationServiceExtension { do { let userSession = try NSEUserSession(credentials: credentials) - let itemProxy = try await userSession.notificationItemProxy(roomID: roomId, eventID: eventId) + guard let itemProxy = try await userSession.notificationItemProxy(roomID: roomId, eventID: eventId) else { + MXLog.info("\(tag) no notification for this event") + return discard() + } // After the first processing, update the modified content modifiedContent = try await itemProxy.process(mediaProvider: nil) diff --git a/NSE/Sources/Other/NSEUserSession.swift b/NSE/Sources/Other/NSEUserSession.swift index e98422941..711aad8e4 100644 --- a/NSE/Sources/Other/NSEUserSession.swift +++ b/NSE/Sources/Other/NSEUserSession.swift @@ -32,11 +32,13 @@ final class NSEUserSession { try client.restoreSession(session: credentials.restorationToken.session) } - func notificationItemProxy(roomID: String, eventID: String) async throws -> NotificationItemProxyProtocol { + func notificationItemProxy(roomID: String, eventID: String) async throws -> NotificationItemProxyProtocol? { let userID = try client.userId() return await Task.dispatch(on: .global()) { do { - let notification = try self.client.getNotificationItem(roomId: roomID, eventId: eventID) + guard let notification = try self.client.getNotificationItem(roomId: roomID, eventId: eventID) else { + return nil + } return NotificationItemProxy(notificationItem: notification, receiverID: userID) } catch { MXLog.error("NSE: Could not get notification's content creating an empty notification instead, error: \(error)") diff --git a/UnitTests/Sources/BugReportServiceTests.swift b/UnitTests/Sources/BugReportServiceTests.swift index 3b06100c0..205e6152b 100644 --- a/UnitTests/Sources/BugReportServiceTests.swift +++ b/UnitTests/Sources/BugReportServiceTests.swift @@ -15,6 +15,8 @@ // @testable import ElementX + +import Combine import Foundation import XCTest @@ -39,7 +41,8 @@ class BugReportServiceTests: XCTestCase { includeCrashLog: true, githubLabels: [], files: []) - let response = try await bugReportService.submitBugReport(bugReport, progressListener: nil).get() + let progressSubject = CurrentValueSubject(0.0) + let response = try await bugReportService.submitBugReport(bugReport, progressListener: progressSubject).get() XCTAssertFalse(response.reportUrl.isEmpty) } @@ -64,7 +67,8 @@ class BugReportServiceTests: XCTestCase { includeCrashLog: true, githubLabels: [], files: []) - let response = try await service.submitBugReport(bugReport, progressListener: nil).get() + let progressSubject = CurrentValueSubject(0.0) + let response = try await service.submitBugReport(bugReport, progressListener: progressSubject).get() XCTAssertEqual(response.reportUrl, "https://example.com/123") } diff --git a/changelog.d/1114.feature b/changelog.d/1114.feature new file mode 100644 index 000000000..c0f9b88f1 --- /dev/null +++ b/changelog.d/1114.feature @@ -0,0 +1 @@ +Filtering out push notifications for encrypted rooms based on the room push context. \ No newline at end of file diff --git a/project.yml b/project.yml index cb22e721b..2647bf5b1 100644 --- a/project.yml +++ b/project.yml @@ -44,7 +44,7 @@ include: packages: MatrixRustSDK: url: https://github.com/matrix-org/matrix-rust-components-swift - exactVersion: 1.0.79-alpha + exactVersion: 1.0.80-alpha # path: ../matrix-rust-sdk DesignKit: path: DesignKit