Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
3.9 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

const KEYBIND_COMMAND_VALUES = [
	'message_edit',
	'message_edit_prev',
	'message_edit_next',
	'message_delete',
	'message_pin',
	'message_react',
	'message_reply',
	'message_reply_prev',
	'message_reply_next',
	'message_forward',
	'message_speak',
	'message_copy_text',
	'message_mark_unread',
	'message_focus_textarea',
	'nav_guild_prev',
	'nav_guild_next',
	'nav_channel_prev',
	'nav_channel_next',
	'nav_history_back',
	'nav_history_forward',
	'nav_unread_prev',
	'nav_unread_next',
	'nav_mention_prev',
	'nav_mention_next',
	'nav_current_call',
	'nav_toggle_last_guild_dms',
	'nav_guild_tab_prev',
	'nav_guild_tab_next',
	'nav_guild_slot_1',
	'nav_guild_slot_2',
	'nav_guild_slot_3',
	'nav_guild_slot_4',
	'nav_guild_slot_5',
	'nav_guild_slot_6',
	'nav_guild_slot_7',
	'nav_guild_slot_8',
	'nav_guild_slot_9',
	'nav_quick_switcher',
	'nav_add_guild',
	'dnd_start',
	'dnd_move_up',
	'dnd_move_down',
	'dnd_drop',
	'dnd_cancel',
	'chat_mark_guild_read',
	'chat_mark_channel_read',
	'chat_new_dm',
	'chat_toggle_pins',
	'chat_toggle_inbox',
	'chat_mark_inbox_read',
	'chat_mark_all_inbox_read',
	'chat_toggle_member_list',
	'chat_toggle_emoji',
	'chat_toggle_gif',
	'chat_toggle_sticker',
	'chat_scroll_up',
	'chat_scroll_down',
	'chat_jump_oldest_unread',
	'chat_focus_textarea',
	'chat_upload',
	'chat_copy_channel_link',
	'voice_toggle_mute',
	'voice_toggle_deafen',
	'voice_answer_call',
	'voice_decline_call',
	'voice_start_dm_call',
	'voice_toggle_soundboard',
	'voice_toggle_compact_call_view',
	'misc_help',
	'misc_search',
	'misc_open_context_menu',
	'message_bookmark',
	'message_toggle_embeds',
	'message_copy_link',
	'message_copy_id',
	'chat_toggle_saved_media',
	'chat_send_voice_message',
	'voice_push_to_talk',
	'voice_push_to_talk_priority',
	'voice_push_to_mute',
	'voice_priority_vad',
	'voice_toggle_vad',
	'voice_toggle_camera',
	'voice_switch_channel',
	'voice_disconnect',
	'system_toggle_settings',
	'system_toggle_shortcuts_overlay',
	'system_open_theme_studio_popout',
	'system_toggle_custom_css',
	'system_zoom_in',
	'system_zoom_out',
	'system_zoom_reset',
	'system_open_account_switcher',
	'system_switch_account_next',
	'system_switch_account_prev',
	'system_switch_account_recent',
	'system_jump_account_mention',
	'nav_quick_switcher_accounts',
	'system_switch_account_slot_1',
	'system_switch_account_slot_2',
	'system_switch_account_slot_3',
	'system_switch_account_slot_4',
	'system_switch_account_slot_5',
	'system_switch_account_slot_6',
	'system_switch_account_slot_7',
	'system_switch_account_slot_8',
	'system_switch_account_slot_9',
] as const;

export type KeybindCommand = (typeof KEYBIND_COMMAND_VALUES)[number];

export const ACCOUNT_SWITCHER_SLOT_ACTIONS: ReadonlyArray<KeybindCommand> = Object.freeze([
	'system_switch_account_slot_1',
	'system_switch_account_slot_2',
	'system_switch_account_slot_3',
	'system_switch_account_slot_4',
	'system_switch_account_slot_5',
	'system_switch_account_slot_6',
	'system_switch_account_slot_7',
	'system_switch_account_slot_8',
	'system_switch_account_slot_9',
]);

const ACCOUNT_KEYBIND_ACTIONS: ReadonlyArray<KeybindCommand> = Object.freeze([
	'system_open_account_switcher',
	'system_switch_account_next',
	'system_switch_account_prev',
	'system_switch_account_recent',
	'system_jump_account_mention',
	'nav_quick_switcher_accounts',
	...ACCOUNT_SWITCHER_SLOT_ACTIONS,
]);

const ACCOUNT_KEYBIND_ACTION_SET = new Set<string>(ACCOUNT_KEYBIND_ACTIONS);
export const isAccountKeybindCommand = (value: unknown): value is KeybindCommand =>
	typeof value === 'string' && ACCOUNT_KEYBIND_ACTION_SET.has(value);

const KEYBIND_COMMAND_SET = new Set<string>(KEYBIND_COMMAND_VALUES);
export const isKeybindCommand = (value: unknown): value is KeybindCommand =>
	typeof value === 'string' && KEYBIND_COMMAND_SET.has(value);

export function resolveKeybindCommand(action: string | null): KeybindCommand | null {
	if (isKeybindCommand(action)) {
		return action;
	}
	return null;
}