mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-11 16:49:44 +01:00
Follow-up
This commit is contained in:
parent
495ed8b42b
commit
d8273a8127
@ -325,6 +325,10 @@ const MessageInput: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (IS_TOUCH_ENV) {
|
||||
return;
|
||||
}
|
||||
|
||||
focusInput();
|
||||
}, [currentChatId, focusInput, replyingToId, shouldSetFocus]);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import parseMessageInput from '../helpers/parseMessageInput';
|
||||
import getMessageTextAsHtml from '../helpers/getMessageTextAsHtml';
|
||||
import useBackgroundMode from '../../../../hooks/useBackgroundMode';
|
||||
import useBeforeUnload from '../../../../hooks/useBeforeUnload';
|
||||
import { IS_TOUCH_ENV } from '../../../../util/environment';
|
||||
|
||||
// Used to avoid running debounced callbacks when chat changes.
|
||||
let currentChatId: number | undefined;
|
||||
@ -66,10 +67,12 @@ export default (
|
||||
|
||||
setHtml(getMessageTextAsHtml(draft));
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const messageInput = document.getElementById(EDITABLE_INPUT_ID)!;
|
||||
focusEditableElement(messageInput, true);
|
||||
});
|
||||
if (!IS_TOUCH_ENV) {
|
||||
requestAnimationFrame(() => {
|
||||
const messageInput = document.getElementById(EDITABLE_INPUT_ID)!;
|
||||
focusEditableElement(messageInput, true);
|
||||
});
|
||||
}
|
||||
}, [chatId, threadId, draft, setHtml, updateDraft, prevChatId, prevThreadId]);
|
||||
|
||||
// Update draft when input changes
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useState } from '../../../../lib/teact/teact';
|
||||
import { useCallback, useEffect } from '../../../../lib/teact/teact';
|
||||
import { getDispatch } from '../../../../lib/teact/teactn';
|
||||
import { InlineBotSettings } from '../../../../types';
|
||||
import useFlag from '../../../../hooks/useFlag';
|
||||
@ -15,12 +15,20 @@ export default function useInlineBotTooltip(
|
||||
inlineBots?: Record<string, false | InlineBotSettings>,
|
||||
) {
|
||||
const [isOpen, markIsOpen, unmarkIsOpen] = useFlag();
|
||||
const [botSettings, setBotSettings] = useState<undefined | false | InlineBotSettings>();
|
||||
const text = getPlainText(html);
|
||||
const { queryInlineBot, resetInlineBot } = getDispatch();
|
||||
const { username, query, canShowHelp } = parseStartWithUsernameString(text);
|
||||
const usernameLowered = username.toLowerCase();
|
||||
const prevUsername = usePrevious(username);
|
||||
const inlineBotData = inlineBots && inlineBots[usernameLowered];
|
||||
const {
|
||||
id: botId,
|
||||
switchPm,
|
||||
offset,
|
||||
results,
|
||||
isGallery,
|
||||
help,
|
||||
} = inlineBotData || {};
|
||||
|
||||
useEffect(() => {
|
||||
if (isAllowed && usernameLowered && chatId) {
|
||||
@ -30,26 +38,17 @@ export default function useInlineBotTooltip(
|
||||
|
||||
const loadMore = useCallback(() => {
|
||||
queryInlineBot({
|
||||
chatId, username: usernameLowered, query, offset: botSettings && botSettings.offset,
|
||||
chatId, username: usernameLowered, query, offset,
|
||||
});
|
||||
}, [botSettings, chatId, query, queryInlineBot, usernameLowered]);
|
||||
|
||||
const inlineBotData = inlineBots && inlineBots[usernameLowered];
|
||||
}, [offset, chatId, query, queryInlineBot, usernameLowered]);
|
||||
|
||||
useEffect(() => {
|
||||
setBotSettings(inlineBotData);
|
||||
}, [inlineBotData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
isAllowed && botSettings && botSettings.id
|
||||
&& (botSettings.switchPm || (botSettings.results && botSettings.results.length))
|
||||
) {
|
||||
if (isAllowed && botId && (switchPm || (results && results.length))) {
|
||||
markIsOpen();
|
||||
} else {
|
||||
unmarkIsOpen();
|
||||
}
|
||||
}, [botSettings, isAllowed, markIsOpen, unmarkIsOpen]);
|
||||
}, [botId, isAllowed, markIsOpen, results, switchPm, unmarkIsOpen]);
|
||||
|
||||
if (prevUsername !== username) {
|
||||
resetInlineBot({ username: prevUsername });
|
||||
@ -60,11 +59,11 @@ export default function useInlineBotTooltip(
|
||||
closeTooltip: unmarkIsOpen,
|
||||
loadMore,
|
||||
username,
|
||||
id: botSettings ? botSettings.id : undefined,
|
||||
isGallery: botSettings ? botSettings.isGallery : undefined,
|
||||
switchPm: botSettings ? botSettings.switchPm : undefined,
|
||||
results: botSettings ? botSettings.results : undefined,
|
||||
help: canShowHelp && botSettings && botSettings.help ? `@${username} ${botSettings.help}` : undefined,
|
||||
id: botId,
|
||||
isGallery,
|
||||
switchPm,
|
||||
results,
|
||||
help: canShowHelp && help ? `@${username} ${help}` : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,11 @@ import {
|
||||
} from '../../selectors';
|
||||
import { addChats, addUsers } from '../../reducers';
|
||||
import { buildCollectionByKey } from '../../../util/iteratees';
|
||||
import { throttle } from '../../../util/schedulers';
|
||||
import { debounce } from '../../../util/schedulers';
|
||||
import { replaceInlineBotSettings, replaceInlineBotsIsLoading } from '../../reducers/bots';
|
||||
|
||||
const TOP_PEERS_REQUEST_COOLDOWN = 60000; // 1 min
|
||||
const runThrottledForSearch = throttle((cb) => cb(), 500, false);
|
||||
const runDebouncedForSearch = debounce((cb) => cb(), 500, false);
|
||||
|
||||
addReducer('clickInlineButton', (global, actions, payload) => {
|
||||
const { button } = payload;
|
||||
@ -144,7 +144,7 @@ addReducer('queryInlineBot', ((global, actions, payload) => {
|
||||
return;
|
||||
}
|
||||
|
||||
void runThrottledForSearch(() => {
|
||||
void runDebouncedForSearch(() => {
|
||||
searchInlineBot({
|
||||
username,
|
||||
inlineBotData: inlineBotData as InlineBotSettings,
|
||||
@ -220,11 +220,12 @@ async function searchInlineBot({
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldReplaceSettings = inlineBotData.query !== query;
|
||||
global = replaceInlineBotsIsLoading(global, true);
|
||||
global = replaceInlineBotSettings(global, username, {
|
||||
...inlineBotData,
|
||||
query,
|
||||
...(inlineBotData && inlineBotData.query !== query && { offset: undefined }),
|
||||
...(shouldReplaceSettings && { offset: undefined, results: [] }),
|
||||
});
|
||||
setGlobal(global);
|
||||
|
||||
@ -232,7 +233,7 @@ async function searchInlineBot({
|
||||
bot,
|
||||
chat,
|
||||
query,
|
||||
offset,
|
||||
offset: shouldReplaceSettings ? undefined : offset,
|
||||
});
|
||||
|
||||
const newInlineBotData = global.inlineBots.byUsername[username];
|
||||
@ -249,7 +250,7 @@ async function searchInlineBot({
|
||||
...newInlineBotData,
|
||||
help: result.help,
|
||||
isGallery: result.isGallery,
|
||||
switchPm: result.switchPm,
|
||||
...(result.switchPm && { switchPm: result.switchPm }),
|
||||
canLoadMore: result.results.length > 0 && Boolean(result.nextOffset),
|
||||
results: newInlineBotData.offset === '' || newInlineBotData.offset === result.nextOffset
|
||||
? result.results
|
||||
|
Loading…
Reference in New Issue
Block a user