Message / Forward: Faster forwarding to "Saved Messages" (#2058)

This commit is contained in:
Alexander Zinchuk 2022-10-10 14:37:48 +02:00
parent 15527f925d
commit 8186401be4
3 changed files with 42 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import type { FC } from '../../lib/teact/teact';
import React, {
memo, useCallback, useEffect,
} from '../../lib/teact/teact';
import { getActions } from '../../global';
import { getActions, withGlobal } from '../../global';
import useLang from '../../hooks/useLang';
import useFlag from '../../hooks/useFlag';
@ -13,12 +13,21 @@ export type OwnProps = {
isOpen: boolean;
};
const ForwardRecipientPicker: FC<OwnProps> = ({
interface StateProps {
currentUserId?: string;
isManyMessages?: boolean;
}
const ForwardRecipientPicker: FC<OwnProps & StateProps> = ({
isOpen,
currentUserId,
isManyMessages,
}) => {
const {
setForwardChatId,
exitForwardMode,
forwardToSavedMessages,
showNotification,
} = getActions();
const lang = useLang();
@ -31,8 +40,17 @@ const ForwardRecipientPicker: FC<OwnProps> = ({
}, [isOpen, markIsShown]);
const handleSelectRecipient = useCallback((recipientId: string) => {
setForwardChatId({ id: recipientId });
}, [setForwardChatId]);
if (recipientId === currentUserId) {
forwardToSavedMessages();
showNotification({
message: lang(isManyMessages
? 'Conversation.ForwardTooltip.SavedMessages.Many'
: 'Conversation.ForwardTooltip.SavedMessages.One'),
});
} else {
setForwardChatId({ id: recipientId });
}
}, [currentUserId, forwardToSavedMessages, isManyMessages, lang, setForwardChatId, showNotification]);
const handleClose = useCallback(() => {
exitForwardMode();
@ -53,4 +71,9 @@ const ForwardRecipientPicker: FC<OwnProps> = ({
);
};
export default memo(ForwardRecipientPicker);
export default memo(withGlobal<OwnProps>((global): StateProps => {
return {
currentUserId: global.currentUserId,
isManyMessages: (global.forwardMessages.messageIds?.length || 0) > 1,
};
})(ForwardRecipientPicker));

View File

@ -1310,6 +1310,19 @@ addActionHandler('setForwardChatId', async (global, actions, payload) => {
actions.exitMessageSelectMode();
});
addActionHandler('forwardToSavedMessages', (global, actions) => {
setGlobal({
...global,
forwardMessages: {
...global.forwardMessages,
toChatId: global.currentUserId,
},
});
actions.exitMessageSelectMode();
actions.forwardMessages({ isSilent: true });
});
function countSortedIds(ids: number[], from: number, to: number) {
let count = 0;

View File

@ -877,6 +877,7 @@ export interface ActionPayloads {
setForwardNoCaptions: boolean;
exitForwardMode: never;
changeForwardRecipient: never;
forwardToSavedMessages: never;
// GIFs
loadSavedGifs: never;