Skip to content

Commit

Permalink
Merge pull request #74 from ulu-telegram/TG-229-mark-unread-shortcut
Browse files Browse the repository at this point in the history
[TG-229] Mark read-unread Cmd+U / Upload file Cmd+Shift+U
  • Loading branch information
iower authored Nov 14, 2023
2 parents 9f9ddaf + 411404b commit 2f6f305
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/components/main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -338,6 +339,7 @@ const Main: FC<OwnProps & StateProps> = ({

useArchiver({ isManual: false });

useShortcutCmdU();
useShortcutCmdE();

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/middle/composer/AttachMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const AttachMenu: FC<OwnProps> = ({

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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useChatContextActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions src/hooks/useShortcutCmdU.ts
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 5 additions & 1 deletion src/util/fallbackLangPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 2f6f305

Please sign in to comment.