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.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<Command>(context), AutocompleteClickListener<Command> {
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)
}

View File

@ -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", "<message>", R.string.command_description_emote),
BAN_USER("/ban", "<user-id> [reason]", R.string.command_description_ban_user),
UNBAN_USER("/unban", "<user-id> [reason]", R.string.command_description_unban_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),
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),
TOPIC("/topic", "<topic>", R.string.command_description_topic),
KICK_USER("/kick", "<user-id> [reason]", R.string.command_description_kick_user),
CHANGE_DISPLAY_NAME("/nick", "<display-name>", R.string.command_description_nick),
MARKDOWN("/markdown", "<on|off>", R.string.command_description_markdown),
RAINBOW("/rainbow", "<message>", R.string.command_description_rainbow),
RAINBOW_EMOTE("/rainbowme", "<message>", R.string.command_description_rainbow_emote),
CLEAR_SCALAR_TOKEN("/clear_scalar_token", "", R.string.command_description_clear_scalar_token),
SPOILER("/spoiler", "<message>", R.string.command_description_spoiler),
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll),
SHRUG("/shrug", "<message>", R.string.command_description_shrug),
PLAIN("/plain", "<message>", R.string.command_description_plain),
DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session),
CONFETTI("/confetti", "<message>", R.string.command_confetti),
SNOW("/snow", "<message>", R.string.command_snow),
CREATE_SPACE("/createspace", "<name> <invitee>*", 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", "<roomId?>", R.string.command_description_leave_room);
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),
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),
INVITE("/invite", "<user-id> [reason]", R.string.command_description_invite_user, false),
JOIN_ROOM("/join", "<room-alias> [reason]", R.string.command_description_join_room, false),
PART("/part", "<room-alias> [reason]", 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),
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),
POLL("/poll", "Question | Option 1 | Option 2 ...", R.string.command_description_poll, false),
SHRUG("/shrug", "<message>", R.string.command_description_shrug, false),
PLAIN("/plain", "<message>", R.string.command_description_plain, false),
DISCARD_SESSION("/discardsession", "", R.string.command_description_discard_session, false),
CONFETTI("/confetti", "<message>", R.string.command_confetti, false),
SNOW("/snow", "<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_create_space, true),
JOIN_SPACE("/joinSpace", "spaceId", R.string.command_description_join_space, true),
LEAVE_ROOM("/leave", "<roomId?>", R.string.command_description_leave_room, true);
val length
get() = command.length + 1

View File

@ -3248,7 +3248,7 @@
<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 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_leave_room">Leave room with given id (or current room if null)</string>