diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index f26a14352..82b96d820 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -500,7 +500,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { MXLog.debug("Selected \(emoji) for \(itemId)") self?.navigationStackCoordinator.setSheetCoordinator(nil) Task { - await self?.timelineController?.sendReaction(emoji, to: itemId) + await self?.timelineController?.toggleReaction(emoji, to: itemId) } case .dismiss: self?.navigationStackCoordinator.setSheetCoordinator(nil) diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index ec2f43cd7..5a8b2e57a 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -610,25 +610,25 @@ class RoomProxyMock: RoomProxyProtocol { return sendMessageInReplyToReturnValue } } - //MARK: - sendReaction + //MARK: - toggleReaction - var sendReactionToCallsCount = 0 - var sendReactionToCalled: Bool { - return sendReactionToCallsCount > 0 + var toggleReactionToCallsCount = 0 + var toggleReactionToCalled: Bool { + return toggleReactionToCallsCount > 0 } - var sendReactionToReceivedArguments: (reaction: String, eventID: String)? - var sendReactionToReceivedInvocations: [(reaction: String, eventID: String)] = [] - var sendReactionToReturnValue: Result! - var sendReactionToClosure: ((String, String) async -> Result)? + var toggleReactionToReceivedArguments: (reaction: String, eventID: String)? + var toggleReactionToReceivedInvocations: [(reaction: String, eventID: String)] = [] + var toggleReactionToReturnValue: Result! + var toggleReactionToClosure: ((String, String) async -> Result)? - func sendReaction(_ reaction: String, to eventID: String) async -> Result { - sendReactionToCallsCount += 1 - sendReactionToReceivedArguments = (reaction: reaction, eventID: eventID) - sendReactionToReceivedInvocations.append((reaction: reaction, eventID: eventID)) - if let sendReactionToClosure = sendReactionToClosure { - return await sendReactionToClosure(reaction, eventID) + func toggleReaction(_ reaction: String, to eventID: String) async -> Result { + toggleReactionToCallsCount += 1 + toggleReactionToReceivedArguments = (reaction: reaction, eventID: eventID) + toggleReactionToReceivedInvocations.append((reaction: reaction, eventID: eventID)) + if let toggleReactionToClosure = toggleReactionToClosure { + return await toggleReactionToClosure(reaction, eventID) } else { - return sendReactionToReturnValue + return toggleReactionToReturnValue } } //MARK: - sendImage diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index ca62b5a5a..9d5cc8f65 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -54,7 +54,7 @@ enum RoomScreenViewAction { case itemTapped(id: String) case linkClicked(url: URL) case sendMessage - case sendReaction(key: String, eventID: String) + case toggleReaction(key: String, eventID: String) case cancelReply case cancelEdit /// Mark the entire room as read - this is heavy handed as a starting point for now. diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 2dd8c0d0c..7e638f22e 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -84,8 +84,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol MXLog.warning("Link clicked: \(url)") case .sendMessage: Task { await sendCurrentMessage() } - case .sendReaction(let emoji, let itemId): - Task { await timelineController.sendReaction(emoji, to: itemId) } + case .toggleReaction(let emoji, let itemId): + Task { await timelineController.toggleReaction(emoji, to: itemId) } case .cancelReply: setComposerMode(.default) case .cancelEdit: diff --git a/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift b/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift index 82e8e45c3..bb14e06d6 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemBubbledStylerView.swift @@ -94,7 +94,7 @@ struct TimelineItemBubbledStylerView: View { if !timelineItem.properties.reactions.isEmpty { TimelineReactionsView(reactions: timelineItem.properties.reactions, alignment: alignment) { key in - context.send(viewAction: .sendReaction(key: key, eventID: timelineItem.id)) + context.send(viewAction: .toggleReaction(key: key, eventID: timelineItem.id)) } } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemPlainStylerView.swift b/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemPlainStylerView.swift index 5048cb0ae..34af5b7e7 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemPlainStylerView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Style/TimelineItemPlainStylerView.swift @@ -117,7 +117,7 @@ struct TimelineItemPlainStylerView: View { if !timelineItem.properties.reactions.isEmpty { TimelineReactionsView(reactions: timelineItem.properties.reactions, alignment: .leading) { key in - context.send(viewAction: .sendReaction(key: key, eventID: timelineItem.id)) + context.send(viewAction: .toggleReaction(key: key, eventID: timelineItem.id)) } } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift index 82ac03084..731a49c5e 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/TimelineItemMenu.swift @@ -150,7 +150,7 @@ public struct TimelineItemMenu: View { private func reactionButton(for emoji: String) -> some View { Button { presentationMode.wrappedValue.dismiss() - context.send(viewAction: .sendReaction(key: emoji, eventID: item.id)) + context.send(viewAction: .toggleReaction(key: emoji, eventID: item.id)) } label: { Text(emoji) .padding(8.0) diff --git a/ElementX/Sources/Services/Room/RoomProxy.swift b/ElementX/Sources/Services/Room/RoomProxy.swift index 84a2db125..0a6984497 100644 --- a/ElementX/Sources/Services/Room/RoomProxy.swift +++ b/ElementX/Sources/Services/Room/RoomProxy.swift @@ -260,7 +260,7 @@ class RoomProxy: RoomProxyProtocol { } } - func sendReaction(_ reaction: String, to eventID: String) async -> Result { + func toggleReaction(_ reaction: String, to eventID: String) async -> Result { sendMessageBackgroundTask = backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true) defer { sendMessageBackgroundTask?.stop() @@ -268,7 +268,7 @@ class RoomProxy: RoomProxyProtocol { return await Task.dispatch(on: userInitiatedDispatchQueue) { do { - try self.room.sendReaction(eventId: eventID, key: reaction) + try self.room.toggleReaction(eventId: eventID, key: reaction) return .success(()) } catch { return .failure(.failedSendingReaction) diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index 8c08c906e..447e89fc7 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -92,7 +92,7 @@ protocol RoomProxyProtocol { func sendMessage(_ message: String, inReplyTo eventID: String?) async -> Result - func sendReaction(_ reaction: String, to eventID: String) async -> Result + func toggleReaction(_ reaction: String, to eventID: String) async -> Result func sendImage(url: URL, thumbnailURL: URL, imageInfo: ImageInfo, progressSubject: CurrentValueSubject?) async -> Result diff --git a/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift index ce972af9f..c96f535b5 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/MockRoomTimelineController.swift @@ -59,7 +59,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol { func sendMessage(_ message: String, inReplyTo itemID: String?) async { } - func sendReaction(_ reaction: String, to itemID: String) async { } + func toggleReaction(_ reaction: String, to itemID: String) async { } func editMessage(_ newMessage: String, original itemID: String) async { } diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift index 4da2c5f1d..05a11a596 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift @@ -156,13 +156,13 @@ class RoomTimelineController: RoomTimelineControllerProtocol { } } - func sendReaction(_ reaction: String, to itemID: String) async { - MXLog.info("Send reaction in \(roomID)") - switch await roomProxy.sendReaction(reaction, to: itemID) { + func toggleReaction(_ reaction: String, to itemID: String) async { + MXLog.info("Toggle reaction in \(roomID)") + switch await roomProxy.toggleReaction(reaction, to: itemID) { case .success: - MXLog.info("Finished sending reaction") + MXLog.info("Finished toggling reaction") case .failure(let error): - MXLog.error("Failed sending reaction with error: \(error)") + MXLog.error("Failed toggling reaction with error: \(error)") } } diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift index 79b6be5fb..5f07880b9 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift @@ -54,7 +54,7 @@ protocol RoomTimelineControllerProtocol { func editMessage(_ newMessage: String, original itemID: String) async - func sendReaction(_ reaction: String, to itemID: String) async + func toggleReaction(_ reaction: String, to itemID: String) async func redact(_ itemID: String) async