Link: Open unsupported t.me links (#4880)
This commit is contained in:
parent
ac2f605649
commit
ee52eae6ac
@ -1244,7 +1244,7 @@ addActionHandler('openChatByPhoneNumber', async (global, actions, payload): Prom
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnType => {
|
addActionHandler('openTelegramLink', async (global, actions, payload): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
url,
|
url,
|
||||||
tabId = getCurrentTabId(),
|
tabId = getCurrentTabId(),
|
||||||
@ -1361,6 +1361,10 @@ addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnTyp
|
|||||||
const messageId = part3 ? Number(part3) : undefined;
|
const messageId = part3 ? Number(part3) : undefined;
|
||||||
const commentId = params.comment ? Number(params.comment) : undefined;
|
const commentId = params.comment ? Number(params.comment) : undefined;
|
||||||
|
|
||||||
|
const isWebApp = await checkWebAppExists(global, part1, part2);
|
||||||
|
|
||||||
|
const shouldTryOpenChat = (part1 && !part2) || isWebApp;
|
||||||
|
|
||||||
if (params.hasOwnProperty('voicechat') || params.hasOwnProperty('livestream')) {
|
if (params.hasOwnProperty('voicechat') || params.hasOwnProperty('livestream')) {
|
||||||
joinVoiceChatByLink({
|
joinVoiceChatByLink({
|
||||||
username: part1,
|
username: part1,
|
||||||
@ -1410,7 +1414,7 @@ addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnTyp
|
|||||||
startParam: params.startattach || params.startapp,
|
startParam: params.startattach || params.startapp,
|
||||||
tabId,
|
tabId,
|
||||||
});
|
});
|
||||||
} else {
|
} else if (shouldTryOpenChat) {
|
||||||
openChatByUsernameAction({
|
openChatByUsernameAction({
|
||||||
username: part1,
|
username: part1,
|
||||||
messageId: messageId || Number(chatOrChannelPostId),
|
messageId: messageId || Number(chatOrChannelPostId),
|
||||||
@ -1423,6 +1427,10 @@ addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnTyp
|
|||||||
originalParts: [part1, part2, part3],
|
originalParts: [part1, part2, part3],
|
||||||
tabId,
|
tabId,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
actions.openUrl({
|
||||||
|
url, shouldSkipModal: true, tabId, ignoreDeepLinks: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2954,6 +2962,20 @@ export async function fetchChatByUsername<T extends GlobalState>(
|
|||||||
return chat;
|
return chat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function checkWebAppExists<T extends GlobalState>(
|
||||||
|
global: T, botName: string, appName: string,
|
||||||
|
) {
|
||||||
|
if (!botName || !appName) return false;
|
||||||
|
global = getGlobal();
|
||||||
|
const chatByUsername = await fetchChatByUsername(global, botName);
|
||||||
|
const bot = chatByUsername && selectUser(global, chatByUsername.id);
|
||||||
|
const botApp = bot && await callApi('fetchBotApp', {
|
||||||
|
bot,
|
||||||
|
appName,
|
||||||
|
});
|
||||||
|
return Boolean(botApp);
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchChatByPhoneNumber<T extends GlobalState>(global: T, phoneNumber: string) {
|
export async function fetchChatByPhoneNumber<T extends GlobalState>(global: T, phoneNumber: string) {
|
||||||
global = getGlobal();
|
global = getGlobal();
|
||||||
const localUser = selectUserByPhoneNumber(global, phoneNumber);
|
const localUser = selectUserByPhoneNumber(global, phoneNumber);
|
||||||
|
|||||||
@ -1752,10 +1752,12 @@ addActionHandler('readAllMentions', (global, actions, payload): ActionReturnType
|
|||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('openUrl', (global, actions, payload): ActionReturnType => {
|
addActionHandler('openUrl', (global, actions, payload): ActionReturnType => {
|
||||||
const { url, shouldSkipModal, tabId = getCurrentTabId() } = payload;
|
const {
|
||||||
|
url, shouldSkipModal, ignoreDeepLinks, tabId = getCurrentTabId(),
|
||||||
|
} = payload;
|
||||||
const urlWithProtocol = ensureProtocol(url)!;
|
const urlWithProtocol = ensureProtocol(url)!;
|
||||||
|
|
||||||
if (isDeepLink(urlWithProtocol)) {
|
if (!ignoreDeepLinks && isDeepLink(urlWithProtocol)) {
|
||||||
actions.closeStoryViewer({ tabId });
|
actions.closeStoryViewer({ tabId });
|
||||||
actions.closePaymentModal({ tabId });
|
actions.closePaymentModal({ tabId });
|
||||||
|
|
||||||
|
|||||||
@ -3050,6 +3050,7 @@ export interface ActionPayloads {
|
|||||||
openUrl: {
|
openUrl: {
|
||||||
url: string;
|
url: string;
|
||||||
shouldSkipModal?: boolean;
|
shouldSkipModal?: boolean;
|
||||||
|
ignoreDeepLinks?: boolean;
|
||||||
} & WithTabId;
|
} & WithTabId;
|
||||||
openMapModal: {
|
openMapModal: {
|
||||||
geoPoint: ApiGeoPoint;
|
geoPoint: ApiGeoPoint;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user