Skip to content

Commit

Permalink
Adopt various rust side Timeline API additions (#3423)
Browse files Browse the repository at this point in the history
* Adopt new reaction toggling API introduced in matrix-org/matrix-rust-sdk/pull/4127

* Adopt the changes introduced in matrix-org/matrix-rust-sdk/pull/4111: use the new `TimelineUniqueId` type instead of `String` for unique timeline identifiers.

* Bump the RustSDK to v1.0.58.

* Fix unit tests
  • Loading branch information
stefanceriu authored Oct 16, 2024
1 parent 5a89219 commit 0651314
Show file tree
Hide file tree
Showing 35 changed files with 201 additions and 184 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7806,7 +7806,7 @@
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.0.57;
version = 1.0.58;
};
};
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" : "5f01589d44aa7045dc1ad87f2583f6083295d3eb",
"version" : "1.0.57"
"revision" : "753c5381ce88b3549cbd8ed9b839109ff143ecdd",
"version" : "1.0.58"
}
},
{
Expand Down
6 changes: 5 additions & 1 deletion ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
MXLog.debug("Selected \(emoji) for \(itemID)")
navigationStackCoordinator.setSheetCoordinator(nil)
Task {
await self.timelineController?.toggleReaction(emoji, to: itemID)
guard case let .event(_, eventOrTransactionID) = itemID else {
fatalError()
}

await self.timelineController?.toggleReaction(emoji, to: eventOrTransactionID)
}
case .dismiss:
navigationStackCoordinator.setSheetCoordinator(nil)
Expand Down
28 changes: 14 additions & 14 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14057,8 +14057,8 @@ class TimelineProxyMock: TimelineProxyProtocol {
var redactReasonCalled: Bool {
return redactReasonCallsCount > 0
}
var redactReasonReceivedArguments: (timelineItemID: TimelineItemIdentifier, reason: String?)?
var redactReasonReceivedInvocations: [(timelineItemID: TimelineItemIdentifier, reason: String?)] = []
var redactReasonReceivedArguments: (eventOrTransactionID: EventOrTransactionId, reason: String?)?
var redactReasonReceivedInvocations: [(eventOrTransactionID: EventOrTransactionId, reason: String?)] = []

var redactReasonUnderlyingReturnValue: Result<Void, TimelineProxyError>!
var redactReasonReturnValue: Result<Void, TimelineProxyError>! {
Expand All @@ -14084,16 +14084,16 @@ class TimelineProxyMock: TimelineProxyProtocol {
}
}
}
var redactReasonClosure: ((TimelineItemIdentifier, String?) async -> Result<Void, TimelineProxyError>)?
var redactReasonClosure: ((EventOrTransactionId, String?) async -> Result<Void, TimelineProxyError>)?

func redact(_ timelineItemID: TimelineItemIdentifier, reason: String?) async -> Result<Void, TimelineProxyError> {
func redact(_ eventOrTransactionID: EventOrTransactionId, reason: String?) async -> Result<Void, TimelineProxyError> {
redactReasonCallsCount += 1
redactReasonReceivedArguments = (timelineItemID: timelineItemID, reason: reason)
redactReasonReceivedArguments = (eventOrTransactionID: eventOrTransactionID, reason: reason)
DispatchQueue.main.async {
self.redactReasonReceivedInvocations.append((timelineItemID: timelineItemID, reason: reason))
self.redactReasonReceivedInvocations.append((eventOrTransactionID: eventOrTransactionID, reason: reason))
}
if let redactReasonClosure = redactReasonClosure {
return await redactReasonClosure(timelineItemID, reason)
return await redactReasonClosure(eventOrTransactionID, reason)
} else {
return redactReasonReturnValue
}
Expand Down Expand Up @@ -14867,8 +14867,8 @@ class TimelineProxyMock: TimelineProxyProtocol {
var toggleReactionToCalled: Bool {
return toggleReactionToCallsCount > 0
}
var toggleReactionToReceivedArguments: (reaction: String, itemID: TimelineItemIdentifier)?
var toggleReactionToReceivedInvocations: [(reaction: String, itemID: TimelineItemIdentifier)] = []
var toggleReactionToReceivedArguments: (reaction: String, eventID: EventOrTransactionId)?
var toggleReactionToReceivedInvocations: [(reaction: String, eventID: EventOrTransactionId)] = []

var toggleReactionToUnderlyingReturnValue: Result<Void, TimelineProxyError>!
var toggleReactionToReturnValue: Result<Void, TimelineProxyError>! {
Expand All @@ -14894,16 +14894,16 @@ class TimelineProxyMock: TimelineProxyProtocol {
}
}
}
var toggleReactionToClosure: ((String, TimelineItemIdentifier) async -> Result<Void, TimelineProxyError>)?
var toggleReactionToClosure: ((String, EventOrTransactionId) async -> Result<Void, TimelineProxyError>)?

func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async -> Result<Void, TimelineProxyError> {
func toggleReaction(_ reaction: String, to eventID: EventOrTransactionId) async -> Result<Void, TimelineProxyError> {
toggleReactionToCallsCount += 1
toggleReactionToReceivedArguments = (reaction: reaction, itemID: itemID)
toggleReactionToReceivedArguments = (reaction: reaction, eventID: eventID)
DispatchQueue.main.async {
self.toggleReactionToReceivedInvocations.append((reaction: reaction, itemID: itemID))
self.toggleReactionToReceivedInvocations.append((reaction: reaction, eventID: eventID))
}
if let toggleReactionToClosure = toggleReactionToClosure {
return await toggleReactionToClosure(reaction, itemID)
return await toggleReactionToClosure(reaction, eventID)
} else {
return toggleReactionToReturnValue
}
Expand Down
134 changes: 67 additions & 67 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,46 @@ open class ClientSDKMock: MatrixRustSDK.Client {

fileprivate var pointer: UnsafeMutableRawPointer!

//MARK: - abortOidcLogin
//MARK: - abortOidcAuth

var abortOidcLoginAuthorizationDataUnderlyingCallsCount = 0
open var abortOidcLoginAuthorizationDataCallsCount: Int {
var abortOidcAuthAuthorizationDataUnderlyingCallsCount = 0
open var abortOidcAuthAuthorizationDataCallsCount: Int {
get {
if Thread.isMainThread {
return abortOidcLoginAuthorizationDataUnderlyingCallsCount
return abortOidcAuthAuthorizationDataUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = abortOidcLoginAuthorizationDataUnderlyingCallsCount
returnValue = abortOidcAuthAuthorizationDataUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
abortOidcLoginAuthorizationDataUnderlyingCallsCount = newValue
abortOidcAuthAuthorizationDataUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
abortOidcLoginAuthorizationDataUnderlyingCallsCount = newValue
abortOidcAuthAuthorizationDataUnderlyingCallsCount = newValue
}
}
}
}
open var abortOidcLoginAuthorizationDataCalled: Bool {
return abortOidcLoginAuthorizationDataCallsCount > 0
open var abortOidcAuthAuthorizationDataCalled: Bool {
return abortOidcAuthAuthorizationDataCallsCount > 0
}
open var abortOidcLoginAuthorizationDataReceivedAuthorizationData: OidcAuthorizationData?
open var abortOidcLoginAuthorizationDataReceivedInvocations: [OidcAuthorizationData] = []
open var abortOidcLoginAuthorizationDataClosure: ((OidcAuthorizationData) async -> Void)?
open var abortOidcAuthAuthorizationDataReceivedAuthorizationData: OidcAuthorizationData?
open var abortOidcAuthAuthorizationDataReceivedInvocations: [OidcAuthorizationData] = []
open var abortOidcAuthAuthorizationDataClosure: ((OidcAuthorizationData) async -> Void)?

open override func abortOidcLogin(authorizationData: OidcAuthorizationData) async {
abortOidcLoginAuthorizationDataCallsCount += 1
abortOidcLoginAuthorizationDataReceivedAuthorizationData = authorizationData
open override func abortOidcAuth(authorizationData: OidcAuthorizationData) async {
abortOidcAuthAuthorizationDataCallsCount += 1
abortOidcAuthAuthorizationDataReceivedAuthorizationData = authorizationData
DispatchQueue.main.async {
self.abortOidcLoginAuthorizationDataReceivedInvocations.append(authorizationData)
self.abortOidcAuthAuthorizationDataReceivedInvocations.append(authorizationData)
}
await abortOidcLoginAuthorizationDataClosure?(authorizationData)
await abortOidcAuthAuthorizationDataClosure?(authorizationData)
}

//MARK: - accountData
Expand Down Expand Up @@ -3872,78 +3872,78 @@ open class ClientSDKMock: MatrixRustSDK.Client {
}
}

//MARK: - urlForOidcLogin
//MARK: - urlForOidc

open var urlForOidcLoginOidcConfigurationThrowableError: Error?
var urlForOidcLoginOidcConfigurationUnderlyingCallsCount = 0
open var urlForOidcLoginOidcConfigurationCallsCount: Int {
open var urlForOidcOidcConfigurationPromptThrowableError: Error?
var urlForOidcOidcConfigurationPromptUnderlyingCallsCount = 0
open var urlForOidcOidcConfigurationPromptCallsCount: Int {
get {
if Thread.isMainThread {
return urlForOidcLoginOidcConfigurationUnderlyingCallsCount
return urlForOidcOidcConfigurationPromptUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = urlForOidcLoginOidcConfigurationUnderlyingCallsCount
returnValue = urlForOidcOidcConfigurationPromptUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
urlForOidcLoginOidcConfigurationUnderlyingCallsCount = newValue
urlForOidcOidcConfigurationPromptUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
urlForOidcLoginOidcConfigurationUnderlyingCallsCount = newValue
urlForOidcOidcConfigurationPromptUnderlyingCallsCount = newValue
}
}
}
}
open var urlForOidcLoginOidcConfigurationCalled: Bool {
return urlForOidcLoginOidcConfigurationCallsCount > 0
open var urlForOidcOidcConfigurationPromptCalled: Bool {
return urlForOidcOidcConfigurationPromptCallsCount > 0
}
open var urlForOidcLoginOidcConfigurationReceivedOidcConfiguration: OidcConfiguration?
open var urlForOidcLoginOidcConfigurationReceivedInvocations: [OidcConfiguration] = []
open var urlForOidcOidcConfigurationPromptReceivedArguments: (oidcConfiguration: OidcConfiguration, prompt: OidcPrompt)?
open var urlForOidcOidcConfigurationPromptReceivedInvocations: [(oidcConfiguration: OidcConfiguration, prompt: OidcPrompt)] = []

var urlForOidcLoginOidcConfigurationUnderlyingReturnValue: OidcAuthorizationData!
open var urlForOidcLoginOidcConfigurationReturnValue: OidcAuthorizationData! {
var urlForOidcOidcConfigurationPromptUnderlyingReturnValue: OidcAuthorizationData!
open var urlForOidcOidcConfigurationPromptReturnValue: OidcAuthorizationData! {
get {
if Thread.isMainThread {
return urlForOidcLoginOidcConfigurationUnderlyingReturnValue
return urlForOidcOidcConfigurationPromptUnderlyingReturnValue
} else {
var returnValue: OidcAuthorizationData? = nil
DispatchQueue.main.sync {
returnValue = urlForOidcLoginOidcConfigurationUnderlyingReturnValue
returnValue = urlForOidcOidcConfigurationPromptUnderlyingReturnValue
}

return returnValue!
}
}
set {
if Thread.isMainThread {
urlForOidcLoginOidcConfigurationUnderlyingReturnValue = newValue
urlForOidcOidcConfigurationPromptUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
urlForOidcLoginOidcConfigurationUnderlyingReturnValue = newValue
urlForOidcOidcConfigurationPromptUnderlyingReturnValue = newValue
}
}
}
}
open var urlForOidcLoginOidcConfigurationClosure: ((OidcConfiguration) async throws -> OidcAuthorizationData)?
open var urlForOidcOidcConfigurationPromptClosure: ((OidcConfiguration, OidcPrompt) async throws -> OidcAuthorizationData)?

open override func urlForOidcLogin(oidcConfiguration: OidcConfiguration) async throws -> OidcAuthorizationData {
if let error = urlForOidcLoginOidcConfigurationThrowableError {
open override func urlForOidc(oidcConfiguration: OidcConfiguration, prompt: OidcPrompt) async throws -> OidcAuthorizationData {
if let error = urlForOidcOidcConfigurationPromptThrowableError {
throw error
}
urlForOidcLoginOidcConfigurationCallsCount += 1
urlForOidcLoginOidcConfigurationReceivedOidcConfiguration = oidcConfiguration
urlForOidcOidcConfigurationPromptCallsCount += 1
urlForOidcOidcConfigurationPromptReceivedArguments = (oidcConfiguration: oidcConfiguration, prompt: prompt)
DispatchQueue.main.async {
self.urlForOidcLoginOidcConfigurationReceivedInvocations.append(oidcConfiguration)
self.urlForOidcOidcConfigurationPromptReceivedInvocations.append((oidcConfiguration: oidcConfiguration, prompt: prompt))
}
if let urlForOidcLoginOidcConfigurationClosure = urlForOidcLoginOidcConfigurationClosure {
return try await urlForOidcLoginOidcConfigurationClosure(oidcConfiguration)
if let urlForOidcOidcConfigurationPromptClosure = urlForOidcOidcConfigurationPromptClosure {
return try await urlForOidcOidcConfigurationPromptClosure(oidcConfiguration, prompt)
} else {
return urlForOidcLoginOidcConfigurationReturnValue
return urlForOidcOidcConfigurationPromptReturnValue
}
}

Expand Down Expand Up @@ -19484,48 +19484,48 @@ open class TimelineSDKMock: MatrixRustSDK.Timeline {

//MARK: - toggleReaction

open var toggleReactionUniqueIdKeyThrowableError: Error?
var toggleReactionUniqueIdKeyUnderlyingCallsCount = 0
open var toggleReactionUniqueIdKeyCallsCount: Int {
open var toggleReactionItemIdKeyThrowableError: Error?
var toggleReactionItemIdKeyUnderlyingCallsCount = 0
open var toggleReactionItemIdKeyCallsCount: Int {
get {
if Thread.isMainThread {
return toggleReactionUniqueIdKeyUnderlyingCallsCount
return toggleReactionItemIdKeyUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = toggleReactionUniqueIdKeyUnderlyingCallsCount
returnValue = toggleReactionItemIdKeyUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
toggleReactionUniqueIdKeyUnderlyingCallsCount = newValue
toggleReactionItemIdKeyUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
toggleReactionUniqueIdKeyUnderlyingCallsCount = newValue
toggleReactionItemIdKeyUnderlyingCallsCount = newValue
}
}
}
}
open var toggleReactionUniqueIdKeyCalled: Bool {
return toggleReactionUniqueIdKeyCallsCount > 0
open var toggleReactionItemIdKeyCalled: Bool {
return toggleReactionItemIdKeyCallsCount > 0
}
open var toggleReactionUniqueIdKeyReceivedArguments: (uniqueId: String, key: String)?
open var toggleReactionUniqueIdKeyReceivedInvocations: [(uniqueId: String, key: String)] = []
open var toggleReactionUniqueIdKeyClosure: ((String, String) async throws -> Void)?
open var toggleReactionItemIdKeyReceivedArguments: (itemId: EventOrTransactionId, key: String)?
open var toggleReactionItemIdKeyReceivedInvocations: [(itemId: EventOrTransactionId, key: String)] = []
open var toggleReactionItemIdKeyClosure: ((EventOrTransactionId, String) async throws -> Void)?

open override func toggleReaction(uniqueId: String, key: String) async throws {
if let error = toggleReactionUniqueIdKeyThrowableError {
open override func toggleReaction(itemId: EventOrTransactionId, key: String) async throws {
if let error = toggleReactionItemIdKeyThrowableError {
throw error
}
toggleReactionUniqueIdKeyCallsCount += 1
toggleReactionUniqueIdKeyReceivedArguments = (uniqueId: uniqueId, key: key)
toggleReactionItemIdKeyCallsCount += 1
toggleReactionItemIdKeyReceivedArguments = (itemId: itemId, key: key)
DispatchQueue.main.async {
self.toggleReactionUniqueIdKeyReceivedInvocations.append((uniqueId: uniqueId, key: key))
self.toggleReactionItemIdKeyReceivedInvocations.append((itemId: itemId, key: key))
}
try await toggleReactionUniqueIdKeyClosure?(uniqueId, key)
try await toggleReactionItemIdKeyClosure?(itemId, key)
}

//MARK: - unpinEvent
Expand Down Expand Up @@ -20724,13 +20724,13 @@ open class TimelineItemSDKMock: MatrixRustSDK.TimelineItem {
return uniqueIdCallsCount > 0
}

var uniqueIdUnderlyingReturnValue: String!
open var uniqueIdReturnValue: String! {
var uniqueIdUnderlyingReturnValue: TimelineUniqueId!
open var uniqueIdReturnValue: TimelineUniqueId! {
get {
if Thread.isMainThread {
return uniqueIdUnderlyingReturnValue
} else {
var returnValue: String? = nil
var returnValue: TimelineUniqueId? = nil
DispatchQueue.main.sync {
returnValue = uniqueIdUnderlyingReturnValue
}
Expand All @@ -20748,9 +20748,9 @@ open class TimelineItemSDKMock: MatrixRustSDK.TimelineItem {
}
}
}
open var uniqueIdClosure: (() -> String)?
open var uniqueIdClosure: (() -> TimelineUniqueId)?

open override func uniqueId() -> String {
open override func uniqueId() -> TimelineUniqueId {
uniqueIdCallsCount += 1
if let uniqueIdClosure = uniqueIdClosure {
return uniqueIdClosure()
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/RoomTimelineProviderMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AutoUpdatingRoomTimelineProviderMock: RoomTimelineProvider {

let timelineItem = TimelineItemSDKMock()
timelineItem.asEventReturnValue = EventTimelineItem.mockMessage
timelineItem.uniqueIdReturnValue = UUID().uuidString
timelineItem.uniqueIdReturnValue = .init(id: UUID().uuidString)

diff.appendReturnValue = [timelineItem]

Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/SDK/ClientSDKMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension ClientSDKMock {
userIdServerNameThrowableError = MockError.generic
serverReturnValue = "https://\(configuration.serverAddress)"
getUrlUrlReturnValue = configuration.elementWellKnown
urlForOidcLoginOidcConfigurationReturnValue = OidcAuthorizationDataSDKMock(configuration: configuration)
urlForOidcOidcConfigurationPromptReturnValue = OidcAuthorizationDataSDKMock(configuration: configuration)
loginUsernamePasswordInitialDeviceNameDeviceIdClosure = { username, password, _, _ in
guard username == configuration.validCredentials.username,
password == configuration.validCredentials.password else {
Expand Down
Loading

0 comments on commit 0651314

Please sign in to comment.