mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-06 08:17:38 +03:00
Added /myroomavatar command (without upload)
This commit is contained in:
parent
13960561c0
commit
1a40b65b53
5 changed files with 52 additions and 24 deletions
|
@ -39,7 +39,8 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
|
||||||
TOPIC("/topic", "<topic>", R.string.command_description_topic),
|
TOPIC("/topic", "<topic>", R.string.command_description_topic),
|
||||||
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user),
|
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("/nick", "<display-name>", R.string.command_description_nick),
|
||||||
CHANGE_DISPLAY_NAME_FOR_ROOM("/myroomnick", "<display-name>", R.string.command_description_room_nick),
|
CHANGE_DISPLAY_NAME_FOR_ROOM("/myroomnick", "<display-name>", R.string.command_description_nick_for_room),
|
||||||
|
CHANGE_AVATAR_FOR_ROOM("/myroomavatar", "<mxc_url>", R.string.command_description_avatar_for_room),
|
||||||
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
|
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
|
||||||
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow),
|
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow),
|
||||||
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote),
|
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote),
|
||||||
|
|
|
@ -87,6 +87,19 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME_FOR_ROOM)
|
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME_FOR_ROOM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command.CHANGE_AVATAR_FOR_ROOM.command -> {
|
||||||
|
if (messageParts.size == 2) {
|
||||||
|
val url = messageParts[1]
|
||||||
|
|
||||||
|
if (url.isNotEmpty()) {
|
||||||
|
ParsedCommand.ChangeAvatarForRoom(url)
|
||||||
|
} else {
|
||||||
|
ParsedCommand.ErrorSyntax(Command.CHANGE_AVATAR_FOR_ROOM)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ParsedCommand.ErrorSyntax(Command.CHANGE_AVATAR_FOR_ROOM)
|
||||||
|
}
|
||||||
|
}
|
||||||
Command.TOPIC.command -> {
|
Command.TOPIC.command -> {
|
||||||
val newTopic = textMessage.substring(Command.TOPIC.command.length).trim()
|
val newTopic = textMessage.substring(Command.TOPIC.command.length).trim()
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ sealed class ParsedCommand {
|
||||||
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
|
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
|
||||||
class ChangeDisplayName(val displayName: String) : ParsedCommand()
|
class ChangeDisplayName(val displayName: String) : ParsedCommand()
|
||||||
class ChangeDisplayNameForRoom(val displayName: String) : ParsedCommand()
|
class ChangeDisplayNameForRoom(val displayName: String) : ParsedCommand()
|
||||||
|
class ChangeAvatarForRoom(val url: String) : ParsedCommand()
|
||||||
class SetMarkdown(val enable: Boolean) : ParsedCommand()
|
class SetMarkdown(val enable: Boolean) : ParsedCommand()
|
||||||
object ClearScalarToken : ParsedCommand()
|
object ClearScalarToken : ParsedCommand()
|
||||||
class SendSpoiler(val message: String) : ParsedCommand()
|
class SendSpoiler(val message: String) : ParsedCommand()
|
||||||
|
|
|
@ -680,6 +680,10 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
handleChangeDisplayNameForRoomSlashCommand(slashCommandResult)
|
handleChangeDisplayNameForRoomSlashCommand(slashCommandResult)
|
||||||
popDraft()
|
popDraft()
|
||||||
}
|
}
|
||||||
|
is ParsedCommand.ChangeAvatarForRoom -> {
|
||||||
|
handleChangeAvatarForRoomSlashCommand(slashCommandResult)
|
||||||
|
popDraft()
|
||||||
|
}
|
||||||
is ParsedCommand.ShowUser -> {
|
is ParsedCommand.ShowUser -> {
|
||||||
_viewEvents.post(RoomDetailViewEvents.SlashCommandHandled())
|
_viewEvents.post(RoomDetailViewEvents.SlashCommandHandled())
|
||||||
handleWhoisSlashCommand(slashCommandResult)
|
handleWhoisSlashCommand(slashCommandResult)
|
||||||
|
@ -841,13 +845,21 @@ class RoomDetailViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleChangeDisplayNameForRoomSlashCommand(changeDisplayName: ParsedCommand.ChangeDisplayNameForRoom) {
|
private fun getLastMemberEvent(): RoomMemberContent {
|
||||||
val content = room.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(session.myUserId))
|
return room.getStateEvent(EventType.STATE_ROOM_MEMBER, QueryStringValue.Equals(session.myUserId))
|
||||||
?.content?.toModel<RoomMemberContent>()
|
?.content?.toModel<RoomMemberContent>()
|
||||||
?: RoomMemberContent(membership = Membership.JOIN)
|
?: RoomMemberContent(membership = Membership.JOIN)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleChangeDisplayNameForRoomSlashCommand(changeDisplayName: ParsedCommand.ChangeDisplayNameForRoom) {
|
||||||
launchSlashCommandFlow {
|
launchSlashCommandFlow {
|
||||||
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, content.copy(displayName = changeDisplayName.displayName).toContent(), it)
|
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, getLastMemberEvent().copy(displayName = changeDisplayName.displayName).toContent(), it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleChangeAvatarForRoomSlashCommand(changeAvatar: ParsedCommand.ChangeAvatarForRoom) {
|
||||||
|
launchSlashCommandFlow {
|
||||||
|
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, getLastMemberEvent().copy(avatarUrl = changeAvatar.url).toContent(), it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1298,7 +1298,8 @@
|
||||||
<string name="command_description_topic">Set the room topic</string>
|
<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_kick_user">Kicks user with given id</string>
|
||||||
<string name="command_description_nick">Changes your display nickname</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_nick_for_room">Changes your display nickname in the current room only</string>
|
||||||
|
<string name="command_description_avatar_for_room">Changes your avatar in this current room only</string>
|
||||||
<string name="command_description_markdown">On/Off markdown</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_clear_scalar_token">To fix Matrix Apps management</string>
|
||||||
<string name="command_description_whois">Displays information about a user</string>
|
<string name="command_description_whois">Displays information about a user</string>
|
||||||
|
|
Loading…
Reference in a new issue