Skip to content

Commit

Permalink
Bump the RustSDK to v1.0.79; add a feature flag for the new rust side…
Browse files Browse the repository at this point in the history
… `ClientBuilder::useEventCachePersistentStorage`
  • Loading branch information
stefanceriu committed Dec 10, 2024
1 parent e59a705 commit df3e597
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 38 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
5 changes: 5 additions & 0 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -49,6 +50,7 @@ final class AppSettings {
case knockingEnabled
case createMediaCaptionsEnabled
case mediaBrowserEnabled
case eventCacheEnabled
}

private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
Expand Down Expand Up @@ -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 { }
209 changes: 183 additions & 26 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -12880,76 +12991,76 @@ 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!
}
}
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!
}
}
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
}
}

Expand Down Expand Up @@ -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?
Expand Down
4 changes: 3 additions & 1 deletion ElementX/Sources/Other/Extensions/ClientBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion ElementX/Sources/Services/Room/JoinedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {

func messageFilteredTimeline(allowedMessageTypes: [RoomMessageEventMessageType]) async -> Result<any TimelineProxyProtocol, RoomProxyError> {
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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit df3e597

Please sign in to comment.