mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-04 07:17:41 +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()
|
||||||
|
|
||||||
|
@ -129,7 +142,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.PART.command -> {
|
Command.PART.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val roomAlias = messageParts[1]
|
val roomAlias = messageParts[1]
|
||||||
|
|
||||||
|
@ -147,7 +160,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.PART)
|
ParsedCommand.ErrorSyntax(Command.PART)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.ROOM_NAME.command -> {
|
Command.ROOM_NAME.command -> {
|
||||||
val newRoomName = textMessage.substring(Command.ROOM_NAME.command.length).trim()
|
val newRoomName = textMessage.substring(Command.ROOM_NAME.command.length).trim()
|
||||||
|
|
||||||
if (newRoomName.isNotEmpty()) {
|
if (newRoomName.isNotEmpty()) {
|
||||||
|
@ -156,7 +169,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.ROOM_NAME)
|
ParsedCommand.ErrorSyntax(Command.ROOM_NAME)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.INVITE.command -> {
|
Command.INVITE.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -183,7 +196,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.INVITE)
|
ParsedCommand.ErrorSyntax(Command.INVITE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.KICK_USER.command -> {
|
Command.KICK_USER.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -201,7 +214,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.KICK_USER)
|
ParsedCommand.ErrorSyntax(Command.KICK_USER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.BAN_USER.command -> {
|
Command.BAN_USER.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -219,7 +232,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.BAN_USER)
|
ParsedCommand.ErrorSyntax(Command.BAN_USER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.UNBAN_USER.command -> {
|
Command.UNBAN_USER.command -> {
|
||||||
if (messageParts.size >= 2) {
|
if (messageParts.size >= 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -237,7 +250,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.UNBAN_USER)
|
ParsedCommand.ErrorSyntax(Command.UNBAN_USER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.IGNORE_USER.command -> {
|
Command.IGNORE_USER.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size == 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -250,7 +263,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.IGNORE_USER)
|
ParsedCommand.ErrorSyntax(Command.IGNORE_USER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.UNIGNORE_USER.command -> {
|
Command.UNIGNORE_USER.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size == 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -263,7 +276,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.UNIGNORE_USER)
|
ParsedCommand.ErrorSyntax(Command.UNIGNORE_USER)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.SET_USER_POWER_LEVEL.command -> {
|
Command.SET_USER_POWER_LEVEL.command -> {
|
||||||
if (messageParts.size == 3) {
|
if (messageParts.size == 3) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
if (MatrixPatterns.isUserId(userId)) {
|
if (MatrixPatterns.isUserId(userId)) {
|
||||||
|
@ -283,7 +296,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL)
|
ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.RESET_USER_POWER_LEVEL.command -> {
|
Command.RESET_USER_POWER_LEVEL.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size == 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -296,7 +309,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL)
|
ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.MARKDOWN.command -> {
|
Command.MARKDOWN.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size == 2) {
|
||||||
when {
|
when {
|
||||||
"on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true)
|
"on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true)
|
||||||
|
@ -307,28 +320,28 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.MARKDOWN)
|
ParsedCommand.ErrorSyntax(Command.MARKDOWN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.CLEAR_SCALAR_TOKEN.command -> {
|
Command.CLEAR_SCALAR_TOKEN.command -> {
|
||||||
if (messageParts.size == 1) {
|
if (messageParts.size == 1) {
|
||||||
ParsedCommand.ClearScalarToken
|
ParsedCommand.ClearScalarToken
|
||||||
} else {
|
} else {
|
||||||
ParsedCommand.ErrorSyntax(Command.CLEAR_SCALAR_TOKEN)
|
ParsedCommand.ErrorSyntax(Command.CLEAR_SCALAR_TOKEN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.SPOILER.command -> {
|
Command.SPOILER.command -> {
|
||||||
val message = textMessage.substring(Command.SPOILER.command.length).trim()
|
val message = textMessage.substring(Command.SPOILER.command.length).trim()
|
||||||
ParsedCommand.SendSpoiler(message)
|
ParsedCommand.SendSpoiler(message)
|
||||||
}
|
}
|
||||||
Command.SHRUG.command -> {
|
Command.SHRUG.command -> {
|
||||||
val message = textMessage.substring(Command.SHRUG.command.length).trim()
|
val message = textMessage.substring(Command.SHRUG.command.length).trim()
|
||||||
|
|
||||||
ParsedCommand.SendShrug(message)
|
ParsedCommand.SendShrug(message)
|
||||||
}
|
}
|
||||||
Command.LENNY.command -> {
|
Command.LENNY.command -> {
|
||||||
val message = textMessage.substring(Command.LENNY.command.length).trim()
|
val message = textMessage.substring(Command.LENNY.command.length).trim()
|
||||||
|
|
||||||
ParsedCommand.SendLenny(message)
|
ParsedCommand.SendLenny(message)
|
||||||
}
|
}
|
||||||
Command.POLL.command -> {
|
Command.POLL.command -> {
|
||||||
val rawCommand = textMessage.substring(Command.POLL.command.length).trim()
|
val rawCommand = textMessage.substring(Command.POLL.command.length).trim()
|
||||||
val split = rawCommand.split("|").map { it.trim() }
|
val split = rawCommand.split("|").map { it.trim() }
|
||||||
if (split.size > 2) {
|
if (split.size > 2) {
|
||||||
|
@ -337,10 +350,10 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.POLL)
|
ParsedCommand.ErrorSyntax(Command.POLL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command.DISCARD_SESSION.command -> {
|
Command.DISCARD_SESSION.command -> {
|
||||||
ParsedCommand.DiscardSession
|
ParsedCommand.DiscardSession
|
||||||
}
|
}
|
||||||
Command.WHOIS.command -> {
|
Command.WHOIS.command -> {
|
||||||
if (messageParts.size == 2) {
|
if (messageParts.size == 2) {
|
||||||
val userId = messageParts[1]
|
val userId = messageParts[1]
|
||||||
|
|
||||||
|
@ -353,7 +366,7 @@ object CommandParser {
|
||||||
ParsedCommand.ErrorSyntax(Command.WHOIS)
|
ParsedCommand.ErrorSyntax(Command.WHOIS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// Unknown command
|
// Unknown command
|
||||||
ParsedCommand.ErrorUnknownSlashCommand(slashCommand)
|
ParsedCommand.ErrorUnknownSlashCommand(slashCommand)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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