Add a migration to expire sync sessions so that m.space.* state is up to date. (#4482)

This commit is contained in:
Doug
2025-09-09 15:35:32 +01:00
committed by GitHub
parent 2f2e6f6226
commit 19189bec06
6 changed files with 116 additions and 29 deletions
@@ -29,6 +29,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
/// Common background task to continue long-running tasks in the background.
private var backgroundTask: UIBackgroundTaskIdentifier?
private var userSessionMigrationsOldVersion: Version?
private var userSession: UserSessionProtocol? {
didSet {
userSessionObserver?.cancel()
@@ -37,7 +38,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
configureNotificationManager()
observeUserSessionChanges()
startSync()
performSettingsToAccountDataMigration(userSession: userSession)
Task { await performUserSessionMigrations(userSession) }
Task { await appHooks.configure(with: userSession) }
}
}
@@ -410,6 +411,27 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
Tracing.migrateLogFiles()
MXLog.info("Migrating to version 25.07.4, log files have been moved.")
}
// Store the old version to run additional migrations on the user session once it has been set up.
userSessionMigrationsOldVersion = oldVersion
}
private func performUserSessionMigrations(_ userSession: UserSessionProtocol) async {
guard let oldVersion = userSessionMigrationsOldVersion else { return }
MXLog.info("Migrating user session from \(oldVersion)")
if oldVersion < Version(25, 6, 0) {
MXLog.info("Migrating to version 25.06.0, migrating timeline media settings to account data.")
performSettingsToAccountDataMigration(userSession: userSession)
}
if oldVersion < Version(25, 9, 2) {
MXLog.info("Migrating to version 25.09.2, triggering sync to ensure m.space state is up to date.")
await userSession.clientProxy.expireSyncSessions()
}
userSessionMigrationsOldVersion = nil
}
// This could be removed once the adoption of 25.06.x is widespread.
@@ -2392,6 +2392,41 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
stopSyncCompletionCallsCount += 1
stopSyncCompletionClosure?(completion)
}
//MARK: - expireSyncSessions
var expireSyncSessionsUnderlyingCallsCount = 0
var expireSyncSessionsCallsCount: Int {
get {
if Thread.isMainThread {
return expireSyncSessionsUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = expireSyncSessionsUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
expireSyncSessionsUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
expireSyncSessionsUnderlyingCallsCount = newValue
}
}
}
}
var expireSyncSessionsCalled: Bool {
return expireSyncSessionsCallsCount > 0
}
var expireSyncSessionsClosure: (() async -> Void)?
func expireSyncSessions() async {
expireSyncSessionsCallsCount += 1
await expireSyncSessionsClosure?()
}
//MARK: - accountURL
var accountURLActionUnderlyingCallsCount = 0
@@ -410,6 +410,10 @@ class ClientProxy: ClientProxyProtocol {
}
}
func expireSyncSessions() async {
await syncService.expireSessions()
}
func accountURL(action: AccountManagementAction) async -> URL? {
try? await client.accountUrl(action: action).flatMap(URL.init(string:))
}
@@ -140,6 +140,8 @@ protocol ClientProxyProtocol: AnyObject {
func stopSync()
func stopSync(completion: (() -> Void)?) // Hopefully this will become async once we get SE-0371.
func expireSyncSessions() async
func accountURL(action: AccountManagementAction) async -> URL?