Mini App: Fix opening from t.me links (#4550)
This commit is contained in:
parent
4ca1398e34
commit
1b3871fb34
@ -390,11 +390,12 @@ const Main: FC<OwnProps & StateProps> = ({
|
||||
|
||||
// Parse deep link
|
||||
useEffect(() => {
|
||||
if (!isSynced) return;
|
||||
const parsedInitialLocationHash = parseInitialLocationHash();
|
||||
if (parsedInitialLocationHash?.tgaddr) {
|
||||
processDeepLink(decodeURIComponent(parsedInitialLocationHash.tgaddr));
|
||||
}
|
||||
}, []);
|
||||
}, [isSynced]);
|
||||
|
||||
useEffect(() => {
|
||||
return window.electron?.on(ElectronEvent.DEEPLINK, (link: string) => {
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
|
||||
.image {
|
||||
.media {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
height: auto !important;
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ const MessageListBotInfo: FC<OwnProps & StateProps> = ({
|
||||
>
|
||||
{botInfoPhotoUrl && (
|
||||
<img
|
||||
className={styles.image}
|
||||
className={styles.media}
|
||||
src={botInfoPhotoUrl}
|
||||
width={botInfoRealDimensions?.width}
|
||||
height={botInfoRealDimensions?.height}
|
||||
@ -81,6 +81,7 @@ const MessageListBotInfo: FC<OwnProps & StateProps> = ({
|
||||
{botInfoGifUrl && (
|
||||
<OptimizedVideo
|
||||
canPlay
|
||||
className={styles.media}
|
||||
src={botInfoGifUrl}
|
||||
loop
|
||||
disablePictureInPicture
|
||||
@ -91,8 +92,10 @@ const MessageListBotInfo: FC<OwnProps & StateProps> = ({
|
||||
)}
|
||||
{botInfoDimensions && !botInfoPhotoUrl && !botInfoGifUrl && (
|
||||
<Skeleton
|
||||
className={styles.media}
|
||||
width={botInfoRealDimensions?.width}
|
||||
height={botInfoRealDimensions?.height}
|
||||
forceAspectRatio
|
||||
/>
|
||||
)}
|
||||
{botInfo.description && (
|
||||
|
||||
@ -35,6 +35,7 @@ import {
|
||||
selectDraft,
|
||||
selectIsTrustedBot,
|
||||
selectMessageReplyInfo,
|
||||
selectPeer,
|
||||
selectSendAs,
|
||||
selectTabState,
|
||||
selectUser,
|
||||
@ -529,7 +530,7 @@ addActionHandler('requestWebView', async (global, actions, payload): Promise<voi
|
||||
|
||||
const bot = selectUser(global, botId);
|
||||
if (!bot) return;
|
||||
const peer = selectChat(global, peerId);
|
||||
const peer = selectPeer(global, peerId);
|
||||
if (!peer) return;
|
||||
|
||||
if (!selectIsTrustedBot(global, botId)) {
|
||||
@ -548,15 +549,12 @@ addActionHandler('requestWebView', async (global, actions, payload): Promise<voi
|
||||
}
|
||||
|
||||
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 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', {
|
||||
url,
|
||||
bot,
|
||||
@ -774,13 +772,12 @@ addActionHandler('markBotTrusted', (global, actions, payload): ActionReturnType
|
||||
setGlobal(global);
|
||||
});
|
||||
|
||||
addActionHandler('loadAttachBots', async (global, actions, payload): Promise<void> => {
|
||||
const { hash } = payload || {};
|
||||
const result = await loadAttachBots(global, hash);
|
||||
addActionHandler('loadAttachBots', async (global): Promise<void> => {
|
||||
await loadAttachBots(global);
|
||||
|
||||
requestActionTimeout({
|
||||
action: 'loadAttachBots',
|
||||
payload: { hash: result?.hash },
|
||||
payload: undefined,
|
||||
}, GENERAL_REFETCH_INTERVAL);
|
||||
});
|
||||
|
||||
|
||||
@ -3039,11 +3039,11 @@ async function openChatByUsername<T extends GlobalState>(
|
||||
if (startAttach !== undefined && !attach) {
|
||||
const bot = await getAttachBotOrNotify(global, actions, username, tabId);
|
||||
|
||||
if (!currentChat || !bot) return;
|
||||
if (!bot) return;
|
||||
|
||||
actions.callAttachBot({
|
||||
bot,
|
||||
chatId: currentChat.id,
|
||||
chatId: currentChat?.id || bot.id,
|
||||
startParam: startAttach,
|
||||
tabId,
|
||||
});
|
||||
|
||||
@ -153,7 +153,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
break;
|
||||
|
||||
case 'updateAttachMenuBots':
|
||||
actions.loadAttachBots({ hash: global.attachMenu.hash });
|
||||
actions.loadAttachBots();
|
||||
break;
|
||||
|
||||
case 'updatePremiumFloodWait': {
|
||||
|
||||
@ -266,6 +266,7 @@ export function serializeGlobal<T extends GlobalState>(global: T) {
|
||||
'authPhoneNumber',
|
||||
'authRememberMe',
|
||||
'authNearestCountry',
|
||||
'attachMenu',
|
||||
'currentUserId',
|
||||
'contactList',
|
||||
'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)
|
||||
.filter((id): id is string => Boolean(id) && isUserId(id));
|
||||
|
||||
const attachBotIds = Object.keys(global.attachMenu?.bots || {});
|
||||
|
||||
const idsToSave = unique([
|
||||
...currentUserId ? [currentUserId] : [],
|
||||
...currentChatIds,
|
||||
...chatStoriesUserIds,
|
||||
...visibleUserIds || [],
|
||||
...attachBotIds,
|
||||
...global.topPeers.userIds || [],
|
||||
...getOrderedIds(ARCHIVED_FOLDER_ID)?.slice(0, GLOBAL_STATE_CACHE_ARCHIVED_CHAT_LIST_LIMIT).filter(isUserId) || [],
|
||||
...getOrderedIds(ALL_FOLDER_ID)?.filter(isUserId) || [],
|
||||
|
||||
@ -1561,7 +1561,7 @@ export interface ActionPayloads {
|
||||
attach?: string;
|
||||
startApp?: string;
|
||||
text?: string;
|
||||
originalParts?: string[];
|
||||
originalParts?: (string | undefined)[];
|
||||
} & WithTabId;
|
||||
processBoostParameters: {
|
||||
usernameOrId: string;
|
||||
@ -2753,9 +2753,7 @@ export interface ActionPayloads {
|
||||
buttonText: string;
|
||||
};
|
||||
|
||||
loadAttachBots: {
|
||||
hash?: string;
|
||||
} | undefined;
|
||||
loadAttachBots: undefined;
|
||||
|
||||
toggleAttachBot: {
|
||||
botId: string;
|
||||
|
||||
@ -61,6 +61,7 @@ interface PublicUsernameOrBotLink {
|
||||
username: string;
|
||||
start?: string;
|
||||
startApp?: string;
|
||||
appName?: string;
|
||||
startAttach?: string;
|
||||
attach?: string;
|
||||
text?: string;
|
||||
@ -197,6 +198,7 @@ function parseTgLink(url: URL) {
|
||||
username: queryParams.domain,
|
||||
start: queryParams.start,
|
||||
text: queryParams.text,
|
||||
appName: queryParams.appname,
|
||||
startApp: queryParams.startapp,
|
||||
startAttach: queryParams.startattach,
|
||||
attach: queryParams.attach,
|
||||
@ -289,6 +291,7 @@ function parseHttpLink(url: URL) {
|
||||
start: queryParams.start,
|
||||
text: queryParams.text,
|
||||
startApp: queryParams.startapp,
|
||||
appName: undefined,
|
||||
startAttach: queryParams.startattach,
|
||||
attach: queryParams.attach,
|
||||
});
|
||||
@ -519,6 +522,7 @@ function buildPublicUsernameOrBotLink(
|
||||
startApp,
|
||||
startAttach,
|
||||
attach,
|
||||
appName,
|
||||
} = params;
|
||||
if (!username) {
|
||||
return undefined;
|
||||
@ -531,6 +535,7 @@ function buildPublicUsernameOrBotLink(
|
||||
username,
|
||||
start,
|
||||
startApp,
|
||||
appName,
|
||||
startAttach,
|
||||
attach,
|
||||
text,
|
||||
|
||||
@ -25,6 +25,7 @@ export const processDeepLink = (url: string): boolean => {
|
||||
startApp: parsedLink.startApp,
|
||||
startAttach: parsedLink.startAttach,
|
||||
attach: parsedLink.attach,
|
||||
originalParts: [parsedLink.username, parsedLink.appName],
|
||||
});
|
||||
return true;
|
||||
case 'businessChatLink':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user