From 2cc5c76fb38a3a1e50d18c9096bed981952f4334 Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 16 Feb 2021 10:02:33 +0100 Subject: [PATCH] hide dev commands from completion --- .../command/AutocompleteCommandPresenter.kt | 23 +++++--- .../im/vector/app/features/command/Command.kt | 54 +++++++++---------- vector/src/main/res/values/strings.xml | 2 +- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt b/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt index d121c68557..aabf15aebe 100644 --- a/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt +++ b/vector/src/main/java/im/vector/app/features/autocomplete/command/AutocompleteCommandPresenter.kt @@ -21,10 +21,12 @@ import androidx.recyclerview.widget.RecyclerView import im.vector.app.features.autocomplete.AutocompleteClickListener import im.vector.app.features.autocomplete.RecyclerViewPresenter import im.vector.app.features.command.Command +import im.vector.app.features.settings.VectorPreferences import javax.inject.Inject class AutocompleteCommandPresenter @Inject constructor(context: Context, - private val controller: AutocompleteCommandController) : + private val controller: AutocompleteCommandController, + private val vectorPreferences: VectorPreferences) : RecyclerViewPresenter(context), AutocompleteClickListener { init { @@ -40,13 +42,18 @@ class AutocompleteCommandPresenter @Inject constructor(context: Context, } override fun onQuery(query: CharSequence?) { - val data = Command.values().filter { - if (query.isNullOrEmpty()) { - true - } else { - it.command.startsWith(query, 1, true) - } - } + val data = Command.values() + .filter { + if (it.isDevCommand && !vectorPreferences.developerMode()) { + return@filter false + } + + if (query.isNullOrEmpty()) { + true + } else { + it.command.startsWith(query, 1, true) + } + } controller.setData(data) } diff --git a/vector/src/main/java/im/vector/app/features/command/Command.kt b/vector/src/main/java/im/vector/app/features/command/Command.kt index 2b78627d88..0b210cf298 100644 --- a/vector/src/main/java/im/vector/app/features/command/Command.kt +++ b/vector/src/main/java/im/vector/app/features/command/Command.kt @@ -24,33 +24,33 @@ 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) { - EMOTE("/me", "", R.string.command_description_emote), - BAN_USER("/ban", " [reason]", R.string.command_description_ban_user), - UNBAN_USER("/unban", " [reason]", R.string.command_description_unban_user), - SET_USER_POWER_LEVEL("/op", " []", R.string.command_description_op_user), - RESET_USER_POWER_LEVEL("/deop", "", R.string.command_description_deop_user), - INVITE("/invite", " [reason]", R.string.command_description_invite_user), - JOIN_ROOM("/join", " [reason]", R.string.command_description_join_room), - PART("/part", " [reason]", R.string.command_description_part_room), - TOPIC("/topic", "", R.string.command_description_topic), - KICK_USER("/kick", " [reason]", R.string.command_description_kick_user), - CHANGE_DISPLAY_NAME("/nick", "", R.string.command_description_nick), - MARKDOWN("/markdown", "", R.string.command_description_markdown), - RAINBOW("/rainbow", "", R.string.command_description_rainbow), - RAINBOW_EMOTE("/rainbowme", "", R.string.command_description_rainbow_emote), - CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token), - SPOILER("/spoiler", "", R.string.command_description_spoiler), - POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll), - SHRUG("/shrug", "", R.string.command_description_shrug), - PLAIN("/plain", "", R.string.command_description_plain), - DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session), - CONFETTI("/confetti", "", R.string.command_confetti), - SNOW("/snow", "", R.string.command_snow), - CREATE_SPACE("/createspace", " *", R.string.command_description_create_space), - ADD_TO_SPACE("/addToSpace", "spaceId", R.string.command_description_create_space), - JOIN_SPACE("/joinSpace", "spaceId", R.string.command_description_join_space), - LEAVE_ROOM("/leave", "", R.string.command_description_leave_room); +enum class Command(val command: String, val parameters: String, @StringRes val description: Int, val isDevCommand: Boolean) { + EMOTE("/me", "", R.string.command_description_emote, false), + BAN_USER("/ban", " [reason]", R.string.command_description_ban_user, false), + UNBAN_USER("/unban", " [reason]", R.string.command_description_unban_user, false), + SET_USER_POWER_LEVEL("/op", " []", R.string.command_description_op_user, false), + RESET_USER_POWER_LEVEL("/deop", "", R.string.command_description_deop_user, false), + INVITE("/invite", " [reason]", R.string.command_description_invite_user, false), + JOIN_ROOM("/join", " [reason]", R.string.command_description_join_room, false), + PART("/part", " [reason]", R.string.command_description_part_room, false), + TOPIC("/topic", "", R.string.command_description_topic, false), + KICK_USER("/kick", " [reason]", R.string.command_description_kick_user, false), + CHANGE_DISPLAY_NAME("/nick", "", R.string.command_description_nick, false), + MARKDOWN("/markdown", "", R.string.command_description_markdown, false), + RAINBOW("/rainbow", "", R.string.command_description_rainbow, false), + RAINBOW_EMOTE("/rainbowme", "", R.string.command_description_rainbow_emote, false), + CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token, false), + SPOILER("/spoiler", "", R.string.command_description_spoiler, false), + POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll, false), + SHRUG("/shrug", "", R.string.command_description_shrug, false), + PLAIN("/plain", "", R.string.command_description_plain, false), + DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session, false), + CONFETTI("/confetti", "", R.string.command_confetti, false), + SNOW("/snow", "", R.string.command_snow, false), + CREATE_SPACE("/createspace", " *", R.string.command_description_create_space, true), + ADD_TO_SPACE("/addToSpace", "spaceId", R.string.command_description_create_space, true), + JOIN_SPACE("/joinSpace", "spaceId", R.string.command_description_join_space, true), + LEAVE_ROOM("/leave", "", R.string.command_description_leave_room, true); val length get() = command.length + 1 diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 37e6c3bbcc..84b2262510 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -3248,7 +3248,7 @@ Event content Create a community - Create a Spcae + Create a Space Join the Space with the given id Leave room with given id (or current room if null)