diff --git a/CHANGES.md b/CHANGES.md index 7259f70a16..3a9e37a511 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ Changes in RiotX 0.3.0 (2019-XX-XX) Features: - Create Direct Room flow + - Handle `/markdown` command Improvements: - UI for pending edits (#193) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 90c2fbac30..ebaa006b72 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -639,8 +639,12 @@ class RoomDetailFragment : private fun renderSendMessageResult(sendMessageResult: SendMessageResult) { when (sendMessageResult) { - is SendMessageResult.MessageSent, + is SendMessageResult.MessageSent -> { + // Clear composer + composerLayout.composerEditText.text = null + } is SendMessageResult.SlashCommandHandled -> { + sendMessageResult.messageRes?.let { showSnackWithMessage(getString(it)) } // Clear composer composerLayout.composerEditText.text = null } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 2bb7327d57..fe87117dcd 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -56,6 +56,7 @@ import im.vector.riotx.core.utils.subscribeLogError import im.vector.riotx.features.command.CommandParser import im.vector.riotx.features.command.ParsedCommand import im.vector.riotx.features.home.room.detail.timeline.helper.TimelineDisplayableEvents +import im.vector.riotx.features.settings.VectorPreferences import io.reactivex.rxkotlin.subscribeBy import org.commonmark.parser.Parser import org.commonmark.renderer.html.HtmlRenderer @@ -66,6 +67,7 @@ import java.util.concurrent.TimeUnit class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: RoomDetailViewState, userPreferencesProvider: UserPreferencesProvider, + private val vectorPreferences: VectorPreferences, private val session: Session ) : VectorViewModel(initialState) { @@ -243,8 +245,9 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandNotImplemented) } is ParsedCommand.SetMarkdown -> { - // TODO - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandNotImplemented) + vectorPreferences.setMarkdownEnabled(slashCommandResult.enable) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled( + if (slashCommandResult.enable) R.string.markdown_has_been_enabled else R.string.markdown_has_been_disabled)) } is ParsedCommand.UnbanUser -> { // TODO @@ -268,7 +271,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } is ParsedCommand.SendEmote -> { room.sendTextMessage(slashCommandResult.message, msgType = MessageType.MSGTYPE_EMOTE) - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled()) } is ParsedCommand.ChangeTopic -> { handleChangeTopicSlashCommand(slashCommandResult) @@ -348,8 +351,6 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } } } - // Handle slash command - } private fun legacyRiotQuoteText(quotedText: String?, myText: String): String { @@ -371,7 +372,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleChangeTopicSlashCommand(changeTopic: ParsedCommand.ChangeTopic) { - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled()) room.updateTopic(changeTopic.topic, object : MatrixCallback { override fun onSuccess(data: Unit) { @@ -385,7 +386,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro } private fun handleInviteSlashCommand(invite: ParsedCommand.Invite) { - _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled) + _sendMessageResultLiveData.postLiveEvent(SendMessageResult.SlashCommandHandled()) room.invite(invite.userId, object : MatrixCallback { override fun onSuccess(data: Unit) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt index ae7a470605..c64b1fbd19 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/SendMessageResult.kt @@ -16,13 +16,14 @@ package im.vector.riotx.features.home.room.detail +import androidx.annotation.StringRes import im.vector.riotx.features.command.Command sealed class SendMessageResult { object MessageSent : SendMessageResult() class SlashCommandError(val command: Command) : SendMessageResult() class SlashCommandUnknown(val command: String) : SendMessageResult() - object SlashCommandHandled : SendMessageResult() + data class SlashCommandHandled(@StringRes val messageRes: Int? = null) : SendMessageResult() object SlashCommandResultOk : SendMessageResult() class SlashCommandResultError(val throwable: Throwable) : SendMessageResult() // TODO Remove