Added /roomavatar command (not upload)

This commit is contained in:
Constantin Wartenburger 2020-10-12 17:43:07 +02:00
parent 1a40b65b53
commit 24c67660c1
No known key found for this signature in database
GPG key ID: 7439D96D8E1DB894
5 changed files with 29 additions and 2 deletions

View file

@ -32,7 +32,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
UNIGNORE_USER("/unignore", "<user-id>", R.string.command_description_unignore_user),
SET_USER_POWER_LEVEL("/op", "<user-id> [<power-level>]", R.string.command_description_op_user),
RESET_USER_POWER_LEVEL("/deop", "<user-id>", R.string.command_description_deop_user),
ROOM_NAME("/roomname", "<user-id> [reason]", R.string.command_description_room_name),
ROOM_NAME("/roomname", "<user-id>", R.string.command_description_room_name),
INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user),
JOIN_ROOM("/join", "<room-alias> [reason]", R.string.command_description_join_room),
PART("/part", "<room-alias> [reason]", R.string.command_description_part_room),
@ -40,6 +40,7 @@ enum class Command(val command: String, val parameters: String, @StringRes val d
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_nick_for_room),
ROOM_AVATAR("/roomavatar", "<mxc_url>", R.string.command_description_room_avatar),
CHANGE_AVATAR_FOR_ROOM("/myroomavatar", "<mxc_url>", R.string.command_description_avatar_for_room),
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow),

View file

@ -87,11 +87,24 @@ object CommandParser {
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME_FOR_ROOM)
}
}
Command.ROOM_AVATAR.command -> {
if (messageParts.size == 2) {
val url = messageParts[1]
if (url.isNotEmpty() && url.startsWith("mxc://")) {
ParsedCommand.ChangeRoomAvatar(url)
} else {
ParsedCommand.ErrorSyntax(Command.ROOM_AVATAR)
}
} else {
ParsedCommand.ErrorSyntax(Command.ROOM_AVATAR)
}
}
Command.CHANGE_AVATAR_FOR_ROOM.command -> {
if (messageParts.size == 2) {
val url = messageParts[1]
if (url.isNotEmpty()) {
if (url.isNotEmpty() && url.startsWith("mxc://")) {
ParsedCommand.ChangeAvatarForRoom(url)
} else {
ParsedCommand.ErrorSyntax(Command.CHANGE_AVATAR_FOR_ROOM)

View file

@ -53,6 +53,7 @@ sealed class ParsedCommand {
class KickUser(val userId: String, val reason: String?) : ParsedCommand()
class ChangeDisplayName(val displayName: String) : ParsedCommand()
class ChangeDisplayNameForRoom(val displayName: String) : ParsedCommand()
class ChangeRoomAvatar(val url: String) : ParsedCommand()
class ChangeAvatarForRoom(val url: String) : ParsedCommand()
class SetMarkdown(val enable: Boolean) : ParsedCommand()
object ClearScalarToken : ParsedCommand()

View file

@ -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.RoomAvatarContent
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
@ -680,6 +681,10 @@ class RoomDetailViewModel @AssistedInject constructor(
handleChangeDisplayNameForRoomSlashCommand(slashCommandResult)
popDraft()
}
is ParsedCommand.ChangeRoomAvatar -> {
handleChangeRoomAvatarSlashCommand(slashCommandResult)
popDraft()
}
is ParsedCommand.ChangeAvatarForRoom -> {
handleChangeAvatarForRoomSlashCommand(slashCommandResult)
popDraft()
@ -857,6 +862,12 @@ class RoomDetailViewModel @AssistedInject constructor(
}
}
private fun handleChangeRoomAvatarSlashCommand(changeAvatar: ParsedCommand.ChangeRoomAvatar) {
launchSlashCommandFlow {
room.sendStateEvent(EventType.STATE_ROOM_AVATAR, null, RoomAvatarContent(changeAvatar.url).toContent(), it)
}
}
private fun handleChangeAvatarForRoomSlashCommand(changeAvatar: ParsedCommand.ChangeAvatarForRoom) {
launchSlashCommandFlow {
room.sendStateEvent(EventType.STATE_ROOM_MEMBER, session.myUserId, getLastMemberEvent().copy(avatarUrl = changeAvatar.url).toContent(), it)

View file

@ -1299,6 +1299,7 @@
<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_for_room">Changes your display nickname in the current room only</string>
<string name="command_description_room_avatar">Changes the avatar of the current room</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_clear_scalar_token">To fix Matrix Apps management</string>