diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index fb48a3cd71..54897bc144 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -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 let eventOrTransactionID = itemID.eventOrTransactionID else { + fatalError() + } + + await self.timelineController?.toggleReaction(emoji, to: eventOrTransactionID) } case .dismiss: navigationStackCoordinator.setSheetCoordinator(nil) diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index db66e04c9c..fea2e088d8 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -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! var toggleReactionToReturnValue: Result! { @@ -14894,16 +14894,16 @@ class TimelineProxyMock: TimelineProxyProtocol { } } } - var toggleReactionToClosure: ((String, TimelineItemIdentifier) async -> Result)? + var toggleReactionToClosure: ((String, EventOrTransactionId) async -> Result)? - func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async -> Result { + func toggleReaction(_ reaction: String, to eventID: EventOrTransactionId) async -> Result { 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 } diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index e4548ff0f1..7adf41288c 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -19484,16 +19484,16 @@ 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! @@ -19501,31 +19501,31 @@ open class TimelineSDKMock: MatrixRustSDK.Timeline { } 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 diff --git a/ElementX/Sources/Screens/Timeline/TimelineInteractionHandler.swift b/ElementX/Sources/Screens/Timeline/TimelineInteractionHandler.swift index 7696f2501a..f4b869c0d0 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineInteractionHandler.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineInteractionHandler.swift @@ -159,7 +159,13 @@ class TimelineInteractionHandler { case .react: displayEmojiPicker(for: itemID) case .toggleReaction(let key): - Task { await timelineController.toggleReaction(key, to: itemID) } + Task { + guard let eventID = itemID.eventOrTransactionID else { + fatalError() + } + + await timelineController.toggleReaction(key, to: eventID) + } case .endPoll(let pollStartID): endPoll(pollStartID: pollStartID) case .pin: diff --git a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift index 2dc59055fa..de5027ba10 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineViewModel.swift @@ -131,8 +131,12 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol { Task { await handleItemTapped(with: id) } case .itemSendInfoTapped(let itemID): handleItemSendInfoTapped(itemID: itemID) - case .toggleReaction(let emoji, let itemId): - Task { await timelineController.toggleReaction(emoji, to: itemId) } + case .toggleReaction(let emoji, let itemID): + guard let eventID = itemID.eventOrTransactionID else { + fatalError() + } + + Task { await timelineController.toggleReaction(emoji, to: eventID) } case .sendReadReceiptIfNeeded(let lastVisibleItemID): Task { await sendReadReceiptIfNeeded(for: lastVisibleItemID) } case .paginateBackwards: diff --git a/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift index d4844c8810..86c02937c3 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift @@ -84,7 +84,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol { inReplyTo itemID: TimelineItemIdentifier?, intentionalMentions: IntentionalMentions) async { } - func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async { } + func toggleReaction(_ reaction: String, to eventID: EventOrTransactionId) async { } func edit(_ timelineItemID: TimelineItemIdentifier, message: String, diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift index cf0381f3a6..369c01eb30 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift @@ -167,10 +167,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol { } } - func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async { - MXLog.info("Toggle reaction in \(roomID)") + func toggleReaction(_ reaction: String, to eventOrTransactionID: EventOrTransactionId) async { + MXLog.info("Toggle reaction \(reaction) to \(eventOrTransactionID)") - switch await activeTimeline.toggleReaction(reaction, to: itemID) { + switch await activeTimeline.toggleReaction(reaction, to: eventOrTransactionID) { case .success: MXLog.info("Finished toggling reaction") case .failure(let error): diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift index 4ea6719dde..871b3296c6 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift @@ -56,7 +56,7 @@ protocol RoomTimelineControllerProtocol { html: String?, intentionalMentions: IntentionalMentions) async - func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async + func toggleReaction(_ reaction: String, to eventOrTransactionID: EventOrTransactionId) async func redact(_ itemID: TimelineItemIdentifier) async diff --git a/ElementX/Sources/Services/Timeline/TimelineProxy.swift b/ElementX/Sources/Services/Timeline/TimelineProxy.swift index 3d7c7ee806..a77710c7b8 100644 --- a/ElementX/Sources/Services/Timeline/TimelineProxy.swift +++ b/ElementX/Sources/Services/Timeline/TimelineProxy.swift @@ -426,15 +426,15 @@ final class TimelineProxy: TimelineProxyProtocol { } } - func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async -> Result { - MXLog.info("Toggling reaction for event: \(itemID)") + func toggleReaction(_ reaction: String, to eventOrTransactionID: EventOrTransactionId) async -> Result { + MXLog.info("Toggling reaction \(reaction) for event: \(eventOrTransactionID)") do { - try await timeline.toggleReaction(uniqueId: itemID.uniqueID, key: reaction) - MXLog.info("Finished toggling reaction for event: \(itemID)") + try await timeline.toggleReaction(itemId: eventOrTransactionID, key: reaction) + MXLog.info("Finished toggling reaction for event: \(eventOrTransactionID)") return .success(()) } catch { - MXLog.error("Failed toggling reaction for event: \(itemID)") + MXLog.error("Failed toggling reaction for event: \(eventOrTransactionID)") return .failure(.sdkError(error)) } } diff --git a/ElementX/Sources/Services/Timeline/TimelineProxyProtocol.swift b/ElementX/Sources/Services/Timeline/TimelineProxyProtocol.swift index c081388487..78ab913b18 100644 --- a/ElementX/Sources/Services/Timeline/TimelineProxyProtocol.swift +++ b/ElementX/Sources/Services/Timeline/TimelineProxyProtocol.swift @@ -92,7 +92,7 @@ protocol TimelineProxyProtocol { inReplyTo eventID: String?, intentionalMentions: IntentionalMentions) async -> Result - func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async -> Result + func toggleReaction(_ reaction: String, to eventID: EventOrTransactionId) async -> Result // Polls func createPoll(question: String, answers: [String], pollKind: Poll.Kind) async -> Result