diff --git a/src/components/main/Main.tsx b/src/components/main/Main.tsx index 8bb37e6c16..28f1f3ef97 100644 --- a/src/components/main/Main.tsx +++ b/src/components/main/Main.tsx @@ -63,6 +63,7 @@ import { useJune } from '../../hooks/useJune'; import useLastCallback from '../../hooks/useLastCallback'; import usePreventPinchZoomGesture from '../../hooks/usePreventPinchZoomGesture'; import useShortcutCmdE from '../../hooks/useShortcutCmdE'; +import useShortcutCmdU from '../../hooks/useShortcutCmdU'; import useShowTransition from '../../hooks/useShowTransition'; import useSyncEffect from '../../hooks/useSyncEffect'; import useTimeout from '../../hooks/useTimeout'; @@ -338,6 +339,7 @@ const Main: FC = ({ useArchiver({ isManual: false }); + useShortcutCmdU(); useShortcutCmdE(); useEffect(() => { diff --git a/src/components/middle/composer/AttachMenu.tsx b/src/components/middle/composer/AttachMenu.tsx index 93f9d614f0..66047d3cfc 100644 --- a/src/components/middle/composer/AttachMenu.tsx +++ b/src/components/middle/composer/AttachMenu.tsx @@ -122,7 +122,7 @@ const AttachMenu: FC = ({ useEffect(() => { function handleKey(e: KeyboardEvent) { - if (((IS_MAC_OS && e.metaKey) || (!IS_MAC_OS && e.ctrlKey)) && e.code === 'KeyU') { + if (((IS_MAC_OS && e.metaKey) || (!IS_MAC_OS && e.ctrlKey)) && e.shiftKey && e.code === 'KeyU') { e.preventDefault(); handleQuickSelect(); } diff --git a/src/hooks/useChatContextActions.ts b/src/hooks/useChatContextActions.ts index e9c1975257..cb6a2ef554 100644 --- a/src/hooks/useChatContextActions.ts +++ b/src/hooks/useChatContextActions.ts @@ -95,10 +95,10 @@ const useChatContextActions = ({ } const actionMaskAsRead = (chat.unreadCount || chat.hasUnreadMark) - ? { title: lang('MarkAsRead'), icon: 'readchats', handler: () => toggleChatUnread({ id: chat.id }) } + ? { title: lang('MarkAsReadHotkey'), icon: 'readchats', handler: () => toggleChatUnread({ id: chat.id }) } : undefined; const actionMarkAsUnread = !(chat.unreadCount || chat.hasUnreadMark) && !chat.isForum - ? { title: lang('MarkAsUnread'), icon: 'unread', handler: () => toggleChatUnread({ id: chat.id }) } + ? { title: lang('MarkAsUnreadHotkey'), icon: 'unread', handler: () => toggleChatUnread({ id: chat.id }) } : undefined; const actionArchive = isChatArchived(chat) diff --git a/src/hooks/useShortcutCmdU.ts b/src/hooks/useShortcutCmdU.ts new file mode 100644 index 0000000000..061c3db32e --- /dev/null +++ b/src/hooks/useShortcutCmdU.ts @@ -0,0 +1,32 @@ +import { useCallback, useEffect } from '../lib/teact/teact'; +import { getActions, getGlobal } from '../global'; + +import { selectCurrentChat } from '../global/selectors'; +import { IS_MAC_OS } from '../util/windowEnvironment'; +import useLang from './useLang'; + +function useShortcutCmdU() { + const { showNotification, toggleChatUnread } = getActions(); + const lang = useLang(); + + const handleKeyDown = useCallback((e: KeyboardEvent) => { + if (((IS_MAC_OS && e.metaKey) || (!IS_MAC_OS && e.ctrlKey)) && !e.shiftKey && e.code === 'KeyU') { + e.preventDefault(); + const global = getGlobal(); + const chat = selectCurrentChat(global); + if (chat && !chat.isForum) { + showNotification({ + message: lang((chat.unreadCount || chat.hasUnreadMark) ? 'MarkedAsRead' : 'MarkedAsUnread'), + }); + toggleChatUnread({ id: chat.id }); + } + } + }, [toggleChatUnread, lang]); + + useEffect(() => { + document.addEventListener('keydown', handleKeyDown); + return () => document.removeEventListener('keydown', handleKeyDown); + }, [handleKeyDown]); +} + +export default useShortcutCmdU; diff --git a/src/util/fallbackLangPack.ts b/src/util/fallbackLangPack.ts index f1826789b8..f5af6c4bd8 100644 --- a/src/util/fallbackLangPack.ts +++ b/src/util/fallbackLangPack.ts @@ -23,6 +23,8 @@ export default { FilterAllChats: 'Inbox', Inbox: 'Inbox', MarkAsUnread: 'Mark as unread', + MarkAsUnreadHotkey: `Mark as unread ${IS_MAC_OS ? '[⌘+U]' : '[Ctrl+U]'}`, + MarkedAsUnread: 'The chat marked as unread', UnpinFromTop: 'Unpin from top', 'ChatList.Mute': 'Mute', Archive: 'Archive', @@ -36,6 +38,8 @@ export default { 'Month.GenJune': 'June', 'Month.ShortJune': 'Jun', MarkAsRead: 'Mark as read', + MarkAsReadHotkey: `Mark as read ${IS_MAC_OS ? '[⌘+U]' : '[Ctrl+U]'}`, + MarkedAsRead: 'The chat marked as read', PinToTop: 'Pin to top', 'ChatList.Unmute': 'Unmute', 'Group.LeaveGroup': 'Leave Group', @@ -103,7 +107,7 @@ export default { otherValue: 'last seen %@ minutes ago', }, 'AttachmentMenu.PhotoOrVideo': 'Photo or Video', - 'AttachmentMenu.PhotoOrVideoHotkey': IS_MAC_OS ? 'Photo or Video [⌘+U]' : 'Photo or Video [Ctrl+U]', + 'AttachmentMenu.PhotoOrVideoHotkey': `Photo or Video ${IS_MAC_OS ? '[⌘+⇧+U]' : '[Ctrl+Shift+U]'}`, AttachDocument: 'File', SendWithoutSound: 'Send without sound', ScheduleMessage: 'Schedule message',