Mini App: Fix opening from t.me links (#4550)

This commit is contained in:
Alexander Zinchuk 2024-05-14 04:23:33 +02:00
parent 4ca1398e34
commit 1b3871fb34
10 changed files with 31 additions and 22 deletions

View File

@ -390,11 +390,12 @@ const Main: FC<OwnProps & StateProps> = ({
// Parse deep link // Parse deep link
useEffect(() => { useEffect(() => {
if (!isSynced) return;
const parsedInitialLocationHash = parseInitialLocationHash(); const parsedInitialLocationHash = parseInitialLocationHash();
if (parsedInitialLocationHash?.tgaddr) { if (parsedInitialLocationHash?.tgaddr) {
processDeepLink(decodeURIComponent(parsedInitialLocationHash.tgaddr)); processDeepLink(decodeURIComponent(parsedInitialLocationHash.tgaddr));
} }
}, []); }, [isSynced]);
useEffect(() => { useEffect(() => {
return window.electron?.on(ElectronEvent.DEEPLINK, (link: string) => { return window.electron?.on(ElectronEvent.DEEPLINK, (link: string) => {

View File

@ -29,7 +29,7 @@
margin-bottom: 0.25rem; margin-bottom: 0.25rem;
} }
.image { .media {
max-width: 100%; max-width: 100%;
height: auto; height: auto !important;
} }

View File

@ -71,7 +71,7 @@ const MessageListBotInfo: FC<OwnProps & StateProps> = ({
> >
{botInfoPhotoUrl && ( {botInfoPhotoUrl && (
<img <img
className={styles.image} className={styles.media}
src={botInfoPhotoUrl} src={botInfoPhotoUrl}
width={botInfoRealDimensions?.width} width={botInfoRealDimensions?.width}
height={botInfoRealDimensions?.height} height={botInfoRealDimensions?.height}
@ -81,6 +81,7 @@ const MessageListBotInfo: FC<OwnProps & StateProps> = ({
{botInfoGifUrl && ( {botInfoGifUrl && (
<OptimizedVideo <OptimizedVideo
canPlay canPlay
className={styles.media}
src={botInfoGifUrl} src={botInfoGifUrl}
loop loop
disablePictureInPicture disablePictureInPicture
@ -91,8 +92,10 @@ const MessageListBotInfo: FC<OwnProps & StateProps> = ({
)} )}
{botInfoDimensions && !botInfoPhotoUrl && !botInfoGifUrl && ( {botInfoDimensions && !botInfoPhotoUrl && !botInfoGifUrl && (
<Skeleton <Skeleton
className={styles.media}
width={botInfoRealDimensions?.width} width={botInfoRealDimensions?.width}
height={botInfoRealDimensions?.height} height={botInfoRealDimensions?.height}
forceAspectRatio
/> />
)} )}
{botInfo.description && ( {botInfo.description && (

View File

@ -35,6 +35,7 @@ import {
selectDraft, selectDraft,
selectIsTrustedBot, selectIsTrustedBot,
selectMessageReplyInfo, selectMessageReplyInfo,
selectPeer,
selectSendAs, selectSendAs,
selectTabState, selectTabState,
selectUser, selectUser,
@ -529,7 +530,7 @@ addActionHandler('requestWebView', async (global, actions, payload): Promise<voi
const bot = selectUser(global, botId); const bot = selectUser(global, botId);
if (!bot) return; if (!bot) return;
const peer = selectChat(global, peerId); const peer = selectPeer(global, peerId);
if (!peer) return; if (!peer) return;
if (!selectIsTrustedBot(global, botId)) { if (!selectIsTrustedBot(global, botId)) {
@ -548,15 +549,12 @@ addActionHandler('requestWebView', async (global, actions, payload): Promise<voi
} }
const currentMessageList = selectCurrentMessageList(global, tabId); const currentMessageList = selectCurrentMessageList(global, tabId);
if (!currentMessageList) {
return;
}
const { chatId, threadId } = currentMessageList; const { chatId, threadId = MAIN_THREAD_ID } = currentMessageList || {};
const draftReplyInfo = chatId ? selectDraft(global, chatId, threadId)?.replyInfo : undefined; const draftReplyInfo = chatId ? selectDraft(global, chatId, threadId)?.replyInfo : undefined;
const replyInfo = selectMessageReplyInfo(global, chatId, threadId, draftReplyInfo); const replyInfo = chatId ? selectMessageReplyInfo(global, chatId, threadId, draftReplyInfo) : undefined;
const sendAs = selectSendAs(global, chatId); const sendAs = chatId ? selectSendAs(global, chatId) : undefined;
const result = await callApi('requestWebView', { const result = await callApi('requestWebView', {
url, url,
bot, bot,
@ -774,13 +772,12 @@ addActionHandler('markBotTrusted', (global, actions, payload): ActionReturnType
setGlobal(global); setGlobal(global);
}); });
addActionHandler('loadAttachBots', async (global, actions, payload): Promise<void> => { addActionHandler('loadAttachBots', async (global): Promise<void> => {
const { hash } = payload || {}; await loadAttachBots(global);
const result = await loadAttachBots(global, hash);
requestActionTimeout({ requestActionTimeout({
action: 'loadAttachBots', action: 'loadAttachBots',
payload: { hash: result?.hash }, payload: undefined,
}, GENERAL_REFETCH_INTERVAL); }, GENERAL_REFETCH_INTERVAL);
}); });

View File

@ -3039,11 +3039,11 @@ async function openChatByUsername<T extends GlobalState>(
if (startAttach !== undefined && !attach) { if (startAttach !== undefined && !attach) {
const bot = await getAttachBotOrNotify(global, actions, username, tabId); const bot = await getAttachBotOrNotify(global, actions, username, tabId);
if (!currentChat || !bot) return; if (!bot) return;
actions.callAttachBot({ actions.callAttachBot({
bot, bot,
chatId: currentChat.id, chatId: currentChat?.id || bot.id,
startParam: startAttach, startParam: startAttach,
tabId, tabId,
}); });

View File

@ -153,7 +153,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
break; break;
case 'updateAttachMenuBots': case 'updateAttachMenuBots':
actions.loadAttachBots({ hash: global.attachMenu.hash }); actions.loadAttachBots();
break; break;
case 'updatePremiumFloodWait': { case 'updatePremiumFloodWait': {

View File

@ -266,6 +266,7 @@ export function serializeGlobal<T extends GlobalState>(global: T) {
'authPhoneNumber', 'authPhoneNumber',
'authRememberMe', 'authRememberMe',
'authNearestCountry', 'authNearestCountry',
'attachMenu',
'currentUserId', 'currentUserId',
'contactList', 'contactList',
'topPeers', 'topPeers',
@ -343,11 +344,14 @@ function reduceUsers<T extends GlobalState>(global: T): GlobalState['users'] {
.map((message) => message.content.storyData?.peerId || message.content.webPage?.story?.peerId) .map((message) => message.content.storyData?.peerId || message.content.webPage?.story?.peerId)
.filter((id): id is string => Boolean(id) && isUserId(id)); .filter((id): id is string => Boolean(id) && isUserId(id));
const attachBotIds = Object.keys(global.attachMenu?.bots || {});
const idsToSave = unique([ const idsToSave = unique([
...currentUserId ? [currentUserId] : [], ...currentUserId ? [currentUserId] : [],
...currentChatIds, ...currentChatIds,
...chatStoriesUserIds, ...chatStoriesUserIds,
...visibleUserIds || [], ...visibleUserIds || [],
...attachBotIds,
...global.topPeers.userIds || [], ...global.topPeers.userIds || [],
...getOrderedIds(ARCHIVED_FOLDER_ID)?.slice(0, GLOBAL_STATE_CACHE_ARCHIVED_CHAT_LIST_LIMIT).filter(isUserId) || [], ...getOrderedIds(ARCHIVED_FOLDER_ID)?.slice(0, GLOBAL_STATE_CACHE_ARCHIVED_CHAT_LIST_LIMIT).filter(isUserId) || [],
...getOrderedIds(ALL_FOLDER_ID)?.filter(isUserId) || [], ...getOrderedIds(ALL_FOLDER_ID)?.filter(isUserId) || [],

View File

@ -1561,7 +1561,7 @@ export interface ActionPayloads {
attach?: string; attach?: string;
startApp?: string; startApp?: string;
text?: string; text?: string;
originalParts?: string[]; originalParts?: (string | undefined)[];
} & WithTabId; } & WithTabId;
processBoostParameters: { processBoostParameters: {
usernameOrId: string; usernameOrId: string;
@ -2753,9 +2753,7 @@ export interface ActionPayloads {
buttonText: string; buttonText: string;
}; };
loadAttachBots: { loadAttachBots: undefined;
hash?: string;
} | undefined;
toggleAttachBot: { toggleAttachBot: {
botId: string; botId: string;

View File

@ -61,6 +61,7 @@ interface PublicUsernameOrBotLink {
username: string; username: string;
start?: string; start?: string;
startApp?: string; startApp?: string;
appName?: string;
startAttach?: string; startAttach?: string;
attach?: string; attach?: string;
text?: string; text?: string;
@ -197,6 +198,7 @@ function parseTgLink(url: URL) {
username: queryParams.domain, username: queryParams.domain,
start: queryParams.start, start: queryParams.start,
text: queryParams.text, text: queryParams.text,
appName: queryParams.appname,
startApp: queryParams.startapp, startApp: queryParams.startapp,
startAttach: queryParams.startattach, startAttach: queryParams.startattach,
attach: queryParams.attach, attach: queryParams.attach,
@ -289,6 +291,7 @@ function parseHttpLink(url: URL) {
start: queryParams.start, start: queryParams.start,
text: queryParams.text, text: queryParams.text,
startApp: queryParams.startapp, startApp: queryParams.startapp,
appName: undefined,
startAttach: queryParams.startattach, startAttach: queryParams.startattach,
attach: queryParams.attach, attach: queryParams.attach,
}); });
@ -519,6 +522,7 @@ function buildPublicUsernameOrBotLink(
startApp, startApp,
startAttach, startAttach,
attach, attach,
appName,
} = params; } = params;
if (!username) { if (!username) {
return undefined; return undefined;
@ -531,6 +535,7 @@ function buildPublicUsernameOrBotLink(
username, username,
start, start,
startApp, startApp,
appName,
startAttach, startAttach,
attach, attach,
text, text,

View File

@ -25,6 +25,7 @@ export const processDeepLink = (url: string): boolean => {
startApp: parsedLink.startApp, startApp: parsedLink.startApp,
startAttach: parsedLink.startAttach, startAttach: parsedLink.startAttach,
attach: parsedLink.attach, attach: parsedLink.attach,
originalParts: [parsedLink.username, parsedLink.appName],
}); });
return true; return true;
case 'businessChatLink': case 'businessChatLink':