added a feature flag for share pos + updated the SDK (#4312)

This commit is contained in:
Mauro
2025-07-10 15:03:03 +02:00
committed by GitHub
parent 5065ed6735
commit d86d90c15a
10 changed files with 104 additions and 18 deletions
@@ -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
@@ -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() {
@@ -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 { }
@@ -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")
@@ -1182,6 +1182,7 @@ private struct ClientProxyServices {
let syncService = try await client
.syncService()
.withCrossProcessLock()
.withSharePos(enable: appSettings.sharePosEnabled)
.finish()
let roomListService = syncService.roomListService()
@@ -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<TimelineProxyProtocol, RoomProxyError> {
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)
}
@@ -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)