Bot Command: Fix always sending command in main thread (#6799)
This commit is contained in:
parent
b98f790308
commit
cbedc34bf0
@ -27,9 +27,10 @@ import { debounce } from '../../../util/schedulers';
|
||||
import { getServerTime } from '../../../util/serverTime';
|
||||
import { extractCurrentThemeParams } from '../../../util/themeStyle';
|
||||
import { callApi } from '../../../api/gramjs';
|
||||
import { getMainUsername } from '../../helpers';
|
||||
import {
|
||||
getMainUsername,
|
||||
getWebAppKey,
|
||||
prepareMessageReplyInfo,
|
||||
} from '../../helpers';
|
||||
import {
|
||||
addActionHandler, getGlobal, setGlobal,
|
||||
@ -247,7 +248,8 @@ addActionHandler('sendBotCommand', (global, actions, payload): ActionReturnType
|
||||
const lastMessageId = selectChatLastMessageId(global, chat.id);
|
||||
|
||||
void sendBotCommand(
|
||||
chat, command, selectDraft(global, chat.id, threadId)?.replyInfo, selectSendAs(global, chat.id), lastMessageId,
|
||||
chat, threadId, command, selectDraft(global, chat.id, threadId)?.replyInfo, selectSendAs(global, chat.id),
|
||||
lastMessageId,
|
||||
);
|
||||
});
|
||||
|
||||
@ -270,7 +272,7 @@ addActionHandler('restartBot', async (global, actions, payload): Promise<void> =
|
||||
global = getGlobal();
|
||||
global = removeBlockedUser(global, bot.id);
|
||||
setGlobal(global);
|
||||
void sendBotCommand(chat, '/start', undefined, selectSendAs(global, chatId), lastMessageId);
|
||||
void sendBotCommand(chat, MAIN_THREAD_ID, '/start', undefined, selectSendAs(global, chatId), lastMessageId);
|
||||
});
|
||||
|
||||
addActionHandler('loadTopInlineBots', async (global): Promise<void> => {
|
||||
@ -1304,11 +1306,12 @@ async function searchInlineBot<T extends GlobalState>(global: T, {
|
||||
}
|
||||
|
||||
async function sendBotCommand(
|
||||
chat: ApiChat, command: string, replyInfo?: ApiInputMessageReplyInfo, sendAs?: ApiPeer, lastMessageId?: number,
|
||||
chat: ApiChat, threadId: ThreadId, command: string, replyInfo?: ApiInputMessageReplyInfo,
|
||||
sendAs?: ApiPeer, lastMessageId?: number,
|
||||
) {
|
||||
await callApi('sendMessage', {
|
||||
chat,
|
||||
replyInfo,
|
||||
replyInfo: prepareMessageReplyInfo(threadId, replyInfo),
|
||||
text: command,
|
||||
sendAs,
|
||||
lastMessageId,
|
||||
|
||||
@ -2,6 +2,7 @@ import type { TeactNode } from '../../lib/teact/teact';
|
||||
|
||||
import type {
|
||||
ApiAttachment,
|
||||
ApiInputMessageReplyInfo,
|
||||
ApiMessage,
|
||||
ApiMessageEntityTextUrl,
|
||||
ApiPeer,
|
||||
@ -573,3 +574,17 @@ export function groupMessageIdsByThreadId(
|
||||
|
||||
return grouped;
|
||||
}
|
||||
|
||||
export function prepareMessageReplyInfo(
|
||||
threadId: ThreadId, additionalReplyInfo?: ApiInputMessageReplyInfo,
|
||||
): ApiInputMessageReplyInfo | undefined {
|
||||
const isMainThread = threadId === MAIN_THREAD_ID;
|
||||
if (!additionalReplyInfo && isMainThread) return undefined;
|
||||
|
||||
return {
|
||||
type: 'message',
|
||||
...additionalReplyInfo,
|
||||
replyToMsgId: additionalReplyInfo?.replyToMsgId || Number(threadId),
|
||||
replyToTopId: additionalReplyInfo?.replyToTopId || (!isMainThread ? Number(threadId) : undefined),
|
||||
};
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ import {
|
||||
isOwnMessage,
|
||||
isServiceNotificationMessage,
|
||||
isUserRightBanned,
|
||||
prepareMessageReplyInfo,
|
||||
} from '../helpers';
|
||||
import { getMessageReplyInfo } from '../helpers/replies';
|
||||
import {
|
||||
@ -1446,17 +1447,8 @@ export function selectMessageReplyInfo<T extends GlobalState>(
|
||||
) {
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) return undefined;
|
||||
const isMainThread = threadId === MAIN_THREAD_ID;
|
||||
if (!additionalReplyInfo && isMainThread) return undefined;
|
||||
|
||||
const replyInfo: ApiInputMessageReplyInfo = {
|
||||
type: 'message',
|
||||
...additionalReplyInfo,
|
||||
replyToMsgId: additionalReplyInfo?.replyToMsgId || Number(threadId),
|
||||
replyToTopId: additionalReplyInfo?.replyToTopId || (!isMainThread ? Number(threadId) : undefined),
|
||||
};
|
||||
|
||||
return replyInfo;
|
||||
return prepareMessageReplyInfo(threadId, additionalReplyInfo);
|
||||
}
|
||||
|
||||
export function selectReplyMessage<T extends GlobalState>(global: T, message: ApiMessage) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user