Rename sendReaction as toggleReaction

This commit is contained in:
aringenbach
2023-06-26 17:44:31 +02:00
committed by Stefan Ceriu
parent 7d3dcee5a3
commit 88ac3fb8c6
12 changed files with 32 additions and 32 deletions
@@ -500,7 +500,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
MXLog.debug("Selected \(emoji) for \(itemId)") MXLog.debug("Selected \(emoji) for \(itemId)")
self?.navigationStackCoordinator.setSheetCoordinator(nil) self?.navigationStackCoordinator.setSheetCoordinator(nil)
Task { Task {
await self?.timelineController?.sendReaction(emoji, to: itemId) await self?.timelineController?.toggleReaction(emoji, to: itemId)
} }
case .dismiss: case .dismiss:
self?.navigationStackCoordinator.setSheetCoordinator(nil) self?.navigationStackCoordinator.setSheetCoordinator(nil)
@@ -610,25 +610,25 @@ class RoomProxyMock: RoomProxyProtocol {
return sendMessageInReplyToReturnValue return sendMessageInReplyToReturnValue
} }
} }
//MARK: - sendReaction //MARK: - toggleReaction
var sendReactionToCallsCount = 0 var toggleReactionToCallsCount = 0
var sendReactionToCalled: Bool { var toggleReactionToCalled: Bool {
return sendReactionToCallsCount > 0 return toggleReactionToCallsCount > 0
} }
var sendReactionToReceivedArguments: (reaction: String, eventID: String)? var toggleReactionToReceivedArguments: (reaction: String, eventID: String)?
var sendReactionToReceivedInvocations: [(reaction: String, eventID: String)] = [] var toggleReactionToReceivedInvocations: [(reaction: String, eventID: String)] = []
var sendReactionToReturnValue: Result<Void, RoomProxyError>! var toggleReactionToReturnValue: Result<Void, RoomProxyError>!
var sendReactionToClosure: ((String, String) async -> Result<Void, RoomProxyError>)? var toggleReactionToClosure: ((String, String) async -> Result<Void, RoomProxyError>)?
func sendReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError> { func toggleReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError> {
sendReactionToCallsCount += 1 toggleReactionToCallsCount += 1
sendReactionToReceivedArguments = (reaction: reaction, eventID: eventID) toggleReactionToReceivedArguments = (reaction: reaction, eventID: eventID)
sendReactionToReceivedInvocations.append((reaction: reaction, eventID: eventID)) toggleReactionToReceivedInvocations.append((reaction: reaction, eventID: eventID))
if let sendReactionToClosure = sendReactionToClosure { if let toggleReactionToClosure = toggleReactionToClosure {
return await sendReactionToClosure(reaction, eventID) return await toggleReactionToClosure(reaction, eventID)
} else { } else {
return sendReactionToReturnValue return toggleReactionToReturnValue
} }
} }
//MARK: - sendImage //MARK: - sendImage
@@ -54,7 +54,7 @@ enum RoomScreenViewAction {
case itemTapped(id: String) case itemTapped(id: String)
case linkClicked(url: URL) case linkClicked(url: URL)
case sendMessage case sendMessage
case sendReaction(key: String, eventID: String) case toggleReaction(key: String, eventID: String)
case cancelReply case cancelReply
case cancelEdit case cancelEdit
/// Mark the entire room as read - this is heavy handed as a starting point for now. /// Mark the entire room as read - this is heavy handed as a starting point for now.
@@ -84,8 +84,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
MXLog.warning("Link clicked: \(url)") MXLog.warning("Link clicked: \(url)")
case .sendMessage: case .sendMessage:
Task { await sendCurrentMessage() } Task { await sendCurrentMessage() }
case .sendReaction(let emoji, let itemId): case .toggleReaction(let emoji, let itemId):
Task { await timelineController.sendReaction(emoji, to: itemId) } Task { await timelineController.toggleReaction(emoji, to: itemId) }
case .cancelReply: case .cancelReply:
setComposerMode(.default) setComposerMode(.default)
case .cancelEdit: case .cancelEdit:
@@ -94,7 +94,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
if !timelineItem.properties.reactions.isEmpty { if !timelineItem.properties.reactions.isEmpty {
TimelineReactionsView(reactions: timelineItem.properties.reactions, TimelineReactionsView(reactions: timelineItem.properties.reactions,
alignment: alignment) { key in alignment: alignment) { key in
context.send(viewAction: .sendReaction(key: key, eventID: timelineItem.id)) context.send(viewAction: .toggleReaction(key: key, eventID: timelineItem.id))
} }
} }
} }
@@ -117,7 +117,7 @@ struct TimelineItemPlainStylerView<Content: View>: View {
if !timelineItem.properties.reactions.isEmpty { if !timelineItem.properties.reactions.isEmpty {
TimelineReactionsView(reactions: timelineItem.properties.reactions, TimelineReactionsView(reactions: timelineItem.properties.reactions,
alignment: .leading) { key in alignment: .leading) { key in
context.send(viewAction: .sendReaction(key: key, eventID: timelineItem.id)) context.send(viewAction: .toggleReaction(key: key, eventID: timelineItem.id))
} }
} }
} }
@@ -150,7 +150,7 @@ public struct TimelineItemMenu: View {
private func reactionButton(for emoji: String) -> some View { private func reactionButton(for emoji: String) -> some View {
Button { Button {
presentationMode.wrappedValue.dismiss() presentationMode.wrappedValue.dismiss()
context.send(viewAction: .sendReaction(key: emoji, eventID: item.id)) context.send(viewAction: .toggleReaction(key: emoji, eventID: item.id))
} label: { } label: {
Text(emoji) Text(emoji)
.padding(8.0) .padding(8.0)
@@ -260,7 +260,7 @@ class RoomProxy: RoomProxyProtocol {
} }
} }
func sendReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError> { func toggleReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError> {
sendMessageBackgroundTask = backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true) sendMessageBackgroundTask = backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true)
defer { defer {
sendMessageBackgroundTask?.stop() sendMessageBackgroundTask?.stop()
@@ -268,7 +268,7 @@ class RoomProxy: RoomProxyProtocol {
return await Task.dispatch(on: userInitiatedDispatchQueue) { return await Task.dispatch(on: userInitiatedDispatchQueue) {
do { do {
try self.room.sendReaction(eventId: eventID, key: reaction) try self.room.toggleReaction(eventId: eventID, key: reaction)
return .success(()) return .success(())
} catch { } catch {
return .failure(.failedSendingReaction) return .failure(.failedSendingReaction)
@@ -92,7 +92,7 @@ protocol RoomProxyProtocol {
func sendMessage(_ message: String, inReplyTo eventID: String?) async -> Result<Void, RoomProxyError> func sendMessage(_ message: String, inReplyTo eventID: String?) async -> Result<Void, RoomProxyError>
func sendReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError> func toggleReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError>
func sendImage(url: URL, thumbnailURL: URL, imageInfo: ImageInfo, progressSubject: CurrentValueSubject<Double, Never>?) async -> Result<Void, RoomProxyError> func sendImage(url: URL, thumbnailURL: URL, imageInfo: ImageInfo, progressSubject: CurrentValueSubject<Double, Never>?) async -> Result<Void, RoomProxyError>
@@ -59,7 +59,7 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
func sendMessage(_ message: String, inReplyTo itemID: String?) async { } 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 { } func editMessage(_ newMessage: String, original itemID: String) async { }
@@ -156,13 +156,13 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
} }
} }
func sendReaction(_ reaction: String, to itemID: String) async { func toggleReaction(_ reaction: String, to itemID: String) async {
MXLog.info("Send reaction in \(roomID)") MXLog.info("Toggle reaction in \(roomID)")
switch await roomProxy.sendReaction(reaction, to: itemID) { switch await roomProxy.toggleReaction(reaction, to: itemID) {
case .success: case .success:
MXLog.info("Finished sending reaction") MXLog.info("Finished toggling reaction")
case .failure(let error): case .failure(let error):
MXLog.error("Failed sending reaction with error: \(error)") MXLog.error("Failed toggling reaction with error: \(error)")
} }
} }
@@ -54,7 +54,7 @@ protocol RoomTimelineControllerProtocol {
func editMessage(_ newMessage: String, original itemID: String) async 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 func redact(_ itemID: String) async