Add files

This commit is contained in:
DoomRye 2022-07-26 10:06:20 -07:00
commit bb80829159
18195 changed files with 2122994 additions and 0 deletions

View file

@ -0,0 +1,36 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const CALL_ACCEPT = {
binds: ['mod+return'],
global: true,
action() {
if (ComponentDispatch.hasSubscribers(ComponentActions.CALL_ACCEPT)) {
ComponentDispatch.dispatch(ComponentActions.CALL_ACCEPT);
return false;
}
},
};
export const CALL_START = {
binds: [`ctrl+'`, `ctrl+shift+'`],
global: true,
action(event: KeyboardEvent) {
if (ComponentDispatch.hasSubscribers(ComponentActions.CALL_START)) {
ComponentDispatch.dispatch(ComponentActions.CALL_START, event);
return false;
}
},
};
export default {
CALL_ACCEPT,
CALL_START,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/calls.js

View file

@ -0,0 +1,74 @@
/* @flow */
import DelayedSelectionActionCreators from '../../actions/DelayedSelectionActionCreators';
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import SelectedGuildStore from '../../stores/SelectedGuildStore';
import navigateToChannel from '../helpers/navigateToChannel';
import transitionTo from '../helpers/transitionTo';
import RouterUtils from '../../utils/RouterUtils';
import {ME, Routes} from '../../Constants';
export const CHANNEL_NEXT = {
binds: [
'alt+down', // slack way
],
global: true,
action() {
navigateToChannel();
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export const CHANNEL_PREV = {
binds: [
'alt+up', // slack way
],
global: true,
action() {
navigateToChannel(-1);
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export const TOGGLE_PREVIOUS_GUILD = {
binds: ['mod+alt+right'],
global: true,
action() {
const hasGuildSelected = SelectedGuildStore.getGuildId();
let targetGuild;
if (hasGuildSelected) {
targetGuild = ME;
} else {
const lastSelectedGuildId = SelectedGuildStore.getLastSelectedGuildId();
if (lastSelectedGuildId) {
targetGuild = lastSelectedGuildId;
transitionTo(lastSelectedGuildId, SelectedChannelStore.getChannelId(lastSelectedGuildId));
}
}
if (targetGuild != null) {
const targetChannel = SelectedChannelStore.getChannelId(targetGuild);
RouterUtils.transitionTo(targetChannel ? Routes.CHANNEL(targetGuild, targetChannel) : Routes.GUILD(targetGuild));
}
return false;
},
};
export default {
CHANNEL_PREV,
CHANNEL_NEXT,
TOGGLE_PREVIOUS_GUILD,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/channelNav.js

View file

@ -0,0 +1,30 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import SelectedGuildStore from '../../stores/SelectedGuildStore';
import DelayedSelectionActionCreators from '../../actions/DelayedSelectionActionCreators';
import transitionTo from '../helpers/transitionTo';
import {ME, ComponentActions} from '../../Constants';
export const CREATE_DM_GROUP = {
binds: ['mod+shift+t'],
global: true,
action() {
// Only transition if we need too
if (SelectedGuildStore.getGuildId()) {
transitionTo(ME);
DelayedSelectionActionCreators.flushSelection(true);
}
ComponentDispatch.safeDispatch(ComponentActions.TOGGLE_DM_CREATE);
return false;
},
};
export default {
CREATE_DM_GROUP,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/createDMGroup.js

View file

@ -0,0 +1,26 @@
/* @flow */
import CreateGuildModalActionCreators from '../../actions/CreateGuildModalActionCreators';
import CreateGuildModalStore from '../../stores/CreateGuildModalStore';
import {CreateGuildModalScreens} from '../../Constants';
export const CREATE_GUILD = {
binds: ['mod+shift+n'],
global: true,
action() {
if (CreateGuildModalStore.isOpen()) {
CreateGuildModalActionCreators.setScreen(CreateGuildModalScreens.JoinGuild);
} else {
CreateGuildModalActionCreators.open(null, 'Keyboard Shortcut');
}
},
};
export default {
CREATE_GUILD,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/createGuild.js

View file

@ -0,0 +1,19 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const FOCUS_SEARCH = {
binds: ['mod+f'],
global: true,
action(event: KeyboardEvent) {
event.preventDefault();
event.stopPropagation();
ComponentDispatch.dispatch(ComponentActions.FOCUS_SEARCH, {prefillCurrentChannel: true});
},
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/focusSearch.js

View file

@ -0,0 +1,54 @@
/* @flow */
import {ME, Routes} from '../../Constants';
import SortedGuildStore from '../../stores/SortedGuildStore';
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import SelectedGuildStore from '../../stores/SelectedGuildStore';
import RouterUtils from '../../utils/RouterUtils';
export const JUMP_TO_GUILD = {
binds: (() => {
const KEY_BINDS = 10;
const combos = [];
// cmd+0 is reserved for resetting zoom level
for (let i = 1; i < KEY_BINDS; i++) {
combos.push(`mod+${i}`);
}
return combos;
})(),
global: true,
action(event: KeyboardEvent, combo: string) {
let key = parseInt(combo.split('+')[1], 10);
if (key === 0) {
key = 10;
}
if (!key) {
return;
}
let newGuild;
if (key === 1) {
newGuild = ME;
} else {
newGuild = SortedGuildStore.guildPositions[key - 2];
}
if (!newGuild) {
return;
}
let newChannel = SelectedChannelStore.getChannelId(newGuild);
if (newGuild == ME && SelectedGuildStore.getGuildId() == null) {
newChannel = null;
}
RouterUtils.transitionTo(newChannel ? Routes.CHANNEL(newGuild, newChannel) : Routes.GUILD(newGuild));
return false;
},
};
export default {
JUMP_TO_GUILD,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/jumpToGuild.js

View file

@ -0,0 +1,62 @@
/* @flow */
import {ComponentActions, MAX_MESSAGES_PER_CHANNEL} from '../../Constants';
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import SelectedGuildStore from '../../stores/SelectedGuildStore';
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import MessageStore from '../../stores/MessageStore';
import ReadStateActionCreators from '../../actions/ReadStateActionCreators';
import MessageActionCreators from '../../actions/MessageActionCreators';
import ReadStateStore from '../../stores/ReadStateStore';
export const MARK_CHANNEL_READ = {
binds: ['esc', 'shift+pagedown'],
global: true,
action() {
// First cancel an incoming call
if (ComponentDispatch.hasSubscribers(ComponentActions.CALL_DECLINE)) {
ComponentDispatch.dispatch(ComponentActions.CALL_DECLINE);
return false;
}
// Then attempt to close a context menu
if (ComponentDispatch.hasSubscribers(ComponentActions.CONTEXT_MENU_CLOSE)) {
ComponentDispatch.dispatch(ComponentActions.CONTEXT_MENU_CLOSE);
return false;
}
// Then attempt to close a popout
if (ComponentDispatch.hasSubscribers(ComponentActions.POPOUT_CLOSE)) {
ComponentDispatch.dispatch(ComponentActions.POPOUT_CLOSE);
return false;
}
// Next attempt to close a modal
if (ComponentDispatch.hasSubscribers(ComponentActions.MODAL_CLOSE)) {
ComponentDispatch.dispatch(ComponentActions.MODAL_CLOSE);
return false;
}
// Finally attempt to mark as read
const currentGuild = SelectedGuildStore.getGuildId();
const currentChannel = SelectedChannelStore.getChannelId(currentGuild);
if (currentChannel) {
const messages = MessageStore.getMessages(currentChannel);
if (messages.hasMoreAfter) {
MessageActionCreators.jumpToPresent(currentChannel, MAX_MESSAGES_PER_CHANNEL);
}
if (ReadStateStore.hasUnread(currentChannel)) {
ReadStateActionCreators.ack(currentChannel);
}
ReadStateActionCreators.localAck(currentChannel);
}
ComponentDispatch.dispatch(ComponentActions.SCROLLTO_PRESENT);
return false;
},
};
export default {
MARK_CHANNEL_READ,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/markChannelRead.js

View file

@ -0,0 +1,46 @@
/* @flow */
import SelectedGuildStore from '../../stores/SelectedGuildStore';
import GuildReadStateStore from '../../stores/GuildReadStateStore';
import GuildActionCreators from '../../actions/GuildActionCreators';
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import MessageStore from '../../stores/MessageStore';
import MessageActionCreators from '../../actions/MessageActionCreators';
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {MAX_MESSAGES_PER_CHANNEL, ComponentActions} from '../../Constants';
const inProgressAcks = {};
export const MARK_SERVER_READ = {
binds: ['shift+esc'],
global: true,
action() {
const currentGuild = SelectedGuildStore.getGuildId();
if (!currentGuild || !GuildReadStateStore.getUnreadGuildsIgnoreMuted(currentGuild)) {
return;
}
if (!inProgressAcks[currentGuild]) {
const clearProgress = () => delete inProgressAcks[currentGuild];
GuildActionCreators.markGuildAsRead(currentGuild).then(clearProgress, clearProgress);
}
const currentChannel = SelectedChannelStore.getChannelId(currentGuild);
if (!currentChannel) {
return;
}
const messages = MessageStore.getMessages(currentChannel);
if (messages.hasMoreAfter) {
MessageActionCreators.jumpToPresent(currentChannel, MAX_MESSAGES_PER_CHANNEL);
} else {
ComponentDispatch.dispatch(ComponentActions.SCROLLTO_PRESENT);
}
},
};
export default {
MARK_SERVER_READ,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/markServerRead.js

View file

@ -0,0 +1,29 @@
/* @flow */
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import ReadStateStore from '../../stores/ReadStateStore';
import MessageActionCreators from '../../actions/MessageActionCreators';
export const JUMP_TO_FIRST_UNREAD = {
binds: ['shift+pageup'],
global: true,
action() {
const selectedChannel = SelectedChannelStore.getChannelId();
if (selectedChannel) {
const unreadMessage = ReadStateStore.ackMessageId(selectedChannel);
if (unreadMessage && ReadStateStore.getOldestUnreadTimestamp(selectedChannel) > 0) {
MessageActionCreators.jumpToMessage(selectedChannel, unreadMessage, false, 'Keyboard Shortcut');
}
}
return false;
},
};
export default {
JUMP_TO_FIRST_UNREAD,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/messagesNav.js

View file

@ -0,0 +1,18 @@
import {show} from '../../actions/QuickSwitcherActionCreators';
import LayerStore from '../../stores/LayerStore';
export const QUICKSWITCHER_SHOW = {
binds: ['mod+k', 'mod+t'],
global: true,
action() {
if (!LayerStore.hasLayers()) {
show();
}
return false;
},
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/quickswitcher.js

View file

@ -0,0 +1,33 @@
/* @flow */
import RTCConnectionStore from '../../stores/RTCConnectionStore';
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import DelayedSelectionActionCreators from '../../actions/DelayedSelectionActionCreators';
import DimensionActionCreators from '../../actions/DimensionActionCreators';
import transitionTo from '../helpers/transitionTo';
import {ME} from '../../Constants';
export const RETURN_TO_AUDIO_CHANNEL = {
binds: ['mod+alt+left'],
global: true,
action() {
if (!RTCConnectionStore.isConnected()) {
return false;
}
const voiceGuild = RTCConnectionStore.getGuildId() || ME;
const selectedChannel = SelectedChannelStore.getChannelId(voiceGuild);
transitionTo(voiceGuild, selectedChannel);
DelayedSelectionActionCreators.flushSelection(true);
DimensionActionCreators.channelListScrollTo(voiceGuild, RTCConnectionStore.getChannelId());
return false;
},
};
export default {
RETURN_TO_AUDIO_CHANNEL,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/returnToAudioChannel.js

View file

@ -0,0 +1,32 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const SCROLL_UP = {
binds: ['pageup'],
global: true,
action() {
ComponentDispatch.dispatchToLastSubscribed(ComponentActions.SCROLL_PAGE_UP);
return false;
},
};
export const SCROLL_DOWN = {
binds: ['pagedown'],
global: true,
action() {
ComponentDispatch.dispatchToLastSubscribed(ComponentActions.SCROLL_PAGE_DOWN);
return false;
},
};
export default {
SCROLL_UP,
SCROLL_DOWN,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/scroll.js

View file

@ -0,0 +1,22 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const SEARCH_EMOJIS = {
binds: ['mod+e'],
global: true,
action() {
ComponentDispatch.dispatch(ComponentActions.TOGGLE_EMOJI_POPOUT);
return false;
},
};
export default {
SEARCH_EMOJIS,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/searchEmojis.js

View file

@ -0,0 +1,54 @@
/* @flow */
import DelayedSelectionActionCreators from '../../actions/DelayedSelectionActionCreators';
import navigateToServer from '../helpers/navigateToServer';
export const SERVER_NEXT = {
binds: [
'mod+alt+down',
'mod+shift+]', // default os way, probably won't work in a browser
'ctrl+tab', // default os way, probably won't work in a browser
],
global: true,
action(event: KeyboardEvent) {
event.preventDefault();
event.stopPropagation();
navigateToServer();
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export const SERVER_PREV = {
binds: [
'mod+alt+up',
'mod+shift+[', // default os way, probably won't work in a browser
'ctrl+shift+tab', // default os way, probably won't work in a browser
],
global: true,
action(event: KeyboardEvent) {
event.preventDefault();
event.stopPropagation();
navigateToServer(-1);
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export default {
SERVER_NEXT,
SERVER_PREV,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/serverNav.js

View file

@ -0,0 +1,24 @@
/* @flow */
import {ComponentActions} from '../../Constants';
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
export const SUBMIT = {
binds: ['return'],
global: false,
action() {
if (ComponentDispatch.hasSubscribers(ComponentActions.MODAL_SUBMIT)) {
ComponentDispatch.dispatch(ComponentActions.MODAL_SUBMIT);
return false;
}
},
};
export default {
SUBMIT,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/submit.js

View file

@ -0,0 +1,47 @@
/* @flow */
import RTCConnectionStore from '../../stores/RTCConnectionStore';
import MediaEngineStore from '../../stores/MediaEngineStore';
import {ComponentActions, InputModes} from '../../Constants';
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
export const TEXTAREA_FOCUS = {
binds: ['tab', 'any-character'],
global: false,
action(event: KeyboardEvent, key: string) {
// Disable automatic focus if a modal is viewable
if (ComponentDispatch.hasSubscribers(ComponentActions.MODAL_CLOSE)) {
return false;
}
// Tab always focuses if possible
if (key === 'tab') {
event.preventDefault();
ComponentDispatch.dispatch(ComponentActions.TEXTAREA_FOCUS);
return false;
}
// Firefox: Keys that shouldn't be triggered by 'any-character'
const allowedKeys = ['PageDown', 'PageUp', 'Home', 'End'];
// Prevent when using PTT and in voice chat
if (
RTCConnectionStore.isConnected() &&
MediaEngineStore.getMode() === InputModes.PUSH_TO_TALK &&
!MediaEngineStore.isSelfMute()
) {
event.preventDefault();
return false;
}
// prevent if meta or ctrl key was held (firefox fix)
if (!event.metaKey && !event.ctrlKey && allowedKeys.indexOf(event.key) === -1) {
ComponentDispatch.dispatchToLastSubscribed(ComponentActions.TEXTAREA_FOCUS);
}
},
};
export default {
TEXTAREA_FOCUS,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/textareaFocus.js

View file

@ -0,0 +1,31 @@
/* @flow */
import AudioActionCreators from '../../actions/AudioActionCreators';
export const TOGGLE_MUTE = {
binds: ['mod+shift+m'],
global: true,
action() {
AudioActionCreators.toggleSelfMute();
return false;
},
};
export const TOGGLE_DEAFEN = {
binds: ['mod+shift+d'],
global: true,
action() {
AudioActionCreators.toggleSelfDeaf();
return false;
},
};
export default {
TOGGLE_MUTE,
TOGGLE_DEAFEN,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/toggleAudio.js

View file

@ -0,0 +1,22 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const TOGGLE_CHANNEL_PINS = {
binds: ['mod+p'],
global: true,
action() {
ComponentDispatch.dispatch(ComponentActions.TOGGLE_CHANNEL_PINS);
return false;
},
};
export default {
TOGGLE_CHANNEL_PINS,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/toggleChannelPins.js

View file

@ -0,0 +1,22 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const TOGGLE_HELP = {
binds: ['mod+shift+h', 'f1'],
global: true,
action() {
ComponentDispatch.dispatch(ComponentActions.TOGGLE_HELP_MODAL);
return false;
},
};
export default {
TOGGLE_HELP,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/toggleHelp.js

View file

@ -0,0 +1,26 @@
/* @flow */
import KeyboardShortcutModalActionCreators from '../../actions/KeyboardShortcutModalActionCreators';
import KeyboardShortcutModalStore from '../../stores/KeyboardShortcutModalStore';
export const TOGGLE_HOTKEYS = {
binds: ['mod+/', 'mod+shift+/'],
global: true,
action() {
if (KeyboardShortcutModalStore.isOpen()) {
KeyboardShortcutModalActionCreators.hide();
} else {
KeyboardShortcutModalActionCreators.show();
}
return false;
},
};
export default {
TOGGLE_HOTKEYS,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/toggleHotkeys.js

View file

@ -0,0 +1,22 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const TOGGLE_MENTIONS = {
binds: ['mod+i'],
global: true,
action() {
ComponentDispatch.dispatch(ComponentActions.TOGGLE_MENTIONS);
return false;
},
};
export default {
TOGGLE_MENTIONS,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/toggleMentions.js

View file

@ -0,0 +1,22 @@
/* @flow */
import ChannelSectionActionCreators from '../../actions/ChannelSectionActionCreators';
import {ChannelSections} from '../../Constants';
export const TOGGLE_USERS = {
binds: ['mod+u'],
global: true,
action() {
ChannelSectionActionCreators.toggleSection(ChannelSections.MEMBERS);
return false;
},
};
export default {
TOGGLE_USERS,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/toggleUsers.js

View file

@ -0,0 +1,91 @@
/* @flow */
import searchForChannel from '../helpers/searchForChannel';
import DelayedSelectionActionCreators from '../../actions/DelayedSelectionActionCreators';
import ReadStateStore from '../../stores/ReadStateStore';
import UserGuildSettingsStore from '../../stores/UserGuildSettingsStore';
import DelayedSelectionStore from '../../stores/DelayedSelectionStore';
import {ME} from '../../Constants';
const CHANNEL_PREDICATE = (guildId, channelId) =>
!UserGuildSettingsStore.isChannelMuted(guildId, channelId) && ReadStateStore.hasUnread(channelId);
export const UNREAD_NEXT = {
binds: [
'alt+shift+down', // slack way
],
global: true,
action() {
const currentGuild = DelayedSelectionStore.getGuildId() || ME;
searchForChannel(
1,
CHANNEL_PREDICATE,
guildId => guildId === currentGuild || !UserGuildSettingsStore.isMuted(guildId)
);
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export const UNREAD_PREV = {
binds: [
'alt+shift+up', // slack way
],
global: true,
action() {
const currentGuild = DelayedSelectionStore.getGuildId() || ME;
searchForChannel(
-1,
CHANNEL_PREDICATE,
guildId => guildId === currentGuild || !UserGuildSettingsStore.isMuted(guildId)
);
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
const HAS_UNREAD = (guildId, channelId) => ReadStateStore.getMentionCount(channelId) > 0;
export const MENTION_NEXT = {
binds: ['mod+shift+alt+down'],
global: true,
action() {
searchForChannel(1, HAS_UNREAD);
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export const MENTION_PREV = {
binds: ['mod+shift+alt+up'],
global: true,
action() {
searchForChannel(-1, HAS_UNREAD);
return false;
},
keyup() {
DelayedSelectionActionCreators.flushSelection();
return false;
},
};
export default {
UNREAD_NEXT,
UNREAD_PREV,
MENTION_NEXT,
MENTION_PREV,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/unreadNav.js

View file

@ -0,0 +1,22 @@
/* @flow */
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
import {ComponentActions} from '../../Constants';
export const UPLOAD_FILE = {
binds: ['mod+shift+u'],
global: true,
action() {
ComponentDispatch.dispatch(ComponentActions.UPLOAD_FILE);
return false;
},
};
export default {
UPLOAD_FILE,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/uploadFile.js

View file

@ -0,0 +1,55 @@
/* @flow */
import AccessibilityStore from '../../stores/AccessibilityStore';
import {zoomTo} from '../../actions/AccessibilityActionCreators';
import {Accessibility} from '../../Constants';
function getNewZoom(change) {
return Accessibility.ZOOM_SCALES[
Math.max(
0,
Math.min(
Accessibility.ZOOM_SCALES.indexOf(AccessibilityStore.zoom) + change,
Accessibility.ZOOM_SCALES.length - 1
)
)
];
}
export const ZOOM_IN = {
binds: ['mod+plus'],
global: true,
action() {
zoomTo(getNewZoom(1));
return false;
},
};
export const ZOOM_OUT = {
binds: ['mod+minus'],
global: true,
action() {
zoomTo(getNewZoom(-1));
return false;
},
};
export const ZOOM_RESET = {
binds: ['mod+0'],
global: true,
action() {
zoomTo(Accessibility.ZOOM_DEFAULT);
return false;
},
};
export default {
ZOOM_IN,
ZOOM_OUT,
ZOOM_RESET,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/actions/zoom.js

View file

@ -0,0 +1,218 @@
/* @flow */
import i18n from '../i18n';
import {KeybindActions} from '../Constants';
import {SERVER_PREV, SERVER_NEXT} from './actions/serverNav';
import {CHANNEL_PREV, CHANNEL_NEXT, TOGGLE_PREVIOUS_GUILD} from './actions/channelNav';
import {UNREAD_PREV, UNREAD_NEXT, MENTION_NEXT, MENTION_PREV} from './actions/unreadNav';
import {SUBMIT} from './actions/submit';
import {TEXTAREA_FOCUS} from './actions/textareaFocus';
import {MARK_CHANNEL_READ} from './actions/markChannelRead';
import {JUMP_TO_GUILD} from './actions/jumpToGuild';
import {MARK_SERVER_READ} from './actions/markServerRead';
import {TOGGLE_CHANNEL_PINS} from './actions/toggleChannelPins';
import {TOGGLE_MENTIONS} from './actions/toggleMentions';
import {SCROLL_UP, SCROLL_DOWN} from './actions/scroll';
import {CREATE_DM_GROUP} from './actions/createDMGroup';
import {TOGGLE_USERS} from './actions/toggleUsers';
import {SEARCH_EMOJIS} from './actions/searchEmojis';
import {TOGGLE_HOTKEYS} from './actions/toggleHotkeys';
import {JUMP_TO_FIRST_UNREAD} from './actions/messagesNav';
import {TOGGLE_HELP} from './actions/toggleHelp';
import {CREATE_GUILD} from './actions/createGuild';
import {UPLOAD_FILE} from './actions/uploadFile';
import {TOGGLE_MUTE, TOGGLE_DEAFEN} from './actions/toggleAudio';
import {RETURN_TO_AUDIO_CHANNEL} from './actions/returnToAudioChannel';
import {CALL_ACCEPT, CALL_START} from './actions/calls';
import {FOCUS_SEARCH} from './actions/focusSearch';
import {QUICKSWITCHER_SHOW} from './actions/quickswitcher';
import {ZOOM_IN, ZOOM_OUT, ZOOM_RESET} from './actions/zoom';
function getBindsFor() {
return Array.from(arguments).map(action => DEFAULT_LAYOUT[action].binds[0]);
}
export const DEFAULT_LAYOUT = {
[KeybindActions.SERVER_NEXT]: SERVER_NEXT,
[KeybindActions.SERVER_PREV]: SERVER_PREV,
[KeybindActions.CHANNEL_NEXT]: CHANNEL_NEXT,
[KeybindActions.CHANNEL_PREV]: CHANNEL_PREV,
[KeybindActions.UNREAD_NEXT]: UNREAD_NEXT,
[KeybindActions.UNREAD_PREV]: UNREAD_PREV,
[KeybindActions.MENTION_CHANNEL_NEXT]: MENTION_NEXT,
[KeybindActions.MENTION_CHANNEL_PREV]: MENTION_PREV,
[KeybindActions.TOGGLE_PREVIOUS_GUILD]: TOGGLE_PREVIOUS_GUILD,
[KeybindActions.JUMP_TO_GUILD]: JUMP_TO_GUILD,
[KeybindActions.SUBMIT]: SUBMIT,
[KeybindActions.TEXTAREA_FOCUS]: TEXTAREA_FOCUS,
[KeybindActions.MARK_CHANNEL_READ]: MARK_CHANNEL_READ,
[KeybindActions.MARK_SERVER_READ]: MARK_SERVER_READ,
[KeybindActions.TOGGLE_CHANNEL_PINS]: TOGGLE_CHANNEL_PINS,
[KeybindActions.TOGGLE_MENTIONS]: TOGGLE_MENTIONS,
[KeybindActions.TOGGLE_USERS]: TOGGLE_USERS,
[KeybindActions.TOGGLE_HELP]: TOGGLE_HELP,
[KeybindActions.TOGGLE_MUTE]: TOGGLE_MUTE,
[KeybindActions.TOGGLE_DEAFEN]: TOGGLE_DEAFEN,
[KeybindActions.SCROLL_UP]: SCROLL_UP,
[KeybindActions.SCROLL_DOWN]: SCROLL_DOWN,
[KeybindActions.QUICKSWITCHER_SHOW]: QUICKSWITCHER_SHOW,
[KeybindActions.CREATE_DM_GROUP]: CREATE_DM_GROUP,
[KeybindActions.SEARCH_EMOJIS]: SEARCH_EMOJIS,
[KeybindActions.TOGGLE_HOTKEYS]: TOGGLE_HOTKEYS,
[KeybindActions.JUMP_TO_FIRST_UNREAD]: JUMP_TO_FIRST_UNREAD,
[KeybindActions.CREATE_GUILD]: CREATE_GUILD,
[KeybindActions.UPLOAD_FILE]: UPLOAD_FILE,
[KeybindActions.RETURN_TO_AUDIO_CHANNEL]: RETURN_TO_AUDIO_CHANNEL,
[KeybindActions.CALL_ACCEPT]: CALL_ACCEPT,
// CALL_DECLINE handled in MARK_CHANNEL_READ
[KeybindActions.CALL_START]: CALL_START,
[KeybindActions.FOCUS_SEARCH]: FOCUS_SEARCH,
[KeybindActions.ZOOM_IN]: ZOOM_IN,
[KeybindActions.ZOOM_OUT]: ZOOM_OUT,
[KeybindActions.ZOOM_RESET]: ZOOM_RESET,
};
export const DEFAULT_LAYOUT_CONTENT = [
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_NAVIGATE_SERVERS,
binds: getBindsFor(KeybindActions.SERVER_PREV, KeybindActions.SERVER_NEXT),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_NAVIGATE_CHANNELS,
binds: getBindsFor(KeybindActions.CHANNEL_PREV, KeybindActions.CHANNEL_NEXT),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_UNREAD_CHANNELS,
binds: getBindsFor(KeybindActions.UNREAD_PREV, KeybindActions.UNREAD_NEXT),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_UNREAD_MENTION_CHANNELS,
binds: getBindsFor(KeybindActions.MENTION_CHANNEL_PREV, KeybindActions.MENTION_CHANNEL_NEXT),
groupEnd: true,
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_PREVIOUS_GUILD,
binds: getBindsFor(KeybindActions.TOGGLE_PREVIOUS_GUILD),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_MARK_SERVER_READ,
binds: getBindsFor(KeybindActions.MARK_SERVER_READ),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_MARK_CHANNEL_READ,
binds: getBindsFor(KeybindActions.MARK_CHANNEL_READ),
},
{
// separator: true,
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_CREATE_GUILD,
binds: getBindsFor(KeybindActions.CREATE_GUILD),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_QUICKSWITCHER,
binds: getBindsFor(KeybindActions.QUICKSWITCHER_SHOW),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_CREATE_DM_GROUP,
binds: getBindsFor(KeybindActions.CREATE_DM_GROUP),
groupEnd: true,
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_PINS,
binds: getBindsFor(KeybindActions.TOGGLE_CHANNEL_PINS),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_MENTIONS,
binds: getBindsFor(KeybindActions.TOGGLE_MENTIONS),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_USERS,
binds: getBindsFor(KeybindActions.TOGGLE_USERS),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_SEARCH_EMOJIS,
binds: getBindsFor(KeybindActions.SEARCH_EMOJIS),
groupEnd: true,
},
{
// separator: true,
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_MUTE,
binds: getBindsFor(KeybindActions.TOGGLE_MUTE),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_DEAFEN,
binds: getBindsFor(KeybindActions.TOGGLE_DEAFEN),
},
{
// separator: true,
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_CALL_ACCEPT,
binds: getBindsFor(KeybindActions.CALL_ACCEPT),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_CALL_DECLINE,
binds: getBindsFor(KeybindActions.MARK_CHANNEL_READ),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_CALL_START,
binds: getBindsFor(KeybindActions.CALL_START),
groupEnd: true,
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_SCROLL_CHAT,
binds: getBindsFor(KeybindActions.SCROLL_UP, KeybindActions.SCROLL_DOWN),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_JUMP_TO_FIRST_UNREAD,
binds: getBindsFor(KeybindActions.JUMP_TO_FIRST_UNREAD),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_FOCUS_TEXT_AREA,
binds: getBindsFor(KeybindActions.TEXTAREA_FOCUS),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_UPLOAD_FILE,
binds: getBindsFor(KeybindActions.UPLOAD_FILE),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_TOGGLE_HELP,
binds: getBindsFor(KeybindActions.TOGGLE_HELP),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_SEARCH,
binds: getBindsFor(KeybindActions.FOCUS_SEARCH),
},
{
description: i18n.Messages.KEYBIND_DESCRIPTION_MODAL_EASTER_EGG,
binds: ['h+h+right+n+k'],
},
];
export default DEFAULT_LAYOUT;
// WEBPACK FOOTER //
// ./discord_app/keybinds/default.js

View file

@ -0,0 +1,60 @@
/* @flow */
import lodash from 'lodash';
import transitionTo from '../helpers/transitionTo';
import DelayedSelectionStore from '../../stores/DelayedSelectionStore';
import PrivateChannelSortStore from '../../stores/views/PrivateChannelSortStore';
import GuildChannelStore from '../../stores/views/GuildChannelStore';
import ChannelCollapseStore from '../../stores/ChannelCollapseStore';
import UserGuildSettingsStore from '../../stores/UserGuildSettingsStore';
import {ME, NAVIGATION_THROTTLE} from '../../Constants';
function filterMutedChannels(currentGuild, currentChannel, channels) {
const mutedCollapsed = ChannelCollapseStore.isMutedCollapsed();
if (currentGuild !== ME && mutedCollapsed) {
const totalMutedChannels = channels.reduce((previousValue, channelId) => {
return UserGuildSettingsStore.isChannelMuted(currentGuild, channelId) ? (previousValue += 1) : previousValue;
}, 0);
if (totalMutedChannels > 3) {
return channels.filter(channelId => {
if (!mutedCollapsed) {
return true;
}
if (channelId === currentChannel) {
return true;
}
return !UserGuildSettingsStore.isChannelMuted(currentGuild, channelId);
});
}
}
return channels;
}
export default lodash.throttle((navigateTo: number = 1) => {
let currentGuild = DelayedSelectionStore.getGuildId();
let sortedChannels;
if (!currentGuild) {
currentGuild = ME;
sortedChannels = [undefined, ...PrivateChannelSortStore.getPrivateChannelIds()];
} else {
sortedChannels = GuildChannelStore.getTextChannelIds(currentGuild);
}
const currentChannel = DelayedSelectionStore.getChannelId(currentGuild);
sortedChannels = filterMutedChannels(currentGuild, currentChannel, sortedChannels);
let newChannelIndex = sortedChannels.indexOf(currentChannel) + navigateTo;
if (newChannelIndex < 0) {
newChannelIndex = sortedChannels.length - 1;
}
if (newChannelIndex >= sortedChannels.length) {
newChannelIndex = 0;
}
transitionTo(currentGuild, sortedChannels[newChannelIndex]);
}, NAVIGATION_THROTTLE);
// WEBPACK FOOTER //
// ./discord_app/keybinds/helpers/navigateToChannel.js

View file

@ -0,0 +1,37 @@
/* @flow */
import lodash from 'lodash';
import SortedGuildStore from '../../stores/SortedGuildStore';
import DelayedSelectionStore from '../../stores/DelayedSelectionStore';
import SelectedChannelStore from '../../stores/SelectedChannelStore';
import transitionTo from './transitionTo';
import {ME, NAVIGATION_THROTTLE} from '../../Constants';
export default lodash.throttle((navigateTo = 1) => {
const sortedGuilds = SortedGuildStore.guildPositions;
const currentGuild = DelayedSelectionStore.getGuildId();
let newIndex = -1;
if (currentGuild) {
newIndex = sortedGuilds.indexOf(currentGuild);
}
newIndex += navigateTo;
if (newIndex === -2) {
newIndex = sortedGuilds.length - 1;
}
let newGuild;
if (newIndex >= sortedGuilds.length || newIndex < 0) {
newGuild = ME;
} else {
newGuild = sortedGuilds[newIndex];
}
const newChannel = SelectedChannelStore.getChannelId(newGuild);
transitionTo(newGuild, newChannel == newGuild ? null : newChannel);
}, NAVIGATION_THROTTLE);
// WEBPACK FOOTER //
// ./discord_app/keybinds/helpers/navigateToServer.js

View file

@ -0,0 +1,68 @@
/* @flow */
import lodash from 'lodash';
import {ME, NAVIGATION_THROTTLE, ComponentActions} from '../../Constants';
import SortedGuildStore from '../../stores/SortedGuildStore';
import PrivateChannelSortStore from '../../stores/views/PrivateChannelSortStore';
import GuildChannelStore from '../../stores/views/GuildChannelStore';
import DelayedSelectionStore from '../../stores/DelayedSelectionStore';
import transitionTo from '../helpers/transitionTo';
import {ComponentDispatch} from '../../utils/ComponentDispatchUtils';
// Ensure that the starting guild is at the beginning or end of array, so we
// can loop around when searching
function getSortedGuilds(startingGuild, direction) {
const guilds = [ME, ...SortedGuildStore.guildPositions];
const guildIndex = guilds.indexOf(startingGuild);
if (direction > 0) {
return guilds.slice(guildIndex).concat(guilds.slice(0, guildIndex), startingGuild);
}
// Funky hack to allow loopback - basically re-search the starting guild to
// potentially include missed channels
guilds.splice(guildIndex, 0, startingGuild);
return guilds.slice(guildIndex + 1).concat(guilds.slice(0, guildIndex + 1));
}
function getSortedChannels(guildId) {
if (guildId === ME) {
return PrivateChannelSortStore.getPrivateChannelIds();
}
return GuildChannelStore.getTextChannelIds(guildId);
}
function searchForChannel(iterator = 1, channelPredicate = () => true, guildPredicate = () => true) {
let currentGuild = DelayedSelectionStore.getGuildId() || ME;
const guilds = getSortedGuilds(currentGuild, iterator);
let guildIndex = iterator > 0 ? 0 : guilds.length - 1;
let sortedChannels = getSortedChannels(currentGuild);
let channelIndex = sortedChannels.indexOf(DelayedSelectionStore.getChannelId(currentGuild)) + iterator;
let currentChannel;
while (currentGuild) {
currentChannel = sortedChannels[channelIndex];
if (guildPredicate(currentGuild)) {
while (currentChannel) {
if (channelPredicate(currentGuild, currentChannel)) {
return transitionTo(currentGuild, currentChannel);
}
channelIndex += iterator;
currentChannel = sortedChannels[channelIndex];
}
}
guildIndex += iterator;
currentGuild = guilds[guildIndex];
if (!currentGuild) {
break;
}
sortedChannels = getSortedChannels(currentGuild);
channelIndex = iterator < 0 ? sortedChannels.length - 1 : 0;
}
ComponentDispatch.dispatch(ComponentActions.SHAKE_APP, {duration: 200, intensity: 2});
}
export default lodash.throttle(searchForChannel, NAVIGATION_THROTTLE);
// WEBPACK FOOTER //
// ./discord_app/keybinds/helpers/searchForChannel.js

View file

@ -0,0 +1,21 @@
/* @flow */
import DelayedSelectionActionCreators from '../../actions/DelayedSelectionActionCreators';
import DimensionActionCreators from '../../actions/DimensionActionCreators';
import PopoutActionCreators from '../../actions/PopoutActionCreators';
import ModalStore from '../../stores/ModalStore';
export default function transitionTo(guildId: string, channelId: ?string) {
if (ModalStore.hasModalOpen()) {
return;
}
PopoutActionCreators.closeAll();
DimensionActionCreators.channelListScrollTo(guildId, channelId);
DelayedSelectionActionCreators.selectChannel(guildId, channelId);
}
// WEBPACK FOOTER //
// ./discord_app/keybinds/helpers/transitionTo.js

View file

@ -0,0 +1,40 @@
import {ComponentActions} from '../Constants';
import {ComponentDispatch} from '../utils/ComponentDispatchUtils';
import ZoomActions from './actions/zoom';
export const SETTINGS_LAYERS_LAYOUT = {
POP_LAYER: {
binds: ['esc'],
global: true,
action() {
// First cancel an incoming call
if (ComponentDispatch.hasSubscribers(ComponentActions.CALL_DECLINE)) {
ComponentDispatch.dispatch(ComponentActions.CALL_DECLINE);
return false;
}
// Then attempt to close a context menu
if (ComponentDispatch.hasSubscribers(ComponentActions.CONTEXT_MENU_CLOSE)) {
ComponentDispatch.dispatch(ComponentActions.CONTEXT_MENU_CLOSE);
return false;
}
// Then attempt to close a popout
if (ComponentDispatch.hasSubscribers(ComponentActions.POPOUT_CLOSE)) {
ComponentDispatch.dispatch(ComponentActions.POPOUT_CLOSE);
return false;
}
// Next attempt to close a modal
if (ComponentDispatch.hasSubscribers(ComponentActions.MODAL_CLOSE)) {
ComponentDispatch.dispatch(ComponentActions.MODAL_CLOSE);
return false;
}
// Finally close the layer
ComponentDispatch.dispatch(ComponentActions.LAYER_POP_ESCAPE_KEY);
},
},
...ZoomActions,
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/settingsLayers.js

View file

@ -0,0 +1,47 @@
import {Arrows, ComponentActions} from '../Constants';
import {ComponentDispatch} from '../utils/ComponentDispatchUtils';
import KeyboardShortcutModalActionCreators from '../actions/KeyboardShortcutModalActionCreators';
function arrowdown(direction) {
ComponentDispatch.dispatch(ComponentActions.DDR_ARROW_DOWN, {direction});
return false;
}
function arrowup(direction) {
ComponentDispatch.dispatch(ComponentActions.DDR_ARROW_UP, {direction});
return false;
}
export const SHORTCUT_MODAL_LAYOUT = {
[Arrows.UP]: {
binds: ['up'],
keydown: arrowdown.bind(null, Arrows.UP),
keyup: arrowup.bind(null, Arrows.UP),
},
[Arrows.DOWN]: {
binds: ['down'],
keydown: arrowdown.bind(null, Arrows.DOWN),
keyup: arrowup.bind(null, Arrows.DOWN),
},
[Arrows.LEFT]: {
binds: ['left'],
keydown: arrowdown.bind(null, Arrows.LEFT),
keyup: arrowup.bind(null, Arrows.LEFT),
},
[Arrows.RIGHT]: {
binds: ['right'],
keydown: arrowdown.bind(null, Arrows.RIGHT),
keyup: arrowup.bind(null, Arrows.RIGHT),
},
RAGING_DEMON: {
binds: ['h h right n k'],
action() {
KeyboardShortcutModalActionCreators.activateRagingDemon();
},
},
};
// WEBPACK FOOTER //
// ./discord_app/keybinds/shortcutModal.js