Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of /join command (#12) #1138

Merged
merged 3 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Features ✨:
-

Improvements 🙌:
-
- Implementation of /join command

Bugfix 🐛:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename it to JoinRoomCommandSucces

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Unit> {
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 {
Expand Down