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 { ApiKeyboardButton, ApiMessage } from '../../../api/types';
import type { ActionPayloads } from '../../../global/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 renderKeyboardButtonText from '../composer/helpers/renderKeyboardButtonText';
import useOldLang from '../../../hooks/useOldLang'; import useOldLang from '../../../hooks/useOldLang';
@ -26,10 +26,15 @@ const InlineButtons: FC<OwnProps> = ({ message, onClick }) => {
const { type } = button; const { type } = button;
switch (type) { switch (type) {
case 'url': { 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" />; return <Icon className="corner-icon" name="arrow-right" />;
} }
break;
return;
} }
case 'urlAuth': case 'urlAuth':
return <Icon className="corner-icon" name="arrow-right" />; return <Icon className="corner-icon" name="arrow-right" />;
@ -55,7 +60,8 @@ const InlineButtons: FC<OwnProps> = ({ message, onClick }) => {
} }
break; break;
} }
return undefined;
return;
}; };
const buttonTexts = useMemo(() => { const buttonTexts = useMemo(() => {

View File

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