hide dev commands from completion

This commit is contained in:
Valere 2021-02-16 10:02:33 +01:00
parent c8916ee83c
commit 2cc5c76fb3
3 changed files with 43 additions and 36 deletions

View File

@ -21,10 +21,12 @@ import androidx.recyclerview.widget.RecyclerView
import im.vector.app.features.autocomplete.AutocompleteClickListener import im.vector.app.features.autocomplete.AutocompleteClickListener
import im.vector.app.features.autocomplete.RecyclerViewPresenter import im.vector.app.features.autocomplete.RecyclerViewPresenter
import im.vector.app.features.command.Command import im.vector.app.features.command.Command
import im.vector.app.features.settings.VectorPreferences
import javax.inject.Inject import javax.inject.Inject
class AutocompleteCommandPresenter @Inject constructor(context: Context, class AutocompleteCommandPresenter @Inject constructor(context: Context,
private val controller: AutocompleteCommandController) : private val controller: AutocompleteCommandController,
private val vectorPreferences: VectorPreferences) :
RecyclerViewPresenter<Command>(context), AutocompleteClickListener<Command> { RecyclerViewPresenter<Command>(context), AutocompleteClickListener<Command> {
init { init {
@ -40,13 +42,18 @@ class AutocompleteCommandPresenter @Inject constructor(context: Context,
} }
override fun onQuery(query: CharSequence?) { override fun onQuery(query: CharSequence?) {
val data = Command.values().filter { val data = Command.values()
if (query.isNullOrEmpty()) { .filter {
true if (it.isDevCommand && !vectorPreferences.developerMode()) {
} else { return@filter false
it.command.startsWith(query, 1, true) }
}
} if (query.isNullOrEmpty()) {
true
} else {
it.command.startsWith(query, 1, true)
}
}
controller.setData(data) controller.setData(data)
} }

View File

@ -24,33 +24,33 @@ import im.vector.app.R
* the user can write theses messages to perform some actions * the user can write theses messages to perform some actions
* the list will be displayed in this order * the list will be displayed in this order
*/ */
enum class Command(val command: String, val parameters: String, @StringRes val description: Int) { enum class Command(val command: String, val parameters: String, @StringRes val description: Int, val isDevCommand: Boolean) {
EMOTE("/me", "<message>", R.string.command_description_emote), EMOTE("/me", "<message>", R.string.command_description_emote, false),
BAN_USER("/ban", "<user-id> [reason]", R.string.command_description_ban_user), 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), UNBAN_USER("/unban", "<user-id> [reason]", R.string.command_description_unban_user, false),
SET_USER_POWER_LEVEL("/op", "<user-id> [<power-level>]", R.string.command_description_op_user), 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), RESET_USER_POWER_LEVEL("/deop", "<user-id>", R.string.command_description_deop_user, false),
INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user), INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user, false),
JOIN_ROOM("/join", "<room-alias> [reason]", R.string.command_description_join_room), JOIN_ROOM("/join", "<room-alias> [reason]", R.string.command_description_join_room, false),
PART("/part", "<room-alias> [reason]", R.string.command_description_part_room), PART("/part", "<room-alias> [reason]", R.string.command_description_part_room, false),
TOPIC("/topic", "<topic>", R.string.command_description_topic), TOPIC("/topic", "<topic>", R.string.command_description_topic, false),
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user), KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user, false),
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick), CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick, false),
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown), MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown, false),
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow), RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow, false),
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote), RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote, false),
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token), CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token, false),
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler), SPOILER("/spoiler", "<message>", R.string.command_description_spoiler, false),
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll), POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll, false),
SHRUG("/shrug", "<message>", R.string.command_description_shrug), SHRUG("/shrug", "<message>", R.string.command_description_shrug, false),
PLAIN("/plain", "<message>", R.string.command_description_plain), PLAIN("/plain", "<message>", R.string.command_description_plain, false),
DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session), DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session, false),
CONFETTI("/confetti", "<message>", R.string.command_confetti), CONFETTI("/confetti", "<message>", R.string.command_confetti, false),
SNOW("/snow", "<message>", R.string.command_snow), SNOW("/snow", "<message>", R.string.command_snow, false),
CREATE_SPACE("/createspace", "<name> <invitee>*", R.string.command_description_create_space), CREATE_SPACE("/createspace", "<name> <invitee>*", R.string.command_description_create_space, true),
ADD_TO_SPACE("/addToSpace", "spaceId", R.string.command_description_create_space), ADD_TO_SPACE("/addToSpace", "spaceId", R.string.command_description_create_space, true),
JOIN_SPACE("/joinSpace", "spaceId", R.string.command_description_join_space), JOIN_SPACE("/joinSpace", "spaceId", R.string.command_description_join_space, true),
LEAVE_ROOM("/leave", "<roomId?>", R.string.command_description_leave_room); LEAVE_ROOM("/leave", "<roomId?>", R.string.command_description_leave_room, true);
val length val length
get() = command.length + 1 get() = command.length + 1

View File

@ -3248,7 +3248,7 @@
<string name="dev_tools_event_content_hint">Event content</string> <string name="dev_tools_event_content_hint">Event content</string>
<string name="command_description_create_space">Create a community</string> <string name="command_description_create_space">Create a community</string>
<string name="command_description_create_space">Create a Spcae</string> <string name="command_description_create_space">Create a Space</string>
<string name="command_description_join_space">Join the Space with the given id</string> <string name="command_description_join_space">Join the Space with the given id</string>
<string name="command_description_leave_room">Leave room with given id (or current room if null)</string> <string name="command_description_leave_room">Leave room with given id (or current room if null)</string>