diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt index a6ae9d7..fc90d92 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/state/MessengerReducer.kt @@ -85,12 +85,22 @@ internal fun messengerReducer( change(ComposerStateChange.ReplyMode::class) { action, state -> when (action) { - is ComposerStateChange.ReplyMode.Enter -> state.copy( - composerState = when (state.composerState) { - is ComposerState.Attachments -> state.composerState.copy(reply = action.replyingTo) - is ComposerState.Text -> state.composerState.copy(reply = action.replyingTo) + is ComposerStateChange.ReplyMode.Enter -> { + when (action.replyingTo) { + is RoomEvent.Message -> state.copy( + composerState = when (state.composerState) { + is ComposerState.Attachments -> state.composerState.copy(reply = action.replyingTo) + is ComposerState.Text -> state.composerState.copy(reply = action.replyingTo) + } + ) + + // TODO support replying to more message types + is RoomEvent.Encrypted, + is RoomEvent.Image, + is RoomEvent.Redacted, + is RoomEvent.Reply -> state } - ) + } ComposerStateChange.ReplyMode.Exit -> state.copy( composerState = when (state.composerState) { diff --git a/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt b/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt index b517dd0..478ec19 100644 --- a/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt +++ b/features/messenger/src/test/kotlin/app/dapk/st/messenger/MessengerReducerTest.kt @@ -29,7 +29,8 @@ private val AN_EVENT_ID = anEventId("state event") private val A_SELF_ID = aUserId("self") private val A_MESSENGER_PAGE_STATE = aMessengerStateWithEvent(AN_EVENT_ID, A_SELF_ID) private val A_MESSAGE_ATTACHMENT = MessageAttachment(AndroidUri("a-uri"), MimeType.Image) -private val A_REPLY = aRoomReplyMessageEvent() +private val A_REPLY = aRoomMessageEvent() +private val AN_SUPPORTED_REPLY = aRoomReplyMessageEvent() private val AN_IMAGE_BUBBLE = BubbleModel.Image( BubbleModel.Image.ImageContent(100, 200, "a-url"), mockk(), @@ -184,7 +185,7 @@ class MessengerReducerTest { } @Test - fun `given text composer, when Enter ReplyMode, then updates composer state with reply`() = runReducerTest { + fun `given message text composer, when Enter ReplyMode, then updates composer state with reply`() = runReducerTest { setState { it.copy(composerState = ComposerState.Text(A_MESSAGE_CONTENT, reply = null)) } reduce(ComposerStateChange.ReplyMode.Enter(A_REPLY)) @@ -194,6 +195,15 @@ class MessengerReducerTest { } } + @Test + fun `given text composer, when Enter ReplyMode with unsupported content, then does nothing`() = runReducerTest { + setState { it.copy(composerState = ComposerState.Text(A_MESSAGE_CONTENT, reply = null)) } + + reduce(ComposerStateChange.ReplyMode.Enter(AN_SUPPORTED_REPLY)) + + assertNoChanges() + } + @Test fun `given text composer, when Exit ReplyMode, then updates composer state`() = runReducerTest { setState { it.copy(composerState = ComposerState.Text(A_MESSAGE_CONTENT, reply = A_REPLY)) } @@ -333,8 +343,8 @@ class MessengerReducerTest { @Test fun `given text composer with reply, when SendMessage, then clear composer and sends text message`() = runReducerTest { - setState { it.copy(composerState = ComposerState.Text(A_MESSAGE_CONTENT, reply = A_REPLY.message), roomState = Lce.Content(A_MESSENGER_PAGE_STATE)) } - fakeChatEngine.expectUnit { it.send(expectTextMessage(A_MESSAGE_CONTENT, reply = A_REPLY.message), A_MESSENGER_PAGE_STATE.roomState.roomOverview) } + setState { it.copy(composerState = ComposerState.Text(A_MESSAGE_CONTENT, reply = A_REPLY), roomState = Lce.Content(A_MESSENGER_PAGE_STATE)) } + fakeChatEngine.expectUnit { it.send(expectTextMessage(A_MESSAGE_CONTENT, reply = A_REPLY), A_MESSENGER_PAGE_STATE.roomState.roomOverview) } reduce(ScreenAction.SendMessage)