TelegramPWA/src/hooks/useSendMessageAction.ts
2023-01-28 02:21:33 +01:00

19 lines
617 B
TypeScript

import { useMemo } from '../lib/teact/teact';
import { getActions } from '../global';
import type { ApiSendMessageAction } from '../api/types';
import { SEND_MESSAGE_ACTION_INTERVAL } from '../config';
import { throttle } from '../util/schedulers';
const useSendMessageAction = (chatId?: string, threadId?: number) => {
return useMemo(() => {
return throttle((action: ApiSendMessageAction) => {
if (!chatId || !threadId) return;
getActions().sendMessageAction({ chatId, threadId, action });
}, SEND_MESSAGE_ACTION_INTERVAL);
}, [chatId, threadId]);
};
export default useSendMessageAction;