Merge pull request #4911 from vector-im/feature/nfe/rename_kick_command
Remove "X kicked X" terminology when removing people from a room
This commit is contained in:
commit
31e487b073
|
@ -0,0 +1 @@
|
|||
"/kick" command is replaced with "/remove". Also replaced all occurrences in string resources
|
|
@ -75,9 +75,12 @@ interface MembershipService {
|
|||
suspend fun unban(userId: String, reason: String? = null)
|
||||
|
||||
/**
|
||||
* Kick a user from the room
|
||||
* Remove a user from the room
|
||||
*/
|
||||
suspend fun kick(userId: String, reason: String? = null)
|
||||
suspend fun remove(userId: String, reason: String? = null)
|
||||
|
||||
@Deprecated("Use remove instead", ReplaceWith("remove(userId, reason)"))
|
||||
suspend fun kick(userId: String, reason: String? = null) = remove(userId, reason)
|
||||
|
||||
/**
|
||||
* Join the room, or accept an invitation.
|
||||
|
|
|
@ -125,7 +125,7 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
membershipAdminTask.execute(params)
|
||||
}
|
||||
|
||||
override suspend fun kick(userId: String, reason: String?) {
|
||||
override suspend fun remove(userId: String, reason: String?) {
|
||||
val params = MembershipAdminTask.Params(MembershipAdminTask.Type.KICK, roomId, userId, reason)
|
||||
membershipAdminTask.execute(params)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class AutocompleteCommandPresenter @Inject constructor(context: Context,
|
|||
if (query.isNullOrEmpty()) {
|
||||
true
|
||||
} else {
|
||||
it.command.startsWith(query, 1, true)
|
||||
it.startsWith(query)
|
||||
}
|
||||
}
|
||||
controller.setData(data)
|
||||
|
|
|
@ -24,42 +24,50 @@ import im.vector.app.R
|
|||
* the user can write theses messages to perform some actions
|
||||
* the list will be displayed in this order
|
||||
*/
|
||||
enum class Command(val command: String, val parameters: String, @StringRes val description: Int, val isDevCommand: Boolean) {
|
||||
EMOTE("/me", "<message>", R.string.command_description_emote, false),
|
||||
BAN_USER("/ban", "<user-id> [reason]", R.string.command_description_ban_user, false),
|
||||
UNBAN_USER("/unban", "<user-id> [reason]", R.string.command_description_unban_user, false),
|
||||
IGNORE_USER("/ignore", "<user-id> [reason]", R.string.command_description_ignore_user, false),
|
||||
UNIGNORE_USER("/unignore", "<user-id>", R.string.command_description_unignore_user, false),
|
||||
SET_USER_POWER_LEVEL("/op", "<user-id> [<power-level>]", R.string.command_description_op_user, false),
|
||||
RESET_USER_POWER_LEVEL("/deop", "<user-id>", R.string.command_description_deop_user, false),
|
||||
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>]", 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),
|
||||
CHANGE_DISPLAY_NAME_FOR_ROOM("/myroomnick", "<display-name>", R.string.command_description_nick_for_room, false),
|
||||
ROOM_AVATAR("/roomavatar", "<mxc_url>", R.string.command_description_room_avatar, true /* Since user has to know the mxc url */),
|
||||
CHANGE_AVATAR_FOR_ROOM("/myroomavatar", "<mxc_url>", R.string.command_description_avatar_for_room, true /* Since user has to know the mxc url */),
|
||||
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown, false),
|
||||
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow, false),
|
||||
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote, false),
|
||||
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token, false),
|
||||
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler, false),
|
||||
SHRUG("/shrug", "<message>", R.string.command_description_shrug, false),
|
||||
LENNY("/lenny", "<message>", R.string.command_description_lenny, false),
|
||||
PLAIN("/plain", "<message>", R.string.command_description_plain, false),
|
||||
WHOIS("/whois", "<user-id>", R.string.command_description_whois, false),
|
||||
DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session, false),
|
||||
CONFETTI("/confetti", "<message>", R.string.command_confetti, false),
|
||||
SNOWFALL("/snowfall", "<message>", R.string.command_snow, false),
|
||||
CREATE_SPACE("/createspace", "<name> <invitee>*", R.string.command_description_create_space, true),
|
||||
ADD_TO_SPACE("/addToSpace", "spaceId", R.string.command_description_add_to_space, true),
|
||||
JOIN_SPACE("/joinSpace", "spaceId", R.string.command_description_join_space, true),
|
||||
LEAVE_ROOM("/leave", "<roomId?>", R.string.command_description_leave_room, true),
|
||||
UPGRADE_ROOM("/upgraderoom", "newVersion", R.string.command_description_upgrade_room, true);
|
||||
enum class Command(val command: String,
|
||||
val aliases: Array<CharSequence>?,
|
||||
val parameters: String,
|
||||
@StringRes val description: Int,
|
||||
val isDevCommand: Boolean) {
|
||||
EMOTE("/me", null, "<message>", R.string.command_description_emote, false),
|
||||
BAN_USER("/ban", null, "<user-id> [reason]", R.string.command_description_ban_user, false),
|
||||
UNBAN_USER("/unban", null, "<user-id> [reason]", R.string.command_description_unban_user, false),
|
||||
IGNORE_USER("/ignore", null, "<user-id> [reason]", R.string.command_description_ignore_user, false),
|
||||
UNIGNORE_USER("/unignore", null, "<user-id>", R.string.command_description_unignore_user, false),
|
||||
SET_USER_POWER_LEVEL("/op", null, "<user-id> [<power-level>]", R.string.command_description_op_user, false),
|
||||
RESET_USER_POWER_LEVEL("/deop", null, "<user-id>", R.string.command_description_deop_user, false),
|
||||
ROOM_NAME("/roomname", null, "<name>", R.string.command_description_room_name, false),
|
||||
INVITE("/invite", null, "<user-id> [reason]", R.string.command_description_invite_user, false),
|
||||
JOIN_ROOM("/join", arrayOf("/j", "/goto"), "<room-address> [reason]", R.string.command_description_join_room, false),
|
||||
PART("/part", null, "[<room-address>]", R.string.command_description_part_room, false),
|
||||
TOPIC("/topic", null, "<topic>", R.string.command_description_topic, false),
|
||||
REMOVE_USER("/remove", arrayOf("/kick"), "<user-id> [reason]", R.string.command_description_kick_user, false),
|
||||
CHANGE_DISPLAY_NAME("/nick", null, "<display-name>", R.string.command_description_nick, false),
|
||||
CHANGE_DISPLAY_NAME_FOR_ROOM("/myroomnick", arrayOf("/roomnick"), "<display-name>", R.string.command_description_nick_for_room, false),
|
||||
ROOM_AVATAR("/roomavatar", null, "<mxc_url>", R.string.command_description_room_avatar, true /* Since user has to know the mxc url */),
|
||||
CHANGE_AVATAR_FOR_ROOM("/myroomavatar", null, "<mxc_url>", R.string.command_description_avatar_for_room, true /* Since user has to know the mxc url */),
|
||||
MARKDOWN("/markdown", null, "<on|off>", R.string.command_description_markdown, false),
|
||||
RAINBOW("/rainbow", null, "<message>", R.string.command_description_rainbow, false),
|
||||
RAINBOW_EMOTE("/rainbowme", null, "<message>", R.string.command_description_rainbow_emote, false),
|
||||
CLEAR_SCALAR_TOKEN("/clear_scalar_token", null, "", R.string.command_description_clear_scalar_token, false),
|
||||
SPOILER("/spoiler", null, "<message>", R.string.command_description_spoiler, false),
|
||||
SHRUG("/shrug", null, "<message>", R.string.command_description_shrug, false),
|
||||
LENNY("/lenny", null, "<message>", R.string.command_description_lenny, false),
|
||||
PLAIN("/plain", null, "<message>", R.string.command_description_plain, false),
|
||||
WHOIS("/whois", null, "<user-id>", R.string.command_description_whois, false),
|
||||
DISCARD_SESSION("/discardsession", null, "", R.string.command_description_discard_session, false),
|
||||
CONFETTI("/confetti", null, "<message>", R.string.command_confetti, false),
|
||||
SNOWFALL("/snowfall", null, "<message>", R.string.command_snow, false),
|
||||
CREATE_SPACE("/createspace", null, "<name> <invitee>*", R.string.command_description_create_space, true),
|
||||
ADD_TO_SPACE("/addToSpace", null, "spaceId", R.string.command_description_add_to_space, true),
|
||||
JOIN_SPACE("/joinSpace", null, "spaceId", R.string.command_description_join_space, true),
|
||||
LEAVE_ROOM("/leave", null, "<roomId?>", R.string.command_description_leave_room, true),
|
||||
UPGRADE_ROOM("/upgraderoom", null, "newVersion", R.string.command_description_upgrade_room, true);
|
||||
|
||||
val length
|
||||
get() = command.length + 1
|
||||
val allAliases = arrayOf(command, *aliases.orEmpty())
|
||||
|
||||
fun matches(inputCommand: CharSequence) = allAliases.any { it.contentEquals(inputCommand, true) }
|
||||
|
||||
fun startsWith(input: CharSequence) =
|
||||
allAliases.any { it.startsWith(input, 1, true) }
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@ object CommandParser {
|
|||
* @param textMessage the text message
|
||||
* @return a parsed slash command (ok or error)
|
||||
*/
|
||||
fun parseSplashCommand(textMessage: CharSequence): ParsedCommand {
|
||||
fun parseSlashCommand(textMessage: CharSequence): ParsedCommand {
|
||||
// check if it has the Slash marker
|
||||
if (!textMessage.startsWith("/")) {
|
||||
return ParsedCommand.ErrorNotACommand
|
||||
} else {
|
||||
Timber.v("parseSplashCommand")
|
||||
Timber.v("parseSlashCommand")
|
||||
|
||||
// "/" only
|
||||
if (textMessage.length == 1) {
|
||||
|
@ -52,7 +52,7 @@ object CommandParser {
|
|||
val messageParts = try {
|
||||
textMessage.split("\\s+".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## manageSplashCommand() : split failed")
|
||||
Timber.e(e, "## manageSlashCommand() : split failed")
|
||||
null
|
||||
}
|
||||
|
||||
|
@ -61,35 +61,32 @@ object CommandParser {
|
|||
return ParsedCommand.ErrorEmptySlashCommand
|
||||
}
|
||||
|
||||
return when (val slashCommand = messageParts.first()) {
|
||||
Command.PLAIN.command -> {
|
||||
val text = textMessage.substring(Command.PLAIN.command.length).trim()
|
||||
val slashCommand = messageParts.first()
|
||||
val message = textMessage.substring(slashCommand.length).trim()
|
||||
|
||||
if (text.isNotEmpty()) {
|
||||
ParsedCommand.SendPlainText(text)
|
||||
return when {
|
||||
Command.PLAIN.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.SendPlainText(message = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.PLAIN)
|
||||
}
|
||||
}
|
||||
Command.CHANGE_DISPLAY_NAME.command -> {
|
||||
val newDisplayName = textMessage.substring(Command.CHANGE_DISPLAY_NAME.command.length).trim()
|
||||
|
||||
if (newDisplayName.isNotEmpty()) {
|
||||
ParsedCommand.ChangeDisplayName(newDisplayName)
|
||||
Command.CHANGE_DISPLAY_NAME.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.ChangeDisplayName(displayName = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME)
|
||||
}
|
||||
}
|
||||
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)
|
||||
Command.CHANGE_DISPLAY_NAME_FOR_ROOM.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.ChangeDisplayNameForRoom(displayName = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.CHANGE_DISPLAY_NAME_FOR_ROOM)
|
||||
}
|
||||
}
|
||||
Command.ROOM_AVATAR.command -> {
|
||||
Command.ROOM_AVATAR.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
val url = messageParts[1]
|
||||
|
||||
|
@ -102,7 +99,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.ROOM_AVATAR)
|
||||
}
|
||||
}
|
||||
Command.CHANGE_AVATAR_FOR_ROOM.command -> {
|
||||
Command.CHANGE_AVATAR_FOR_ROOM.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
val url = messageParts[1]
|
||||
|
||||
|
@ -115,40 +112,42 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.CHANGE_AVATAR_FOR_ROOM)
|
||||
}
|
||||
}
|
||||
Command.TOPIC.command -> {
|
||||
val newTopic = textMessage.substring(Command.TOPIC.command.length).trim()
|
||||
|
||||
if (newTopic.isNotEmpty()) {
|
||||
ParsedCommand.ChangeTopic(newTopic)
|
||||
Command.TOPIC.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.ChangeTopic(topic = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.TOPIC)
|
||||
}
|
||||
}
|
||||
Command.EMOTE.command -> {
|
||||
val message = textMessage.subSequence(Command.EMOTE.command.length, textMessage.length).trim()
|
||||
|
||||
ParsedCommand.SendEmote(message)
|
||||
Command.EMOTE.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.SendEmote(message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.EMOTE)
|
||||
}
|
||||
}
|
||||
Command.RAINBOW.command -> {
|
||||
val message = textMessage.subSequence(Command.RAINBOW.command.length, textMessage.length).trim()
|
||||
|
||||
ParsedCommand.SendRainbow(message)
|
||||
Command.RAINBOW.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.SendRainbow(message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.RAINBOW)
|
||||
}
|
||||
}
|
||||
Command.RAINBOW_EMOTE.command -> {
|
||||
val message = textMessage.subSequence(Command.RAINBOW_EMOTE.command.length, textMessage.length).trim()
|
||||
|
||||
ParsedCommand.SendRainbowEmote(message)
|
||||
Command.RAINBOW_EMOTE.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.SendRainbowEmote(message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.RAINBOW_EMOTE)
|
||||
}
|
||||
}
|
||||
Command.JOIN_ROOM.command -> {
|
||||
Command.JOIN_ROOM.matches(slashCommand) -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val roomAlias = messageParts[1]
|
||||
|
||||
if (roomAlias.isNotEmpty()) {
|
||||
ParsedCommand.JoinRoom(
|
||||
roomAlias,
|
||||
textMessage.substring(Command.JOIN_ROOM.length + roomAlias.length)
|
||||
.trim()
|
||||
.takeIf { it.isNotBlank() }
|
||||
trimParts(textMessage, messageParts.take(2))
|
||||
)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
||||
|
@ -157,23 +156,21 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.JOIN_ROOM)
|
||||
}
|
||||
}
|
||||
Command.PART.command -> {
|
||||
Command.PART.matches(slashCommand) -> {
|
||||
when (messageParts.size) {
|
||||
1 -> ParsedCommand.PartRoom(null)
|
||||
2 -> ParsedCommand.PartRoom(messageParts[1])
|
||||
else -> ParsedCommand.ErrorSyntax(Command.PART)
|
||||
}
|
||||
}
|
||||
Command.ROOM_NAME.command -> {
|
||||
val newRoomName = textMessage.substring(Command.ROOM_NAME.command.length).trim()
|
||||
|
||||
if (newRoomName.isNotEmpty()) {
|
||||
ParsedCommand.ChangeRoomName(newRoomName)
|
||||
Command.ROOM_NAME.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.ChangeRoomName(name = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.ROOM_NAME)
|
||||
}
|
||||
}
|
||||
Command.INVITE.command -> {
|
||||
Command.INVITE.matches(slashCommand) -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
|
@ -181,9 +178,7 @@ object CommandParser {
|
|||
MatrixPatterns.isUserId(userId) -> {
|
||||
ParsedCommand.Invite(
|
||||
userId,
|
||||
textMessage.substring(Command.INVITE.length + userId.length)
|
||||
.trim()
|
||||
.takeIf { it.isNotBlank() }
|
||||
trimParts(textMessage, messageParts.take(2))
|
||||
)
|
||||
}
|
||||
userId.isEmail() -> {
|
||||
|
@ -200,34 +195,30 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.INVITE)
|
||||
}
|
||||
}
|
||||
Command.KICK_USER.command -> {
|
||||
Command.REMOVE_USER.matches(slashCommand) -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
if (MatrixPatterns.isUserId(userId)) {
|
||||
ParsedCommand.KickUser(
|
||||
ParsedCommand.RemoveUser(
|
||||
userId,
|
||||
textMessage.substring(Command.KICK_USER.length + userId.length)
|
||||
.trim()
|
||||
.takeIf { it.isNotBlank() }
|
||||
trimParts(textMessage, messageParts.take(2))
|
||||
)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.KICK_USER)
|
||||
ParsedCommand.ErrorSyntax(Command.REMOVE_USER)
|
||||
}
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.KICK_USER)
|
||||
ParsedCommand.ErrorSyntax(Command.REMOVE_USER)
|
||||
}
|
||||
}
|
||||
Command.BAN_USER.command -> {
|
||||
Command.BAN_USER.matches(slashCommand) -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
if (MatrixPatterns.isUserId(userId)) {
|
||||
ParsedCommand.BanUser(
|
||||
userId,
|
||||
textMessage.substring(Command.BAN_USER.length + userId.length)
|
||||
.trim()
|
||||
.takeIf { it.isNotBlank() }
|
||||
trimParts(textMessage, messageParts.take(2))
|
||||
)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.BAN_USER)
|
||||
|
@ -236,16 +227,14 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.BAN_USER)
|
||||
}
|
||||
}
|
||||
Command.UNBAN_USER.command -> {
|
||||
Command.UNBAN_USER.matches(slashCommand) -> {
|
||||
if (messageParts.size >= 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
if (MatrixPatterns.isUserId(userId)) {
|
||||
ParsedCommand.UnbanUser(
|
||||
userId,
|
||||
textMessage.substring(Command.UNBAN_USER.length + userId.length)
|
||||
.trim()
|
||||
.takeIf { it.isNotBlank() }
|
||||
trimParts(textMessage, messageParts.take(2))
|
||||
)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.UNBAN_USER)
|
||||
|
@ -254,7 +243,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.UNBAN_USER)
|
||||
}
|
||||
}
|
||||
Command.IGNORE_USER.command -> {
|
||||
Command.IGNORE_USER.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
|
@ -267,7 +256,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.IGNORE_USER)
|
||||
}
|
||||
}
|
||||
Command.UNIGNORE_USER.command -> {
|
||||
Command.UNIGNORE_USER.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
|
@ -280,7 +269,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.UNIGNORE_USER)
|
||||
}
|
||||
}
|
||||
Command.SET_USER_POWER_LEVEL.command -> {
|
||||
Command.SET_USER_POWER_LEVEL.matches(slashCommand) -> {
|
||||
if (messageParts.size == 3) {
|
||||
val userId = messageParts[1]
|
||||
if (MatrixPatterns.isUserId(userId)) {
|
||||
|
@ -300,7 +289,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL)
|
||||
}
|
||||
}
|
||||
Command.RESET_USER_POWER_LEVEL.command -> {
|
||||
Command.RESET_USER_POWER_LEVEL.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
|
@ -313,7 +302,7 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.SET_USER_POWER_LEVEL)
|
||||
}
|
||||
}
|
||||
Command.MARKDOWN.command -> {
|
||||
Command.MARKDOWN.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
when {
|
||||
"on".equals(messageParts[1], true) -> ParsedCommand.SetMarkdown(true)
|
||||
|
@ -324,31 +313,34 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.MARKDOWN)
|
||||
}
|
||||
}
|
||||
Command.CLEAR_SCALAR_TOKEN.command -> {
|
||||
Command.CLEAR_SCALAR_TOKEN.matches(slashCommand) -> {
|
||||
if (messageParts.size == 1) {
|
||||
ParsedCommand.ClearScalarToken
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.CLEAR_SCALAR_TOKEN)
|
||||
}
|
||||
}
|
||||
Command.SPOILER.command -> {
|
||||
val message = textMessage.substring(Command.SPOILER.command.length).trim()
|
||||
ParsedCommand.SendSpoiler(message)
|
||||
Command.SPOILER.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.SendSpoiler(message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.SPOILER)
|
||||
}
|
||||
}
|
||||
Command.SHRUG.command -> {
|
||||
val message = textMessage.substring(Command.SHRUG.command.length).trim()
|
||||
|
||||
Command.SHRUG.matches(slashCommand) -> {
|
||||
ParsedCommand.SendShrug(message)
|
||||
}
|
||||
Command.LENNY.command -> {
|
||||
val message = textMessage.substring(Command.LENNY.command.length).trim()
|
||||
|
||||
Command.LENNY.matches(slashCommand) -> {
|
||||
ParsedCommand.SendLenny(message)
|
||||
}
|
||||
Command.DISCARD_SESSION.command -> {
|
||||
ParsedCommand.DiscardSession
|
||||
Command.DISCARD_SESSION.matches(slashCommand) -> {
|
||||
if (messageParts.size == 1) {
|
||||
ParsedCommand.DiscardSession
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.DISCARD_SESSION)
|
||||
}
|
||||
}
|
||||
Command.WHOIS.command -> {
|
||||
Command.WHOIS.matches(slashCommand) -> {
|
||||
if (messageParts.size == 2) {
|
||||
val userId = messageParts[1]
|
||||
|
||||
|
@ -361,57 +353,57 @@ object CommandParser {
|
|||
ParsedCommand.ErrorSyntax(Command.WHOIS)
|
||||
}
|
||||
}
|
||||
Command.CONFETTI.command -> {
|
||||
val message = textMessage.substring(Command.CONFETTI.command.length).trim()
|
||||
Command.CONFETTI.matches(slashCommand) -> {
|
||||
ParsedCommand.SendChatEffect(ChatEffect.CONFETTI, message)
|
||||
}
|
||||
Command.SNOWFALL.command -> {
|
||||
val message = textMessage.substring(Command.SNOWFALL.command.length).trim()
|
||||
Command.SNOWFALL.matches(slashCommand) -> {
|
||||
ParsedCommand.SendChatEffect(ChatEffect.SNOWFALL, message)
|
||||
}
|
||||
Command.CREATE_SPACE.command -> {
|
||||
val rawCommand = textMessage.substring(Command.CREATE_SPACE.command.length).trim()
|
||||
val split = rawCommand.split(" ").map { it.trim() }
|
||||
if (split.isEmpty()) {
|
||||
ParsedCommand.ErrorSyntax(Command.CREATE_SPACE)
|
||||
} else {
|
||||
Command.CREATE_SPACE.matches(slashCommand) -> {
|
||||
if (messageParts.size >= 2) {
|
||||
ParsedCommand.CreateSpace(
|
||||
split[0],
|
||||
split.subList(1, split.size)
|
||||
messageParts[1],
|
||||
messageParts.drop(2)
|
||||
)
|
||||
}
|
||||
}
|
||||
Command.ADD_TO_SPACE.command -> {
|
||||
val rawCommand = textMessage.substring(Command.ADD_TO_SPACE.command.length).trim()
|
||||
ParsedCommand.AddToSpace(
|
||||
rawCommand
|
||||
)
|
||||
}
|
||||
Command.JOIN_SPACE.command -> {
|
||||
val spaceIdOrAlias = textMessage.substring(Command.JOIN_SPACE.command.length).trim()
|
||||
ParsedCommand.JoinSpace(
|
||||
spaceIdOrAlias
|
||||
)
|
||||
}
|
||||
Command.LEAVE_ROOM.command -> {
|
||||
val spaceIdOrAlias = textMessage.substring(Command.LEAVE_ROOM.command.length).trim()
|
||||
ParsedCommand.LeaveRoom(
|
||||
spaceIdOrAlias
|
||||
)
|
||||
}
|
||||
Command.UPGRADE_ROOM.command -> {
|
||||
val newVersion = textMessage.substring(Command.UPGRADE_ROOM.command.length).trim()
|
||||
if (newVersion.isEmpty()) {
|
||||
ParsedCommand.ErrorSyntax(Command.UPGRADE_ROOM)
|
||||
} else {
|
||||
ParsedCommand.UpgradeRoom(newVersion)
|
||||
ParsedCommand.ErrorSyntax(Command.CREATE_SPACE)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Command.ADD_TO_SPACE.matches(slashCommand) -> {
|
||||
if (messageParts.size == 1) {
|
||||
ParsedCommand.AddToSpace(spaceId = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.ADD_TO_SPACE)
|
||||
}
|
||||
}
|
||||
Command.JOIN_SPACE.matches(slashCommand) -> {
|
||||
if (messageParts.size == 1) {
|
||||
ParsedCommand.JoinSpace(spaceIdOrAlias = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.JOIN_SPACE)
|
||||
}
|
||||
}
|
||||
Command.LEAVE_ROOM.matches(slashCommand) -> {
|
||||
ParsedCommand.LeaveRoom(roomId = message)
|
||||
}
|
||||
Command.UPGRADE_ROOM.matches(slashCommand) -> {
|
||||
if (message.isNotEmpty()) {
|
||||
ParsedCommand.UpgradeRoom(newVersion = message)
|
||||
} else {
|
||||
ParsedCommand.ErrorSyntax(Command.UPGRADE_ROOM)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// Unknown command
|
||||
ParsedCommand.ErrorUnknownSlashCommand(slashCommand)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun trimParts(message: CharSequence, messageParts: List<String>): String? {
|
||||
val partsSize = messageParts.sumOf { it.length }
|
||||
val gapsNumber = messageParts.size - 1
|
||||
return message.substring(partsSize + gapsNumber).trim().takeIf { it.isNotEmpty() }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ sealed class ParsedCommand {
|
|||
class JoinRoom(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 RemoveUser(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()
|
||||
|
|
|
@ -2113,7 +2113,7 @@ class RoomDetailFragment @Inject constructor(
|
|||
userId == session.myUserId) {
|
||||
// Empty composer, current user: start an emote
|
||||
views.composerLayout.views.composerEditText.setText(Command.EMOTE.command + " ")
|
||||
views.composerLayout.views.composerEditText.setSelection(Command.EMOTE.length)
|
||||
views.composerLayout.views.composerEditText.setSelection(Command.EMOTE.command.length + 1)
|
||||
} else {
|
||||
val roomMember = roomDetailViewModel.getMember(userId)
|
||||
// TODO move logic outside of fragment
|
||||
|
|
|
@ -183,7 +183,7 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
withState { state ->
|
||||
when (state.sendMode) {
|
||||
is SendMode.Regular -> {
|
||||
when (val slashCommandResult = CommandParser.parseSplashCommand(action.text)) {
|
||||
when (val slashCommandResult = CommandParser.parseSlashCommand(action.text)) {
|
||||
is ParsedCommand.ErrorNotACommand -> {
|
||||
// Send the text message to the room
|
||||
room.sendTextMessage(action.text, autoMarkdown = action.autoMarkdown)
|
||||
|
@ -239,8 +239,8 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
is ParsedCommand.UnignoreUser -> {
|
||||
handleUnignoreSlashCommand(slashCommandResult)
|
||||
}
|
||||
is ParsedCommand.KickUser -> {
|
||||
handleKickSlashCommand(slashCommandResult)
|
||||
is ParsedCommand.RemoveUser -> {
|
||||
handleRemoveSlashCommand(slashCommandResult)
|
||||
}
|
||||
is ParsedCommand.JoinRoom -> {
|
||||
handleJoinToAnotherRoomSlashCommand(slashCommandResult)
|
||||
|
@ -598,9 +598,9 @@ class MessageComposerViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleKickSlashCommand(kick: ParsedCommand.KickUser) {
|
||||
private fun handleRemoveSlashCommand(removeUser: ParsedCommand.RemoveUser) {
|
||||
launchSlashCommandFlowSuspendable {
|
||||
room.kick(kick.userId, kick.reason)
|
||||
room.remove(removeUser.userId, removeUser.reason)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
|
|||
viewModelScope.launch {
|
||||
try {
|
||||
_viewEvents.post(RoomMemberProfileViewEvents.Loading())
|
||||
room.kick(initialState.userId, action.reason)
|
||||
room.remove(initialState.userId, action.reason)
|
||||
_viewEvents.post(RoomMemberProfileViewEvents.OnKickActionSuccess)
|
||||
} catch (failure: Throwable) {
|
||||
_viewEvents.post(RoomMemberProfileViewEvents.Failure(failure))
|
||||
|
|
|
@ -25,8 +25,9 @@
|
|||
<string name="notice_direct_room_leave_by_you">You left the room</string>
|
||||
<string name="notice_room_reject">%1$s rejected the invitation</string>
|
||||
<string name="notice_room_reject_by_you">You rejected the invitation</string>
|
||||
<string name="notice_room_kick">%1$s kicked %2$s</string>
|
||||
<string name="notice_room_kick_by_you">You kicked %1$s</string>
|
||||
<!-- TODO: replace "kick" with "remove" in string resources keys -->
|
||||
<string name="notice_room_kick">%1$s removed %2$s</string>
|
||||
<string name="notice_room_kick_by_you">You removed %1$s</string>
|
||||
<string name="notice_room_unban">%1$s unbanned %2$s</string>
|
||||
<string name="notice_room_unban_by_you">You unbanned %1$s</string>
|
||||
<string name="notice_room_ban">%1$s banned %2$s</string>
|
||||
|
@ -229,8 +230,8 @@
|
|||
<string name="notice_direct_room_leave_with_reason_by_you">You left. Reason: %1$s</string>
|
||||
<string name="notice_room_reject_with_reason">%1$s rejected the invitation. Reason: %2$s</string>
|
||||
<string name="notice_room_reject_with_reason_by_you">You rejected the invitation. Reason: %1$s</string>
|
||||
<string name="notice_room_kick_with_reason">%1$s kicked %2$s. Reason: %3$s</string>
|
||||
<string name="notice_room_kick_with_reason_by_you">You kicked %1$s. Reason: %2$s</string>
|
||||
<string name="notice_room_kick_with_reason">%1$s removed %2$s. Reason: %3$s</string>
|
||||
<string name="notice_room_kick_with_reason_by_you">You removed %1$s. Reason: %2$s</string>
|
||||
<string name="notice_room_unban_with_reason">%1$s unbanned %2$s. Reason: %3$s</string>
|
||||
<string name="notice_room_unban_with_reason_by_you">You unbanned %1$s. Reason: %2$s</string>
|
||||
<string name="notice_room_ban_with_reason">%1$s banned %2$s. Reason: %3$s</string>
|
||||
|
@ -884,7 +885,7 @@
|
|||
<string name="room_participants_action_remove">Remove from this room</string>
|
||||
<string name="room_participants_action_ban">Ban</string>
|
||||
<string name="room_participants_action_unban">Unban</string>
|
||||
<string name="room_participants_action_kick">Kick</string>
|
||||
<string name="room_participants_action_kick">Remove from chat</string>
|
||||
<string name="room_participants_action_set_default_power_level">Reset to normal user</string>
|
||||
<string name="room_participants_action_set_moderator">Make moderator</string>
|
||||
<string name="room_participants_action_set_admin">Make admin</string>
|
||||
|
@ -908,15 +909,15 @@
|
|||
|
||||
<string name="room_participants_action_cancel_invite_title">Cancel invite</string>
|
||||
<string name="room_participants_action_cancel_invite_prompt_msg">Are you sure you want to cancel the invite for this user?</string>
|
||||
<string name="room_participants_kick_title">Kick user</string>
|
||||
<string name="room_participants_kick_reason">Reason to kick</string>
|
||||
<string name="room_participants_kick_prompt_msg">kicking user will remove them from this room.\n\nTo prevent them from joining again, you should ban them instead.</string>
|
||||
<string name="space_participants_kick_prompt_msg">kicking user will remove them from this space.\n\nTo prevent them from joining again, you should ban them instead.</string>
|
||||
<string name="room_participants_kick_title">Remove user</string>
|
||||
<string name="room_participants_kick_reason">Reason to remove</string>
|
||||
<string name="room_participants_kick_prompt_msg">The user will be removed from this room.\n\nTo prevent them from joining again, you should ban them instead.</string>
|
||||
<string name="space_participants_kick_prompt_msg">The user will be removed from this space.\n\nTo prevent them from joining again, you should ban them instead.</string>
|
||||
<string name="room_participants_ban_title">Ban user</string>
|
||||
<string name="room_participants_ban_reason">Reason to ban</string>
|
||||
<string name="room_participants_unban_title">Unban user</string>
|
||||
<string name="room_participants_ban_prompt_msg">Banning user will kick them from this room and prevent them from joining again.</string>
|
||||
<string name="space_participants_ban_prompt_msg">Banning user will kick them from this space and prevent them from joining again.</string>
|
||||
<string name="room_participants_ban_prompt_msg">Banning user will remove them from this room and prevent them from joining again.</string>
|
||||
<string name="space_participants_ban_prompt_msg">Banning user will remove them from this space and prevent them from joining again.</string>
|
||||
<string name="room_participants_unban_prompt_msg">Unbanning user will allow them to join the room again.</string>
|
||||
<string name="space_participants_unban_prompt_msg">Unbanning user will allow them to join the space again.</string>
|
||||
|
||||
|
@ -998,7 +999,7 @@
|
|||
<string name="room_permissions_send_messages">Send messages</string>
|
||||
<string name="room_permissions_invite_users">Invite users</string>
|
||||
<string name="room_permissions_change_settings">Change settings</string>
|
||||
<string name="room_permissions_kick_users">Kick users</string>
|
||||
<string name="room_permissions_kick_users">Remove users</string>
|
||||
<string name="room_permissions_ban_users">Ban users</string>
|
||||
<string name="room_permissions_remove_messages_sent_by_others">Remove messages sent by others</string>
|
||||
<string name="room_permissions_notify_everyone">Notify everyone</string>
|
||||
|
@ -1325,9 +1326,9 @@
|
|||
<string name="settings_show_room_member_state_events">Show room member state events</string>
|
||||
<string name="settings_chat_effects_title">Show chat effects</string>
|
||||
<string name="settings_chat_effects_description">Use /confetti command or send a message containing ❄️ or 🎉</string>
|
||||
<string name="settings_show_room_member_state_events_summary">Includes invite/join/left/kick/ban events and avatar/display name changes.</string>
|
||||
<string name="settings_show_room_member_state_events_summary">Includes invite/join/left/remove/ban events and avatar/display name changes.</string>
|
||||
<string name="settings_show_join_leave_messages">Show join and leave events</string>
|
||||
<string name="settings_show_join_leave_messages_summary">Invites, kicks, and bans are unaffected.</string>
|
||||
<string name="settings_show_join_leave_messages_summary">Invites, removes, and bans are unaffected.</string>
|
||||
<string name="settings_show_avatar_display_name_changes_messages">Show account events</string>
|
||||
<string name="settings_show_avatar_display_name_changes_messages_summary">Includes avatar and display name changes.</string>
|
||||
<string name="settings_vibrate_on_mention">Vibrate when mentioning a user</string>
|
||||
|
@ -1855,7 +1856,7 @@
|
|||
<string name="command_description_join_room">Joins room with given address</string>
|
||||
<string name="command_description_part_room">Leave room</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">Removes user with given id from this room</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>
|
||||
|
@ -1905,7 +1906,7 @@
|
|||
</plurals>
|
||||
<string name="group_no_long_description">The community admin has not provided a long description for this community.</string>
|
||||
|
||||
<string name="has_been_kicked">You have been kicked from %1$s by %2$s</string>
|
||||
<string name="has_been_kicked">You have been removed from %1$s by %2$s</string>
|
||||
<string name="has_been_banned">You have been banned from %1$s by %2$s</string>
|
||||
<string name="reason_colon">Reason: %1$s</string>
|
||||
<string name="rejoin">Rejoin</string>
|
||||
|
|
Loading…
Reference in New Issue