From 5cb7e455b1eb4a4da1724812d423e1d798a2feb5 Mon Sep 17 00:00:00 2001 From: onurays Date: Fri, 13 Mar 2020 14:00:46 +0300 Subject: [PATCH] Implementation of /join command. --- CHANGES.md | 2 +- .../home/room/detail/RoomDetailFragment.kt | 7 +++++++ .../home/room/detail/RoomDetailViewEvents.kt | 1 + .../home/room/detail/RoomDetailViewModel.kt | 20 +++++++++++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 918cfd61de..04825e2ac7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ Features ✨: - Improvements 🙌: - - + - /join command implemented Bugfix 🐛: - 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 ad4e9694db..9916fa522b 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 @@ -297,11 +297,18 @@ class RoomDetailFragment @Inject constructor( is RoomDetailViewEvents.NavigateToEvent -> navigateToEvent(it) is RoomDetailViewEvents.FileTooBigError -> displayFileTooBigError(it) is RoomDetailViewEvents.DownloadFileState -> handleDownloadFileState(it) + is RoomDetailViewEvents.JoinedToAnotherRoom -> handleJoinedToAnotherRoom(it) is RoomDetailViewEvents.SendMessageResult -> renderSendMessageResult(it) }.exhaustive } } + private fun handleJoinedToAnotherRoom(action: RoomDetailViewEvents.JoinedToAnotherRoom) { + updateComposerText("") + lockSendButton = false + navigator.openRoom(vectorBaseActivity, action.roomId) + } + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) if (savedInstanceState == null) { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt index fcbe7f37c0..df0ead3b38 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewEvents.kt @@ -50,6 +50,7 @@ sealed class RoomDetailViewEvents : VectorViewEvents { abstract class SendMessageResult : RoomDetailViewEvents() object MessageSent : SendMessageResult() + data class JoinedToAnotherRoom(val roomId: String) : SendMessageResult() class SlashCommandError(val command: Command) : SendMessageResult() class SlashCommandUnknown(val command: String) : SendMessageResult() data class SlashCommandHandled(@StringRes val messageRes: Int? = null) : SendMessageResult() 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 4ab9125c4f..aa04b80202 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 @@ -379,8 +379,8 @@ class RoomDetailViewModel @AssistedInject constructor( _viewEvents.post(RoomDetailViewEvents.SlashCommandNotImplemented) } is ParsedCommand.JoinRoom -> { - // TODO - _viewEvents.post(RoomDetailViewEvents.SlashCommandNotImplemented) + handleJoinToAnotherRoomSlashCommand(slashCommandResult) + popDraft() } is ParsedCommand.PartRoom -> { // TODO @@ -512,6 +512,22 @@ class RoomDetailViewModel @AssistedInject constructor( room.deleteDraft(NoOpMatrixCallback()) } + private fun handleJoinToAnotherRoomSlashCommand(command: ParsedCommand.JoinRoom) { + session.joinRoom(command.roomAlias, command.reason, object : MatrixCallback { + override fun onSuccess(data: Unit) { + session.getRoomSummary(command.roomAlias) + ?.roomId + ?.let { + _viewEvents.post(RoomDetailViewEvents.JoinedToAnotherRoom(it)) + } + } + + override fun onFailure(failure: Throwable) { + _viewEvents.post(RoomDetailViewEvents.SlashCommandResultError(failure)) + } + }) + } + private fun legacyRiotQuoteText(quotedText: String?, myText: String): String { val messageParagraphs = quotedText?.split("\n\n".toRegex())?.dropLastWhile { it.isEmpty() }?.toTypedArray() return buildString {