mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Implement /part command, with or without parameter
This commit is contained in:
parent
f5eaf2f05f
commit
fe2ba28441
5 changed files with 23 additions and 19 deletions
1
changelog.d/2909.feature
Normal file
1
changelog.d/2909.feature
Normal file
|
@ -0,0 +1 @@
|
|||
Implement /part command, with or without parameter
|
|
@ -35,7 +35,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
|
|||
ROOM_NAME("/roomname", "<name>", R.string.command_description_room_name, false),
|
||||
INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user, false),
|
||||
JOIN_ROOM("/join", "<room-address> [reason]", R.string.command_description_join_room, false),
|
||||
PART("/part", "<room-address> [reason]", R.string.command_description_part_room, false),
|
||||
PART("/part", "[<room-address>]", R.string.command_description_part_room, false),
|
||||
TOPIC("/topic", "<topic>", R.string.command_description_topic, false),
|
||||
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user, false),
|
||||
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick, false),
|
||||
|
|
|
@ -158,21 +158,10 @@ object CommandParser {
|
|||
}
|
||||
}
|
||||
Command.PART.command -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val roomAlias = messageParts[1]
|
||||
|
||||
if (roomAlias.isNotEmpty()) {
|
||||
ParsedCommand.PartRoom(
|
||||
roomAlias,
|
||||
textMessage.substring(Command.PART.length + roomAlias.length)
|
||||
.trim()
|
||||
.takeIf { it.isNotBlank() }
|
||||
)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.PART)
|
||||
}
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.PART)
|
||||
when (messageParts.size) {
|
||||
1 -> ParsedCommand.PartRoom(null)
|
||||
2 -> ParsedCommand.PartRoom(messageParts[1])
|
||||
else -> ParsedCommand.ErrorSyntax(Command.PART)
|
||||
}
|
||||
}
|
||||
Command.ROOM_NAME.command -> {
|
||||
|
|
|
@ -49,7 +49,7 @@ sealed class ParsedCommand {
|
|||
class Invite(val userId: String, val reason: String?) : ParsedCommand()
|
||||
class Invite3Pid(val threePid: ThreePid) : ParsedCommand()
|
||||
class JoinRoom(val roomAlias: String, val reason: String?) : ParsedCommand()
|
||||
class PartRoom(val roomAlias: String, val reason: String?) : ParsedCommand()
|
||||
class PartRoom(val roomAlias: String?) : ParsedCommand()
|
||||
class ChangeTopic(val topic: String) : ParsedCommand()
|
||||
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
|
||||
class ChangeDisplayName(val displayName: String) : ParsedCommand()
|
||||
|
|
|
@ -225,8 +225,8 @@ class TextComposerViewModel @AssistedInject constructor(
|
|||
popDraft()
|
||||
}
|
||||
is ParsedCommand.PartRoom -> {
|
||||
// TODO
|
||||
_viewEvents.post(TextComposerViewEvents.SlashCommandNotImplemented)
|
||||
handlePartSlashCommand(slashCommandResult)
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.SendEmote -> {
|
||||
room.sendTextMessage(slashCommandResult.message, msgType = MessageType.MSGTYPE_EMOTE, autoMarkdown = action.autoMarkdown)
|
||||
|
@ -578,6 +578,20 @@ class TextComposerViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handlePartSlashCommand(command: ParsedCommand.PartRoom) {
|
||||
launchSlashCommandFlowSuspendable {
|
||||
if (command.roomAlias == null) {
|
||||
// Leave the current room
|
||||
room
|
||||
} else {
|
||||
session.getRoomSummary(roomIdOrAlias = command.roomAlias)
|
||||
?.roomId
|
||||
?.let { session.getRoom(it) }
|
||||
}
|
||||
?.leave(reason = null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleKickSlashCommand(kick: ParsedCommand.KickUser) {
|
||||
launchSlashCommandFlowSuspendable {
|
||||
room.kick(kick.userId, kick.reason)
|
||||
|
|
Loading…
Reference in a new issue