mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-01 05:48:39 +03:00
Added /myroomnick command
This commit is contained in:
parent
c0cf534845
commit
13960561c0
5 changed files with 34 additions and 7 deletions
|
@ -39,6 +39,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
|
|||
TOPIC("/topic", "<topic>", R.string.command_description_topic),
|
||||
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user),
|
||||
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick),
|
||||
CHANGE_DISPLAY_NAME_FOR_ROOM("/myroomnick", "<display-name>", R.string.command_description_room_nick),
|
||||
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
|
||||
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow),
|
||||
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote),
|
||||
|
|
|
@ -60,7 +60,7 @@ object CommandParser {
|
|||
}
|
||||
|
||||
return when (val slashCommand = messageParts.first()) {
|
||||
Command.PLAIN.command -> {
|
||||
Command.PLAIN.command -> {
|
||||
val text = textMessage.substring(Command.PLAIN.command.length).trim()
|
||||
|
||||
if (text.isNotEmpty()) {
|
||||
|
@ -69,7 +69,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.PLAIN)
|
||||
}
|
||||
}
|
||||
Command.CHANGE_DISPLAY_NAME.command -> {
|
||||
Command.CHANGE_DISPLAY_NAME.command -> {
|
||||
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()
|
||||
|
||||
if (newDisplayName.isNotEmpty()) {
|
||||
|
@ -78,7 +78,16 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME)
|
||||
}
|
||||
}
|
||||
Command.TOPIC.command -> {
|
||||
Command.CHANGE_DISPLAY_NAME_FOR_ROOM.command -> {
|
||||
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME_FOR_ROOM.command.length).trim()
|
||||
|
||||
if (newDisplayName.isNotEmpty()) {
|
||||
ParsedCommand.ChangeDisplayNameForRoom(newDisplayName)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME_FOR_ROOM)
|
||||
}
|
||||
}
|
||||
Command.TOPIC.command -> {
|
||||
val newTopic = textMessage.substring(Command.TOPIC.command.length).trim()
|
||||
|
||||
if (newTopic.isNotEmpty()) {
|
||||
|
@ -87,22 +96,22 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.TOPIC)
|
||||
}
|
||||
}
|
||||
Command.EMOTE.command -> {
|
||||
Command.EMOTE.command -> {
|
||||
val message = textMessage.subSequence(Command.EMOTE.command.length, textMessage.length).trim()
|
||||
|
||||
ParsedCommand.SendEmote(message)
|
||||
}
|
||||
Command.RAINBOW.command -> {
|
||||
Command.RAINBOW.command -> {
|
||||
val message = textMessage.subSequence(Command.RAINBOW.command.length, textMessage.length).trim()
|
||||
|
||||
ParsedCommand.SendRainbow(message)
|
||||
}
|
||||
Command.RAINBOW_EMOTE.command -> {
|
||||
Command.RAINBOW_EMOTE.command -> {
|
||||
val message = textMessage.subSequence(Command.RAINBOW_EMOTE.command.length, textMessage.length).trim()
|
||||
|
||||
ParsedCommand.SendRainbowEmote(message)
|
||||
}
|
||||
Command.JOIN_ROOM.command -> {
|
||||
Command.JOIN_ROOM.command -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val roomAlias = messageParts[1]
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ sealed class ParsedCommand {
|
|||
class ChangeTopic(val topic: String) : ParsedCommand()
|
||||
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
|
||||
class ChangeDisplayName(val displayName: String) : ParsedCommand()
|
||||
class ChangeDisplayNameForRoom(val displayName: String) : ParsedCommand()
|
||||
class SetMarkdown(val enable: Boolean) : ParsedCommand()
|
||||
object ClearScalarToken : ParsedCommand()
|
||||
class SendSpoiler(val message: String) : ParsedCommand()
|
||||
|
|
|
@ -74,6 +74,7 @@ import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState
|
|||
import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberContent
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||
|
@ -675,6 +676,10 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
handleChangeDisplayNameSlashCommand(slashCommandResult)
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.ChangeDisplayNameForRoom -> {
|
||||
handleChangeDisplayNameForRoomSlashCommand(slashCommandResult)
|
||||
popDraft()
|
||||
}
|
||||
is ParsedCommand.ShowUser -> {
|
||||
_viewEvents.post(RoomDetailViewEvents.SlashCommandHandled())
|
||||
handleWhoisSlashCommand(slashCommandResult)
|
||||
|
@ -836,6 +841,16 @@ class RoomDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleChangeDisplayNameForRoomSlashCommand(changeDisplayName: ParsedCommand.ChangeDisplayNameForRoom) {
|
||||
val content = room.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(session.myUserId))
|
||||
?.content?.toModel<RoomMemberContent>()
|
||||
?: RoomMemberContent(membership = Membership.JOIN)
|
||||
|
||||
launchSlashCommandFlow {
|
||||
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, content.copy(displayName = changeDisplayName.displayName).toContent(), it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleKickSlashCommand(kick: ParsedCommand.KickUser) {
|
||||
launchSlashCommandFlow {
|
||||
room.kick(kick.userId, kick.reason, it)
|
||||
|
|
|
@ -1298,6 +1298,7 @@
|
|||
<string name="command_description_topic">Set the room topic</string>
|
||||
<string name="command_description_kick_user">Kicks user with given id</string>
|
||||
<string name="command_description_nick">Changes your display nickname</string>
|
||||
<string name="command_description_room_nick">Changes your display nickname</string>
|
||||
<string name="command_description_markdown">On/Off markdown</string>
|
||||
<string name="command_description_clear_scalar_token">To fix Matrix Apps management</string>
|
||||
<string name="command_description_whois">Displays information about a user</string>
|
||||
|
|
Loading…
Reference in a new issue