Message / Inline Buttons: Show mini-app icon for t.me links

This commit is contained in:
Alexander Zinchuk 2025-10-15 19:57:18 +02:00
parent 980fb6ef41
commit 3c3e8401db
2 changed files with 20 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import { memo, useMemo } from '../../../lib/teact/teact';
import type { ApiKeyboardButton, ApiMessage } from '../../../api/types';
import type { ActionPayloads } from '../../../global/types';
import { RE_TME_LINK } from '../../../config';
import { RE_TME_LINK, TME_LINK_PREFIX } from '../../../config';
import renderKeyboardButtonText from '../composer/helpers/renderKeyboardButtonText';
import useOldLang from '../../../hooks/useOldLang';
@ -26,10 +26,15 @@ const InlineButtons: FC<OwnProps> = ({ message, onClick }) => {
const { type } = button;
switch (type) {
case 'url': {
if (!RE_TME_LINK.test(button.url)) {
const { url } = button;
if (url.startsWith(TME_LINK_PREFIX) && url.includes('?startapp')) {
return <Icon className="corner-icon" name="webapp" />;
} else if (!RE_TME_LINK.test(url)) {
return <Icon className="corner-icon" name="arrow-right" />;
}
break;
return;
}
case 'urlAuth':
return <Icon className="corner-icon" name="arrow-right" />;
@ -55,7 +60,8 @@ const InlineButtons: FC<OwnProps> = ({ message, onClick }) => {
}
break;
}
return undefined;
return;
};
const buttonTexts = useMemo(() => {

View File

@ -108,23 +108,28 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur
case 'command':
actions.sendBotCommand({ command: button.text, tabId });
break;
case 'url': {
const { url } = button;
actions.openUrl({ url, tabId, linkContext: { type: 'message', chatId, messageId, threadId } });
break;
}
case 'copy': {
copyTextToClipboard(button.copyText);
actions.showNotification({ message: oldTranslate('ExactTextCopied', button.copyText), tabId });
break;
}
case 'callback': {
void answerCallbackButton(global, actions, chat, messageId, threadId, button.data, undefined, tabId);
break;
}
case 'requestPoll':
actions.openPollModal({ isQuiz: button.isQuiz, tabId });
break;
case 'requestPhone': {
const user = global.currentUserId ? selectUser(global, global.currentUserId) : undefined;
if (!user) {
@ -141,6 +146,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur
});
break;
}
case 'receipt': {
const { receiptMessageId } = button;
actions.getReceipt({
@ -148,6 +154,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur
});
break;
}
case 'buy': {
actions.openInvoice({
type: 'message',
@ -157,10 +164,12 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur
});
break;
}
case 'game': {
void answerCallbackButton(global, actions, chat, messageId, threadId, undefined, true, tabId);
break;
}
case 'switchBotInline': {
const { query, isSamePeer } = button;
actions.switchBotInline({
@ -207,6 +216,7 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur
});
break;
}
case 'urlAuth': {
const { url } = button;
actions.requestBotUrlAuth({