From 5837ebdca321f63c8496c13ec0f46613d896c48f Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Thu, 10 Jul 2025 15:03:03 +0200 Subject: [PATCH] added a feature flag for share pos + updated the SDK (#4312) --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 12 +-- .../Sources/Application/AppSettings.swift | 4 + .../Mocks/Generated/SDKGeneratedMocks.swift | 77 ++++++++++++++++++- .../DeveloperOptionsScreenModels.swift | 1 + .../View/DeveloperOptionsScreen.swift | 7 ++ .../Sources/Services/Client/ClientProxy.swift | 1 + .../Services/Room/JoinedRoomProxy.swift | 6 +- .../RoomSummary/RoomSummaryProvider.swift | 10 ++- project.yml | 2 +- 10 files changed, 104 insertions(+), 18 deletions(-) diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 52fd1bed5..fba161a7b 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -8771,7 +8771,7 @@ repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = 25.07.04; + version = 25.07.10; }; }; 701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ba8b8ad16..8ddc69850 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -95,8 +95,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/onevcat/Kingfisher", "state" : { - "revision" : "7deda23bbdca612076c5c315003d8638a08ed0f1", - "version" : "8.3.2" + "revision" : "010a06c4387cea2d13606222b6c08e0454e6dd2d", + "version" : "8.3.3" } }, { @@ -158,8 +158,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/matrix-rust-components-swift", "state" : { - "revision" : "9ca4d9e3b6fc15f1decf024a7474b368525ef52a", - "version" : "25.7.4" + "revision" : "91d7262dfdea3eec2e6a6fff5ab303ca953dd90b", + "version" : "25.7.10" } }, { @@ -266,8 +266,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-snapshot-testing", "state" : { - "revision" : "1be8144023c367c5de701a6313ed29a3a10bf59b", - "version" : "1.18.3" + "revision" : "37230a37e83f1b7023be08e1b1a2603fcb1567fb", + "version" : "1.18.4" } }, { diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index c88204d7b..0c82ad629 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -57,6 +57,7 @@ final class AppSettings { case knockingEnabled case threadsEnabled case developerOptionsEnabled + case sharePosEnabled // Doug's tweaks 🔧 case hideUnreadMessagesBadge @@ -346,6 +347,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.threadsEnabled, defaultValue: isDevelopmentBuild, storageType: .userDefaults(store)) var developerOptionsEnabled + @UserPreference(key: UserDefaultsKeys.sharePosEnabled, defaultValue: false, storageType: .userDefaults(store)) + var sharePosEnabled + #endif // MARK: - Shared diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index f82e372d9..d9df93098 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -18125,9 +18125,9 @@ open class RoomListServiceSDKMock: MatrixRustSDK.RoomListService, @unchecked Sen } open var subscribeToRoomsRoomIdsReceivedRoomIds: [String]? open var subscribeToRoomsRoomIdsReceivedInvocations: [[String]] = [] - open var subscribeToRoomsRoomIdsClosure: (([String]) throws -> Void)? + open var subscribeToRoomsRoomIdsClosure: (([String]) async throws -> Void)? - open override func subscribeToRooms(roomIds: [String]) throws { + open override func subscribeToRooms(roomIds: [String]) async throws { if let error = subscribeToRoomsRoomIdsThrowableError { throw error } @@ -18136,7 +18136,7 @@ open class RoomListServiceSDKMock: MatrixRustSDK.RoomListService, @unchecked Sen DispatchQueue.main.async { self.subscribeToRoomsRoomIdsReceivedInvocations.append(roomIds) } - try subscribeToRoomsRoomIdsClosure?(roomIds) + try await subscribeToRoomsRoomIdsClosure?(roomIds) } //MARK: - syncIndicator @@ -21663,6 +21663,77 @@ open class SyncServiceBuilderSDKMock: MatrixRustSDK.SyncServiceBuilder, @uncheck return withOfflineModeReturnValue } } + + //MARK: - withSharePos + + var withSharePosEnableUnderlyingCallsCount = 0 + open var withSharePosEnableCallsCount: Int { + get { + if Thread.isMainThread { + return withSharePosEnableUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = withSharePosEnableUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + withSharePosEnableUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + withSharePosEnableUnderlyingCallsCount = newValue + } + } + } + } + open var withSharePosEnableCalled: Bool { + return withSharePosEnableCallsCount > 0 + } + open var withSharePosEnableReceivedEnable: Bool? + open var withSharePosEnableReceivedInvocations: [Bool] = [] + + var withSharePosEnableUnderlyingReturnValue: SyncServiceBuilder! + open var withSharePosEnableReturnValue: SyncServiceBuilder! { + get { + if Thread.isMainThread { + return withSharePosEnableUnderlyingReturnValue + } else { + var returnValue: SyncServiceBuilder? = nil + DispatchQueue.main.sync { + returnValue = withSharePosEnableUnderlyingReturnValue + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + withSharePosEnableUnderlyingReturnValue = newValue + } else { + DispatchQueue.main.sync { + withSharePosEnableUnderlyingReturnValue = newValue + } + } + } + } + open var withSharePosEnableClosure: ((Bool) -> SyncServiceBuilder)? + + open override func withSharePos(enable: Bool) -> SyncServiceBuilder { + withSharePosEnableCallsCount += 1 + withSharePosEnableReceivedEnable = enable + DispatchQueue.main.async { + self.withSharePosEnableReceivedInvocations.append(enable) + } + if let withSharePosEnableClosure = withSharePosEnableClosure { + return withSharePosEnableClosure(enable) + } else { + return withSharePosEnableReturnValue + } + } } open class TaskHandleSDKMock: MatrixRustSDK.TaskHandle, @unchecked Sendable { init() { diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index 2037dd37b..0e10b4adc 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -47,6 +47,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var knockingEnabled: Bool { get set } var threadsEnabled: Bool { get set } var hideQuietNotificationAlerts: Bool { get set } + var sharePosEnabled: Bool { get set } } extension AppSettings: DeveloperOptionsProtocol { } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index d8a224a8c..c08cf3c98 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -59,6 +59,13 @@ struct DeveloperOptionsScreen: View { } } + Section("Sync") { + Toggle(isOn: $context.sharePosEnabled) { + Text("Share pos") + Text("Keep the sliding sync pos to make initial syncs faster. Requires an app restart to take effect. Might make the sync unstable.") + } + } + Section { Toggle(isOn: $context.enableOnlySignedDeviceIsolationMode) { Text("Exclude insecure devices when sending/receiving messages") diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index 2a03de51f..4d6400e0e 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -1182,6 +1182,7 @@ private struct ClientProxyServices { let syncService = try await client .syncService() .withCrossProcessLock() + .withSharePos(enable: appSettings.sharePosEnabled) .finish() let roomListService = syncService.roomListService() diff --git a/ElementX/Sources/Services/Room/JoinedRoomProxy.swift b/ElementX/Sources/Services/Room/JoinedRoomProxy.swift index aedfc07b6..6f61fec26 100644 --- a/ElementX/Sources/Services/Room/JoinedRoomProxy.swift +++ b/ElementX/Sources/Services/Room/JoinedRoomProxy.swift @@ -110,7 +110,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol { subscribedForUpdates = true do { - try roomListService.subscribeToRooms(roomIds: [id]) + try await roomListService.subscribeToRooms(roomIds: [id]) } catch { MXLog.error("Failed subscribing to room with error: \(error)") } @@ -173,7 +173,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol { func threadTimeline(eventID: String) async -> Result { do { - let sdkTimeline = try await room.timelineWithConfiguration(configuration: .init(focus: .thread(rootEventId: eventID, numEvents: 20), + let sdkTimeline = try await room.timelineWithConfiguration(configuration: .init(focus: .thread(rootEventId: eventID), filter: .all, internalIdPrefix: UUID().uuidString, dateDividerMode: .daily, @@ -197,7 +197,7 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol { let rustFocus: MatrixRustSDK.TimelineFocus = switch focus { case .live: .live(hideThreadedEvents: false) case .eventID(let eventID): .event(eventId: eventID, numContextEvents: 100, hideThreadedEvents: false) - case .thread(let eventID): .thread(rootEventId: eventID, numEvents: 20) + case .thread(let eventID): .thread(rootEventId: eventID) case .pinned: .pinnedEvents(maxEventsToLoad: 100, maxConcurrentRequests: 10) } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index fbdbcb33f..878ea4927 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -177,10 +177,12 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { .sink { [weak self] roomIDs in guard let self else { return } - do { - try roomListService.subscribeToRooms(roomIds: roomIDs) - } catch { - MXLog.error("Failed subscribing to rooms with error: \(error)") + Task { [weak self] in + do { + try await self?.roomListService.subscribeToRooms(roomIds: roomIDs) + } catch { + MXLog.error("Failed subscribing to rooms with error: \(error)") + } } } .store(in: &cancellables) diff --git a/project.yml b/project.yml index cf8e595ea..34e2d839a 100644 --- a/project.yml +++ b/project.yml @@ -65,7 +65,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/element-hq/matrix-rust-components-swift - exactVersion: 25.07.04 + exactVersion: 25.07.10 # path: ../matrix-rust-sdk Compound: url: https://github.com/element-hq/compound-ios