diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 36b076f9cf..4e30b4a023 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -8319,7 +8319,7 @@ repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = 1.0.78; + version = 1.0.79; }; }; 701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e93807efdd..5702b2baa4 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -149,8 +149,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/matrix-rust-components-swift", "state" : { - "revision" : "b4705d95bd049f1c7d93cff38e2c2ac2d892f23d", - "version" : "1.0.78" + "revision" : "14fc58ea578bd370f78e45e83ef2f077a3bd683f", + "version" : "1.0.79" } }, { diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index e5c4227a42..0c37794696 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -13,6 +13,7 @@ protocol CommonSettingsProtocol { var logLevel: TracingConfiguration.LogLevel { get } var enableOnlySignedDeviceIsolationMode: Bool { get } var hideTimelineMedia: Bool { get } + var eventCacheEnabled: Bool { get } } /// Store Element specific app settings. @@ -49,6 +50,7 @@ final class AppSettings { case knockingEnabled case createMediaCaptionsEnabled case mediaBrowserEnabled + case eventCacheEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -305,6 +307,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.hideTimelineMedia, defaultValue: false, storageType: .userDefaults(store)) var hideTimelineMedia + + @UserPreference(key: UserDefaultsKeys.eventCacheEnabled, defaultValue: false, storageType: .userDefaults(store)) + var eventCacheEnabled } extension AppSettings: CommonSettingsProtocol { } diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index 8b3d2ca5d3..7500757ff7 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -5832,6 +5832,77 @@ open class ClientBuilderSDKMock: MatrixRustSDK.ClientBuilder { } } + //MARK: - useEventCachePersistentStorage + + var useEventCachePersistentStorageValueUnderlyingCallsCount = 0 + open var useEventCachePersistentStorageValueCallsCount: Int { + get { + if Thread.isMainThread { + return useEventCachePersistentStorageValueUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = useEventCachePersistentStorageValueUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + useEventCachePersistentStorageValueUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + useEventCachePersistentStorageValueUnderlyingCallsCount = newValue + } + } + } + } + open var useEventCachePersistentStorageValueCalled: Bool { + return useEventCachePersistentStorageValueCallsCount > 0 + } + open var useEventCachePersistentStorageValueReceivedValue: Bool? + open var useEventCachePersistentStorageValueReceivedInvocations: [Bool] = [] + + var useEventCachePersistentStorageValueUnderlyingReturnValue: ClientBuilder! + open var useEventCachePersistentStorageValueReturnValue: ClientBuilder! { + get { + if Thread.isMainThread { + return useEventCachePersistentStorageValueUnderlyingReturnValue + } else { + var returnValue: ClientBuilder? = nil + DispatchQueue.main.sync { + returnValue = useEventCachePersistentStorageValueUnderlyingReturnValue + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + useEventCachePersistentStorageValueUnderlyingReturnValue = newValue + } else { + DispatchQueue.main.sync { + useEventCachePersistentStorageValueUnderlyingReturnValue = newValue + } + } + } + } + open var useEventCachePersistentStorageValueClosure: ((Bool) -> ClientBuilder)? + + open override func useEventCachePersistentStorage(value: Bool) -> ClientBuilder { + useEventCachePersistentStorageValueCallsCount += 1 + useEventCachePersistentStorageValueReceivedValue = value + DispatchQueue.main.async { + self.useEventCachePersistentStorageValueReceivedInvocations.append(value) + } + if let useEventCachePersistentStorageValueClosure = useEventCachePersistentStorageValueClosure { + return useEventCachePersistentStorageValueClosure(value) + } else { + return useEventCachePersistentStorageValueReturnValue + } + } + //MARK: - userAgent var userAgentUserAgentUnderlyingCallsCount = 0 @@ -10881,6 +10952,46 @@ open class RoomSDKMock: MatrixRustSDK.Room { try await clearComposerDraftClosure?() } + //MARK: - clearEventCacheStorage + + open var clearEventCacheStorageThrowableError: Error? + var clearEventCacheStorageUnderlyingCallsCount = 0 + open var clearEventCacheStorageCallsCount: Int { + get { + if Thread.isMainThread { + return clearEventCacheStorageUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = clearEventCacheStorageUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + clearEventCacheStorageUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + clearEventCacheStorageUnderlyingCallsCount = newValue + } + } + } + } + open var clearEventCacheStorageCalled: Bool { + return clearEventCacheStorageCallsCount > 0 + } + open var clearEventCacheStorageClosure: (() async throws -> Void)? + + open override func clearEventCacheStorage() async throws { + if let error = clearEventCacheStorageThrowableError { + throw error + } + clearEventCacheStorageCallsCount += 1 + try await clearEventCacheStorageClosure?() + } + //MARK: - discardRoomKey open var discardRoomKeyThrowableError: Error? @@ -12880,16 +12991,16 @@ open class RoomSDKMock: MatrixRustSDK.Room { //MARK: - messageFilteredTimeline - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesThrowableError: Error? - var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingCallsCount = 0 - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesCallsCount: Int { + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeThrowableError: Error? + var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingCallsCount = 0 + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeCallsCount: Int { get { if Thread.isMainThread { - return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingCallsCount + return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingCallsCount } else { var returnValue: Int? = nil DispatchQueue.main.sync { - returnValue = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingCallsCount + returnValue = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingCallsCount } return returnValue! @@ -12897,29 +13008,29 @@ open class RoomSDKMock: MatrixRustSDK.Room { } set { if Thread.isMainThread { - messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingCallsCount = newValue + messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingCallsCount = newValue } else { DispatchQueue.main.sync { - messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingCallsCount = newValue + messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingCallsCount = newValue } } } } - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesCalled: Bool { - return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesCallsCount > 0 + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeCalled: Bool { + return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeCallsCount > 0 } - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesReceivedArguments: (internalIdPrefix: String?, allowedMessageTypes: [RoomMessageEventMessageType])? - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesReceivedInvocations: [(internalIdPrefix: String?, allowedMessageTypes: [RoomMessageEventMessageType])] = [] + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeReceivedArguments: (internalIdPrefix: String?, allowedMessageTypes: [RoomMessageEventMessageType], dateDividerMode: DateDividerMode)? + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeReceivedInvocations: [(internalIdPrefix: String?, allowedMessageTypes: [RoomMessageEventMessageType], dateDividerMode: DateDividerMode)] = [] - var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingReturnValue: Timeline! - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesReturnValue: Timeline! { + var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingReturnValue: Timeline! + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeReturnValue: Timeline! { get { if Thread.isMainThread { - return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingReturnValue + return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingReturnValue } else { var returnValue: Timeline? = nil DispatchQueue.main.sync { - returnValue = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingReturnValue + returnValue = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingReturnValue } return returnValue! @@ -12927,29 +13038,29 @@ open class RoomSDKMock: MatrixRustSDK.Room { } set { if Thread.isMainThread { - messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingReturnValue = newValue + messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingReturnValue = newValue } else { DispatchQueue.main.sync { - messageFilteredTimelineInternalIdPrefixAllowedMessageTypesUnderlyingReturnValue = newValue + messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeUnderlyingReturnValue = newValue } } } } - open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesClosure: ((String?, [RoomMessageEventMessageType]) async throws -> Timeline)? + open var messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeClosure: ((String?, [RoomMessageEventMessageType], DateDividerMode) async throws -> Timeline)? - open override func messageFilteredTimeline(internalIdPrefix: String?, allowedMessageTypes: [RoomMessageEventMessageType]) async throws -> Timeline { - if let error = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesThrowableError { + open override func messageFilteredTimeline(internalIdPrefix: String?, allowedMessageTypes: [RoomMessageEventMessageType], dateDividerMode: DateDividerMode) async throws -> Timeline { + if let error = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeThrowableError { throw error } - messageFilteredTimelineInternalIdPrefixAllowedMessageTypesCallsCount += 1 - messageFilteredTimelineInternalIdPrefixAllowedMessageTypesReceivedArguments = (internalIdPrefix: internalIdPrefix, allowedMessageTypes: allowedMessageTypes) + messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeCallsCount += 1 + messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeReceivedArguments = (internalIdPrefix: internalIdPrefix, allowedMessageTypes: allowedMessageTypes, dateDividerMode: dateDividerMode) DispatchQueue.main.async { - self.messageFilteredTimelineInternalIdPrefixAllowedMessageTypesReceivedInvocations.append((internalIdPrefix: internalIdPrefix, allowedMessageTypes: allowedMessageTypes)) + self.messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeReceivedInvocations.append((internalIdPrefix: internalIdPrefix, allowedMessageTypes: allowedMessageTypes, dateDividerMode: dateDividerMode)) } - if let messageFilteredTimelineInternalIdPrefixAllowedMessageTypesClosure = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesClosure { - return try await messageFilteredTimelineInternalIdPrefixAllowedMessageTypesClosure(internalIdPrefix, allowedMessageTypes) + if let messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeClosure = messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeClosure { + return try await messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeClosure(internalIdPrefix, allowedMessageTypes, dateDividerMode) } else { - return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesReturnValue + return messageFilteredTimelineInternalIdPrefixAllowedMessageTypesDateDividerModeReturnValue } } @@ -13560,6 +13671,52 @@ open class RoomSDKMock: MatrixRustSDK.Room { try await sendCallNotificationIfNeededClosure?() } + //MARK: - sendRaw + + open var sendRawEventTypeContentThrowableError: Error? + var sendRawEventTypeContentUnderlyingCallsCount = 0 + open var sendRawEventTypeContentCallsCount: Int { + get { + if Thread.isMainThread { + return sendRawEventTypeContentUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = sendRawEventTypeContentUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + sendRawEventTypeContentUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + sendRawEventTypeContentUnderlyingCallsCount = newValue + } + } + } + } + open var sendRawEventTypeContentCalled: Bool { + return sendRawEventTypeContentCallsCount > 0 + } + open var sendRawEventTypeContentReceivedArguments: (eventType: String, content: String)? + open var sendRawEventTypeContentReceivedInvocations: [(eventType: String, content: String)] = [] + open var sendRawEventTypeContentClosure: ((String, String) async throws -> Void)? + + open override func sendRaw(eventType: String, content: String) async throws { + if let error = sendRawEventTypeContentThrowableError { + throw error + } + sendRawEventTypeContentCallsCount += 1 + sendRawEventTypeContentReceivedArguments = (eventType: eventType, content: content) + DispatchQueue.main.async { + self.sendRawEventTypeContentReceivedInvocations.append((eventType: eventType, content: content)) + } + try await sendRawEventTypeContentClosure?(eventType, content) + } + //MARK: - setIsFavourite open var setIsFavouriteIsFavouriteTagOrderThrowableError: Error? diff --git a/ElementX/Sources/Other/Extensions/ClientBuilder.swift b/ElementX/Sources/Other/Extensions/ClientBuilder.swift index 6ca8cb335a..2b90d963b9 100644 --- a/ElementX/Sources/Other/Extensions/ClientBuilder.swift +++ b/ElementX/Sources/Other/Extensions/ClientBuilder.swift @@ -15,13 +15,15 @@ extension ClientBuilder { slidingSync: ClientBuilderSlidingSync, sessionDelegate: ClientSessionDelegate, appHooks: AppHooks, - enableOnlySignedDeviceIsolationMode: Bool) -> ClientBuilder { + enableOnlySignedDeviceIsolationMode: Bool, + eventCacheEnabled: Bool) -> ClientBuilder { var builder = ClientBuilder() .crossProcessStoreLocksHolderName(holderName: InfoPlistReader.main.bundleIdentifier) .enableOidcRefreshLock() .setSessionDelegate(sessionDelegate: sessionDelegate) .userAgent(userAgent: UserAgentBuilder.makeASCIIUserAgent()) .requestConfig(config: .init(retryLimit: 0, timeout: 30000, maxConcurrentRequests: nil, retryTimeout: nil)) + .useEventCachePersistentStorage(value: eventCacheEnabled) builder = switch slidingSync { case .restored: builder diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index ce43cbc9cc..ed3deb3bc6 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -52,6 +52,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var knockingEnabled: Bool { get set } var createMediaCaptionsEnabled: Bool { get set } var mediaBrowserEnabled: Bool { get set } + var eventCacheEnabled: 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 c4c8a6b015..faa486f9a3 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -23,6 +23,15 @@ struct DeveloperOptionsScreen: View { LogLevelConfigurationView(logLevel: $context.logLevel) } + Section("General") { + Toggle(isOn: $context.eventCacheEnabled) { + Text("Event cache") + } + .onChange(of: context.eventCacheEnabled) { + context.send(viewAction: .clearCache) + } + } + Section { Picker("Discovery", selection: $context.slidingSyncDiscovery) { Text("Proxy only").tag(AppSettings.SlidingSyncDiscovery.proxy) diff --git a/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift b/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift index 1c448eae92..0c87cdfb38 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift @@ -78,7 +78,8 @@ struct AuthenticationClientBuilder: AuthenticationClientBuilderProtocol { slidingSync: slidingSync, sessionDelegate: clientSessionDelegate, appHooks: appHooks, - enableOnlySignedDeviceIsolationMode: appSettings.enableOnlySignedDeviceIsolationMode) + enableOnlySignedDeviceIsolationMode: appSettings.enableOnlySignedDeviceIsolationMode, + eventCacheEnabled: appSettings.eventCacheEnabled) .sessionPaths(dataPath: sessionDirectories.dataPath, cachePath: sessionDirectories.cachePath) .passphrase(passphrase: passphrase) diff --git a/ElementX/Sources/Services/Room/JoinedRoomProxy.swift b/ElementX/Sources/Services/Room/JoinedRoomProxy.swift index 16b149e1e5..55970a85ba 100644 --- a/ElementX/Sources/Services/Room/JoinedRoomProxy.swift +++ b/ElementX/Sources/Services/Room/JoinedRoomProxy.swift @@ -168,7 +168,9 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol { func messageFilteredTimeline(allowedMessageTypes: [RoomMessageEventMessageType]) async -> Result { do { - let timeline = try await TimelineProxy(timeline: room.messageFilteredTimeline(internalIdPrefix: nil, allowedMessageTypes: allowedMessageTypes), + let timeline = try await TimelineProxy(timeline: room.messageFilteredTimeline(internalIdPrefix: nil, + allowedMessageTypes: allowedMessageTypes, + dateDividerMode: .monthly), kind: .media) await timeline.subscribeForUpdates() diff --git a/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift b/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift index e446a40ee5..cbc5b8fe6e 100644 --- a/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift +++ b/ElementX/Sources/Services/Timeline/RoomTimelineProvider.swift @@ -203,7 +203,7 @@ private extension TimelineItemProxy { private extension VirtualTimelineItem { var description: String { switch self { - case .dayDivider(let timestamp): + case .dateDivider(let timestamp): return "DayDiviver(\(timestamp))" case .readMarker: return "ReadMarker" diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift index f422c61f03..e51182503b 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift @@ -470,7 +470,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol { return timelineItem case .virtual(let virtualItem, let uniqueID): switch virtualItem { - case .dayDivider(let timestamp): + case .dateDivider(let timestamp): let date = Date(timeIntervalSince1970: TimeInterval(timestamp / 1000)) let dateString = date.formatted(date: .complete, time: .omitted) diff --git a/ElementX/Sources/Services/UserSession/UserSessionStore.swift b/ElementX/Sources/Services/UserSession/UserSessionStore.swift index 1f4ca5e5b5..8cbdf79170 100644 --- a/ElementX/Sources/Services/UserSession/UserSessionStore.swift +++ b/ElementX/Sources/Services/UserSession/UserSessionStore.swift @@ -130,7 +130,8 @@ class UserSessionStore: UserSessionStoreProtocol { slidingSync: .restored, sessionDelegate: keychainController, appHooks: appHooks, - enableOnlySignedDeviceIsolationMode: appSettings.enableOnlySignedDeviceIsolationMode) + enableOnlySignedDeviceIsolationMode: appSettings.enableOnlySignedDeviceIsolationMode, + eventCacheEnabled: appSettings.eventCacheEnabled) .sessionPaths(dataPath: credentials.restorationToken.sessionDirectories.dataPath, cachePath: credentials.restorationToken.sessionDirectories.cachePath) .username(username: credentials.userID) diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index 0df8b17c13..3436f9b6fb 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -46,7 +46,17 @@ class NotificationServiceExtension: UNNotificationServiceExtension { // Used to create one single UserSession across process/instances/runs private static let serialQueue = DispatchQueue(label: "io.element.elementx.nse") - private static var userSession: NSEUserSession? + + // Temporary. We need to make sure the NSE and the main app pass in the same value. + // The NSE has a tendency of staying alive for longer so use this to manually kill it + // when the feature flag doesn't match. + private static var eventCacheEnabled = false + + private static var userSession: NSEUserSession? { + didSet { + eventCacheEnabled = settings.eventCacheEnabled + } + } override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { @@ -94,6 +104,11 @@ class NotificationServiceExtension: UNNotificationServiceExtension { return discard(unreadCount: request.unreadCount) } } + + guard Self.eventCacheEnabled == settings.eventCacheEnabled else { + MXLog.error("Found missmatch `eventCacheEnabled` feature flag missmatch, restarting the NSE.") + exit(0) + } Task { await run(with: credentials, diff --git a/NSE/Sources/Other/NSEUserSession.swift b/NSE/Sources/Other/NSEUserSession.swift index 6a2d99dbc2..52611ab698 100644 --- a/NSE/Sources/Other/NSEUserSession.swift +++ b/NSE/Sources/Other/NSEUserSession.swift @@ -34,7 +34,8 @@ final class NSEUserSession { slidingSync: .restored, sessionDelegate: clientSessionDelegate, appHooks: appHooks, - enableOnlySignedDeviceIsolationMode: appSettings.enableOnlySignedDeviceIsolationMode) + enableOnlySignedDeviceIsolationMode: appSettings.enableOnlySignedDeviceIsolationMode, + eventCacheEnabled: appSettings.eventCacheEnabled) .sessionPaths(dataPath: credentials.restorationToken.sessionDirectories.dataPath, cachePath: credentials.restorationToken.sessionDirectories.cachePath) .username(username: credentials.userID) diff --git a/project.yml b/project.yml index 88056ad70e..15f4167ced 100644 --- a/project.yml +++ b/project.yml @@ -61,7 +61,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/element-hq/matrix-rust-components-swift - exactVersion: 1.0.78 + exactVersion: 1.0.79 # path: ../matrix-rust-sdk Compound: url: https://github.com/element-hq/compound-ios