diff --git a/src/api/gramjs/methods/bots.ts b/src/api/gramjs/methods/bots.ts index 1bc8f34dd..3938d67e7 100644 --- a/src/api/gramjs/methods/bots.ts +++ b/src/api/gramjs/methods/bots.ts @@ -91,7 +91,7 @@ export async function fetchInlineBotResults({ return { isGallery: Boolean(result.gallery), help: bot.botPlaceholder, - nextOffset: result.nextOffset, + nextOffset: getInlineBotResultsNextOffset(bot.username, result.nextOffset), switchPm: buildSwitchPm(result.switchPm), users: result.users.map(buildApiUser).filter(Boolean as any), results: processInlineBotResult(String(result.queryId), result.results), @@ -144,6 +144,10 @@ function processInlineBotResult(queryId: string, results: GramJs.TypeBotInlineRe }); } +function getInlineBotResultsNextOffset(username: string, nextOffset?: string) { + return username === 'gif' && nextOffset === '0' ? '' : nextOffset; +} + function addUserToLocalDb(user: GramJs.User) { localDb.users[user.id] = user; } diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index b7f7a21d7..10b9e311a 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -800,6 +800,17 @@ const Composer: FC = ({ filteredUsers={mentionFilteredUsers} usersById={usersById} /> +
@@ -917,17 +928,6 @@ const Composer: FC = ({ onClose={closeBotKeyboard} /> )} - = ({ sendBotCommand({ chatId: botId, command: `/start ${switchPm!.startParam}` }); }, [botId, openChat, sendBotCommand, switchPm]); - if (!shouldRender || !inlineBotResults || (!inlineBotResults.length && !switchPm)) { + + const prevInlineBotResults = usePrevious( + inlineBotResults && inlineBotResults.length + ? inlineBotResults + : undefined, + shouldRender, + ); + const renderedInlineBotResults = inlineBotResults && !inlineBotResults.length + ? prevInlineBotResults + : inlineBotResults; + + if (!shouldRender || !renderedInlineBotResults || (!renderedInlineBotResults.length && !switchPm)) { return undefined; } @@ -142,7 +154,7 @@ const InlineBotTooltip: FC = ({ } function renderContent() { - return inlineBotResults!.map((inlineBotResult, index) => { + return renderedInlineBotResults!.map((inlineBotResult, index) => { switch (inlineBotResult.type) { case 'gif': return ( @@ -205,7 +217,7 @@ const InlineBotTooltip: FC = ({ { + if (prevQuery !== query) { + unmarkIsOpen(); + } + }, [prevQuery, query, unmarkIsOpen]); + useEffect(() => { if (isAllowed && usernameLowered && chatId) { queryInlineBot({ chatId, username: usernameLowered, query }); diff --git a/src/modules/actions/api/bots.ts b/src/modules/actions/api/bots.ts index 37b9e1790..732bdd30a 100644 --- a/src/modules/actions/api/bots.ts +++ b/src/modules/actions/api/bots.ts @@ -249,7 +249,7 @@ async function searchInlineBot({ global = replaceInlineBotSettings(global, username, { ...newInlineBotData, help: result.help, - isGallery: result.isGallery, + ...(newResults.length && { isGallery: result.isGallery }), ...(result.switchPm && { switchPm: result.switchPm }), canLoadMore: result.results.length > 0 && Boolean(result.nextOffset), results: newInlineBotData.offset === '' || newInlineBotData.offset === result.nextOffset