Message / Forward: Faster forwarding to "Saved Messages" (#2058)
This commit is contained in:
parent
15527f925d
commit
8186401be4
@ -2,7 +2,7 @@ import type { FC } from '../../lib/teact/teact';
|
|||||||
import React, {
|
import React, {
|
||||||
memo, useCallback, useEffect,
|
memo, useCallback, useEffect,
|
||||||
} from '../../lib/teact/teact';
|
} from '../../lib/teact/teact';
|
||||||
import { getActions } from '../../global';
|
import { getActions, withGlobal } from '../../global';
|
||||||
|
|
||||||
import useLang from '../../hooks/useLang';
|
import useLang from '../../hooks/useLang';
|
||||||
import useFlag from '../../hooks/useFlag';
|
import useFlag from '../../hooks/useFlag';
|
||||||
@ -13,12 +13,21 @@ export type OwnProps = {
|
|||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ForwardRecipientPicker: FC<OwnProps> = ({
|
interface StateProps {
|
||||||
|
currentUserId?: string;
|
||||||
|
isManyMessages?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ForwardRecipientPicker: FC<OwnProps & StateProps> = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
|
currentUserId,
|
||||||
|
isManyMessages,
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
setForwardChatId,
|
setForwardChatId,
|
||||||
exitForwardMode,
|
exitForwardMode,
|
||||||
|
forwardToSavedMessages,
|
||||||
|
showNotification,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
@ -31,8 +40,17 @@ const ForwardRecipientPicker: FC<OwnProps> = ({
|
|||||||
}, [isOpen, markIsShown]);
|
}, [isOpen, markIsShown]);
|
||||||
|
|
||||||
const handleSelectRecipient = useCallback((recipientId: string) => {
|
const handleSelectRecipient = useCallback((recipientId: string) => {
|
||||||
setForwardChatId({ id: recipientId });
|
if (recipientId === currentUserId) {
|
||||||
}, [setForwardChatId]);
|
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(() => {
|
const handleClose = useCallback(() => {
|
||||||
exitForwardMode();
|
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));
|
||||||
|
|||||||
@ -1310,6 +1310,19 @@ addActionHandler('setForwardChatId', async (global, actions, payload) => {
|
|||||||
actions.exitMessageSelectMode();
|
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) {
|
function countSortedIds(ids: number[], from: number, to: number) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
|
|||||||
@ -877,6 +877,7 @@ export interface ActionPayloads {
|
|||||||
setForwardNoCaptions: boolean;
|
setForwardNoCaptions: boolean;
|
||||||
exitForwardMode: never;
|
exitForwardMode: never;
|
||||||
changeForwardRecipient: never;
|
changeForwardRecipient: never;
|
||||||
|
forwardToSavedMessages: never;
|
||||||
|
|
||||||
// GIFs
|
// GIFs
|
||||||
loadSavedGifs: never;
|
loadSavedGifs: never;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user