From 3e0e4d02cf7f432cb840d7cb7bd7eda0ecacb4f0 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Wed, 7 Jun 2023 15:22:54 +0200 Subject: [PATCH] SDK Bump to 1.0.73-alpha (#1043) * sdk bump * moved the bump event types to the sliding sync list builder * removed sync growing mode from notifications even if we are not really using it anymore * recency order is also for the all room list * removed the local notification code entirely * removed unused function * fixed the code placement for the ordering --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 6 +- .../Sources/Application/AppSettings.swift | 2 - .../Mocks/Generated/SDKGeneratedMocks.swift | 74 ++++++++++-------- .../Sources/Services/Client/ClientProxy.swift | 75 ++----------------- .../Services/Client/ClientProxyProtocol.swift | 1 - .../Services/Media/Provider/MediaLoader.swift | 2 +- .../Manager/NotificationManager.swift | 34 --------- project.yml | 2 +- 9 files changed, 54 insertions(+), 144 deletions(-) diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index d9c74598c..e756e586c 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -4780,7 +4780,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = "1.0.72-alpha"; + version = "1.0.73-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 e78bb71f8..244796746 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -11,7 +11,7 @@ { "identity" : "compound-ios", "kind" : "remoteSourceControl", - "location" : "https://github.com/vector-im/compound-ios.git", + "location" : "https://github.com/vector-im/compound-ios", "state" : { "revision" : "aaa43409ca09130cb9e9a0fe02c803c65aa42aed" } @@ -102,8 +102,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "d0533a4ba40ff1d9ea9c6473a07639fa9b9c5079", - "version" : "1.0.72-alpha" + "revision" : "849e6c5c47d0172b28d757dee0c7d203bf4b34cc", + "version" : "1.0.73-alpha" } }, { diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 14bb834b9..57c736a1c 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -159,8 +159,6 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.enableInAppNotifications, defaultValue: true, storageType: .userDefaults(store)) var enableInAppNotifications - let enableLocalPushNotifications = false - /// Tag describing which set of device specific rules a pusher executes. @UserPreference(key: UserDefaultsKeys.pusherProfileTag, storageType: .userDefaults(store)) var pusherProfileTag: String? diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index 61d4e8c00..315b68d22 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -192,27 +192,27 @@ class SDKClientMock: SDKClientProtocol { } //MARK: - `getMediaFile` - public var getMediaFileMediaSourceBodyMimeTypeThrowableError: Error? - public var getMediaFileMediaSourceBodyMimeTypeCallsCount = 0 - public var getMediaFileMediaSourceBodyMimeTypeCalled: Bool { - return getMediaFileMediaSourceBodyMimeTypeCallsCount > 0 + public var getMediaFileMediaSourceBodyMimeTypeTempDirThrowableError: Error? + public var getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount = 0 + public var getMediaFileMediaSourceBodyMimeTypeTempDirCalled: Bool { + return getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount > 0 } - public var getMediaFileMediaSourceBodyMimeTypeReceivedArguments: (`mediaSource`: MediaSource, `body`: String?, `mimeType`: String)? - public var getMediaFileMediaSourceBodyMimeTypeReceivedInvocations: [(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String)] = [] - public var getMediaFileMediaSourceBodyMimeTypeReturnValue: MediaFileHandle! - public var getMediaFileMediaSourceBodyMimeTypeClosure: ((MediaSource, String?, String) throws -> MediaFileHandle)? + public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments: (`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?)? + public var getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations: [(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?)] = [] + public var getMediaFileMediaSourceBodyMimeTypeTempDirReturnValue: MediaFileHandle! + public var getMediaFileMediaSourceBodyMimeTypeTempDirClosure: ((MediaSource, String?, String, String?) throws -> MediaFileHandle)? - public func `getMediaFile`(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String) throws -> MediaFileHandle { - if let error = getMediaFileMediaSourceBodyMimeTypeThrowableError { + public func `getMediaFile`(`mediaSource`: MediaSource, `body`: String?, `mimeType`: String, `tempDir`: String?) throws -> MediaFileHandle { + if let error = getMediaFileMediaSourceBodyMimeTypeTempDirThrowableError { throw error } - getMediaFileMediaSourceBodyMimeTypeCallsCount += 1 - getMediaFileMediaSourceBodyMimeTypeReceivedArguments = (`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`) - getMediaFileMediaSourceBodyMimeTypeReceivedInvocations.append((`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`)) - if let getMediaFileMediaSourceBodyMimeTypeClosure = getMediaFileMediaSourceBodyMimeTypeClosure { - return try getMediaFileMediaSourceBodyMimeTypeClosure(`mediaSource`, `body`, `mimeType`) + getMediaFileMediaSourceBodyMimeTypeTempDirCallsCount += 1 + getMediaFileMediaSourceBodyMimeTypeTempDirReceivedArguments = (`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`, `tempDir`: `tempDir`) + getMediaFileMediaSourceBodyMimeTypeTempDirReceivedInvocations.append((`mediaSource`: `mediaSource`, `body`: `body`, `mimeType`: `mimeType`, `tempDir`: `tempDir`)) + if let getMediaFileMediaSourceBodyMimeTypeTempDirClosure = getMediaFileMediaSourceBodyMimeTypeTempDirClosure { + return try getMediaFileMediaSourceBodyMimeTypeTempDirClosure(`mediaSource`, `body`, `mimeType`, `tempDir`) } else { - return getMediaFileMediaSourceBodyMimeTypeReturnValue + return getMediaFileMediaSourceBodyMimeTypeTempDirReturnValue } } //MARK: - `getMediaThumbnail` @@ -559,23 +559,6 @@ class SDKClientMock: SDKClientProtocol { setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangReceivedInvocations.append((`identifiers`: `identifiers`, `kind`: `kind`, `appDisplayName`: `appDisplayName`, `deviceDisplayName`: `deviceDisplayName`, `profileTag`: `profileTag`, `lang`: `lang`)) try setPusherIdentifiersKindAppDisplayNameDeviceDisplayNameProfileTagLangClosure?(`identifiers`, `kind`, `appDisplayName`, `deviceDisplayName`, `profileTag`, `lang`) } - //MARK: - `slidingSync` - - public var slidingSyncCallsCount = 0 - public var slidingSyncCalled: Bool { - return slidingSyncCallsCount > 0 - } - public var slidingSyncReturnValue: SlidingSyncBuilder! - public var slidingSyncClosure: (() -> SlidingSyncBuilder)? - - public func `slidingSync`() -> SlidingSyncBuilder { - slidingSyncCallsCount += 1 - if let slidingSyncClosure = slidingSyncClosure { - return slidingSyncClosure() - } else { - return slidingSyncReturnValue - } - } //MARK: - `unignoreUser` public var unignoreUserUserIdThrowableError: Error? @@ -642,5 +625,30 @@ class SDKClientMock: SDKClientProtocol { return userIdReturnValue } } + //MARK: - `slidingSync` + + public var slidingSyncIdThrowableError: Error? + public var slidingSyncIdCallsCount = 0 + public var slidingSyncIdCalled: Bool { + return slidingSyncIdCallsCount > 0 + } + public var slidingSyncIdReceivedId: String? + public var slidingSyncIdReceivedInvocations: [String] = [] + public var slidingSyncIdReturnValue: SlidingSyncBuilder! + public var slidingSyncIdClosure: ((String) throws -> SlidingSyncBuilder)? + + public func `slidingSync`(`id`: String) throws -> SlidingSyncBuilder { + if let error = slidingSyncIdThrowableError { + throw error + } + slidingSyncIdCallsCount += 1 + slidingSyncIdReceivedId = id + slidingSyncIdReceivedInvocations.append(`id`) + if let slidingSyncIdClosure = slidingSyncIdClosure { + return try slidingSyncIdClosure(`id`) + } else { + return slidingSyncIdReturnValue + } + } } // swiftlint:enable all diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index bb5eae9d8..091a95df5 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -19,7 +19,7 @@ import Foundation import MatrixRustSDK import UIKit -private class WeakClientProxyWrapper: ClientDelegate, NotificationDelegate, SlidingSyncObserver { +private class WeakClientProxyWrapper: ClientDelegate, SlidingSyncObserver { private weak var clientProxy: ClientProxy? init(clientProxy: ClientProxy) { @@ -44,13 +44,6 @@ private class WeakClientProxyWrapper: ClientDelegate, NotificationDelegate, Slid MXLog.info("Received sliding sync update") clientProxy?.didReceiveSlidingSyncUpdate(summary: summary) } - - // MARK: - NotificationDelegate - - func didReceiveNotification(notification: MatrixRustSDK.NotificationItem) { - guard let userID = clientProxy?.userID else { return } - clientProxy?.didReceiveNotification(notification: NotificationItemProxy(notificationItem: notification, receiverID: userID)) - } } class ClientProxy: ClientProxyProtocol { @@ -76,7 +69,7 @@ class ClientProxy: ClientProxyProtocol { var invitesListProxy: SlidingSyncListProxy? var invitesSummaryProvider: RoomSummaryProviderProtocol? - var notificationsListBuilder: SlidingSyncListBuilder? + private let roomListRecencyOrderingAllowedEventTypes = ["m.room.message", "m.room.encrypted", "m.sticker"] private var loadCachedAvatarURLTask: Task? private let avatarURLSubject = CurrentValueSubject(nil) @@ -109,13 +102,6 @@ class ClientProxy: ClientProxyProtocol { let delegate = WeakClientProxyWrapper(clientProxy: self) client.setDelegate(delegate: delegate) - - // Set up sync listener for generating local notifications. - if ServiceLocator.shared.settings.enableLocalPushNotifications { - await Task.dispatch(on: clientQueue) { - client.setNotificationDelegate(notificationDelegate: delegate) - } - } configureSlidingSync() @@ -414,31 +400,24 @@ class ClientProxy: ClientProxyProtocol { } do { - let slidingSyncBuilder = client.slidingSync() + let slidingSyncBuilder = try client.slidingSync(id: "ElementX") // List observers need to be setup before calling build() on the SlidingSyncBuilder otherwise // cold cache state and count updates will be lost buildAndConfigureVisibleRoomsSlidingSyncList() buildAndConfigureAllRoomsSlidingSyncList() buildAndConfigureInvitesSlidingSyncList() - if ServiceLocator.shared.settings.enableLocalPushNotifications { - buildAndConfigureNotificationsSlidingSyncList() - } guard let visibleRoomsListBuilder else { MXLog.error("Visible rooms sliding sync view unavailable") return } - - let roomListRecencyOrderingAllowedEventTypes = ["m.room.message", "m.room.encrypted", "m.sticker"] - + // Add the visibleRoomsSlidingSyncList here so that it can take advantage of the SS builder cold cache // We will still register the allRoomsSlidingSyncList later, and than will have no cache let slidingSync = try slidingSyncBuilder .addList(listBuilder: visibleRoomsListBuilder) .withCommonExtensions() - .bumpEventTypes(bumpEventTypes: roomListRecencyOrderingAllowedEventTypes) - // .storageKey(name: "ElementX") .build() // Don't forget to update the view proxies after building the slidingSync @@ -466,12 +445,13 @@ class ClientProxy: ClientProxyProtocol { let listName = "CurrentlyVisibleRooms" let visibleRoomsListProxy = SlidingSyncListProxy(name: listName) - + let visibleRoomsListBuilder = SlidingSyncListBuilder(name: listName) .timelineLimit(limit: UInt32(SlidingSyncConstants.initialTimelineLimit)) // Starts off with zero to quickly load rooms, then goes to 1 while scrolling to quickly load last messages and 20 when the scrolling stops to load room history .requiredState(requiredState: slidingSyncRequiredState) .filters(filters: slidingSyncFilters) .syncModeSelective(selectiveModeBuilder: .init().addRange(start: 0, endInclusive: 20)) + .bumpEventTypes(bumpEventTypes: roomListRecencyOrderingAllowedEventTypes) .onceBuilt(callback: visibleRoomsListProxy) self.visibleRoomsListBuilder = visibleRoomsListBuilder @@ -503,6 +483,7 @@ class ClientProxy: ClientProxyProtocol { .requiredState(requiredState: slidingSyncRequiredState) .filters(filters: slidingSyncFilters) .syncModeGrowing(batchSize: 100, maximumNumberOfRoomsToFetch: nil) + .bumpEventTypes(bumpEventTypes: roomListRecencyOrderingAllowedEventTypes) .onceBuilt(callback: allRoomsListProxy) self.allRoomsListBuilder = allRoomsListBuilder @@ -529,20 +510,6 @@ class ClientProxy: ClientProxyProtocol { self.invitesListProxy = invitesListProxy } - private func buildAndConfigureNotificationsSlidingSyncList() { - guard notificationsListBuilder == nil else { - fatalError("This shouldn't be called more than once") - } - - let notificationsListBuilder = SlidingSyncListBuilder(name: "Notifications") - .noTimelineLimit() - .requiredState(requiredState: slidingSyncNotificationsRequiredState) - .filters(filters: slidingSyncNotificationsFilters) - .syncModeGrowing(batchSize: 100, maximumNumberOfRoomsToFetch: nil) - - self.notificationsListBuilder = notificationsListBuilder - } - private func buildRoomSummaryProviders() { guard visibleRoomsSummaryProvider == nil, allRoomsSummaryProvider == nil, invitesSummaryProvider == nil else { fatalError("This shouldn't be called more than once") @@ -569,10 +536,6 @@ class ClientProxy: ClientProxyProtocol { private lazy var slidingSyncRequiredState = [RequiredState(key: "m.room.avatar", value: ""), RequiredState(key: "m.room.encryption", value: ""), RequiredState(key: "m.room.power_levels", value: "")] - - private lazy var slidingSyncNotificationsRequiredState = [RequiredState(key: "m.room.member", value: "$ME"), - RequiredState(key: "m.room.power_levels", value: ""), - RequiredState(key: "m.room.name", value: "")] private lazy var slidingSyncInvitesRequiredState = [RequiredState(key: "m.room.avatar", value: ""), RequiredState(key: "m.room.encryption", value: ""), @@ -589,17 +552,6 @@ class ClientProxy: ClientProxyProtocol { roomNameLike: nil, tags: [], notTags: []) - - private lazy var slidingSyncNotificationsFilters = SlidingSyncRequestListFilters(isDm: nil, - spaces: [], - isEncrypted: nil, - isInvite: nil, - isTombstoned: false, - roomTypes: [], - notRoomTypes: ["m.space"], - roomNameLike: nil, - tags: [], - notTags: []) private lazy var slidingSyncInviteFilters = SlidingSyncRequestListFilters(isDm: nil, spaces: [], @@ -633,15 +585,6 @@ class ClientProxy: ClientProxyProtocol { } else { MXLog.error("Invites sliding sync view unavailable") } - - if ServiceLocator.shared.settings.enableLocalPushNotifications { - if let notificationsListBuilder { - MXLog.info("Registering notifications view") - slidingSyncTasks.append(slidingSync?.addList(listBuilder: notificationsListBuilder)) - } else { - MXLog.error("Notifications sliding sync view unavailable") - } - } } private func roomTupleForIdentifier(_ identifier: String) -> (SlidingSyncRoom?, Room?) { @@ -667,10 +610,6 @@ class ClientProxy: ClientProxyProtocol { fileprivate func didReceiveSlidingSyncUpdate(summary: UpdateSummary) { callbacks.send(.receivedSyncUpdate) } - - fileprivate func didReceiveNotification(notification: NotificationItemProxyProtocol) { - callbacks.send(.receivedNotification(notification)) - } } extension ClientProxy: MediaLoaderProtocol { diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index da0d3a426..613d5a300 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -21,7 +21,6 @@ import MatrixRustSDK enum ClientProxyCallback { case receivedSyncUpdate case receivedAuthError(isSoftLogout: Bool) - case receivedNotification(NotificationItemProxyProtocol) case updateRestorationToken var isSyncUpdate: Bool { diff --git a/ElementX/Sources/Services/Media/Provider/MediaLoader.swift b/ElementX/Sources/Services/Media/Provider/MediaLoader.swift index a1a07650c..3d98d0739 100644 --- a/ElementX/Sources/Services/Media/Provider/MediaLoader.swift +++ b/ElementX/Sources/Services/Media/Provider/MediaLoader.swift @@ -48,7 +48,7 @@ actor MediaLoader: MediaLoaderProtocol { func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy { let result = try await Task.dispatch(on: clientQueue) { - try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream") + try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream", tempDir: nil) } return MediaFileHandleProxy(handle: result) diff --git a/ElementX/Sources/Services/Notification/Manager/NotificationManager.swift b/ElementX/Sources/Services/Notification/Manager/NotificationManager.swift index e2971b5c7..8e9ee758c 100644 --- a/ElementX/Sources/Services/Notification/Manager/NotificationManager.swift +++ b/ElementX/Sources/Services/Notification/Manager/NotificationManager.swift @@ -22,7 +22,6 @@ import UserNotifications class NotificationManager: NSObject, NotificationManagerProtocol { private let notificationCenter: UserNotificationCenterProtocol private var userSession: UserSessionProtocol? - var clientCancellable: AnyCancellable? init(notificationCenter: UserNotificationCenterProtocol = UNUserNotificationCenter.current()) { self.notificationCenter = notificationCenter @@ -73,17 +72,6 @@ class NotificationManager: NSObject, NotificationManagerProtocol { func setUserSession(_ userSession: UserSessionProtocol?) { self.userSession = userSession - clientCancellable = userSession?.clientProxy.callbacks.sink { [weak self] value in - guard let self else { return } - switch value { - case let .receivedNotification(notification): - Task { - await self.showLocalNotification(notification) - } - default: - return - } - } } func registrationFailed(with error: Error) { @@ -106,28 +94,6 @@ class NotificationManager: NSObject, NotificationManagerProtocol { MXLog.error("[NotificationManager] show local notification failed: \(error)") } } - - private func showLocalNotification(_ notification: NotificationItemProxyProtocol) async { - guard let userSession, - notification.event.timestamp > ServiceLocator.shared.settings.lastLaunchDate else { return } - do { - guard let identifier = notification.id else { - return - } - - let content = try await notification.process(mediaProvider: userSession.mediaProvider) - let request = UNNotificationRequest(identifier: identifier, content: content, trigger: nil) - - guard !ServiceLocator.shared.settings.servedNotificationIdentifiers.contains(identifier) else { - MXLog.info("NotificationManager] local notification discarded because it has already been served") - return - } - ServiceLocator.shared.settings.servedNotificationIdentifiers.insert(identifier) - try await notificationCenter.add(request) - } catch { - MXLog.error("[NotificationManager] show local notification item failed: \(error)") - } - } private func setPusher(with deviceToken: Data, clientProxy: ClientProxyProtocol) async -> Bool { do { diff --git a/project.yml b/project.yml index fced7cd6a..83b086fef 100644 --- a/project.yml +++ b/project.yml @@ -42,7 +42,7 @@ include: packages: MatrixRustSDK: url: https://github.com/matrix-org/matrix-rust-components-swift - exactVersion: 1.0.72-alpha + exactVersion: 1.0.73-alpha # path: ../matrix-rust-sdk DesignKit: path: DesignKit