Channel: Support direct messages deeplink (#6175)

This commit is contained in:
zubiden 2025-09-09 20:26:10 +02:00 committed by Alexander Zinchuk
parent 3f64201451
commit dbe78ad9e7
3 changed files with 25 additions and 4 deletions

View File

@ -1654,7 +1654,7 @@ addActionHandler('acceptChatInvite', async (global, actions, payload): Promise<v
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
const {
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts,
startApp, shouldStartMainApp, mode,
startApp, shouldStartMainApp, mode, isDirect,
text, onChatChanged, choose, ref, timestamp, linkContext,
tabId = getCurrentTabId(),
} = payload;
@ -3433,7 +3433,13 @@ async function openChatByUsername<T extends GlobalState>(
return;
}
const isCurrentChat = currentChat?.usernames?.some((c) => c.username === username);
const localChat = selectChatByUsername(global, username);
const localDirectChat = isDirect && localChat?.linkedMonoforumId && !localChat.isMonoforum
? selectChat(global, localChat.linkedMonoforumId) : undefined;
const isCurrentChat = !isDirect
? currentChat?.usernames?.some((c) => c.username === username)
: localDirectChat?.id === currentChat?.id;
if (!isCurrentChat) {
// Open temporary empty chat to make the click response feel faster
@ -3459,7 +3465,12 @@ async function openChatByUsername<T extends GlobalState>(
return;
}
openChatWithParams(global, actions, chat, {
const monoforumChat = isDirect && !chat.isMonoforum && chat.linkedMonoforumId
? selectChat(global, chat.linkedMonoforumId) : undefined;
const targetChat = (isDirect && monoforumChat) || chat;
openChatWithParams(global, actions, targetChat, {
isCurrentChat,
threadId,
messageId: channelPostId,

View File

@ -70,6 +70,7 @@ interface PublicUsernameOrBotLink {
attach?: string;
text?: string;
choose?: string;
isDirect?: boolean;
}
interface PrivateChannelLink {
@ -146,6 +147,10 @@ type PublicMessageLinkBuilderParams = Omit<BuilderParams<PublicMessageLink>, 'is
single?: string;
};
type PublicUsernameOrBotLinkBuilderParams = Omit<BuilderParams<PublicUsernameOrBotLink>, 'isDirect'> & {
direct?: string;
};
const ELIGIBLE_HOSTNAMES = new Set(['t.me', 'telegram.me', 'telegram.dog']);
export function isDeepLink(link: string): boolean {
@ -249,6 +254,7 @@ function parseTgLink(url: URL) {
attach: queryParams.attach,
choose: queryParams.choose,
ref: queryParams.ref,
direct: queryParams.direct,
});
case 'privateChannelLink': {
return buildPrivateChannelLink({ channelId: queryParams.channel });
@ -355,6 +361,7 @@ function parseHttpLink(url: URL) {
attach: queryParams.attach,
choose: queryParams.choose,
ref: queryParams.ref,
direct: queryParams.direct,
});
case 'privateChannelLink': {
return buildPrivateChannelLink({ channelId: pathParams[1] });
@ -605,7 +612,7 @@ function buildTelegramPassportLink(
}
function buildPublicUsernameOrBotLink(
params: BuilderParams<PublicUsernameOrBotLink>,
params: PublicUsernameOrBotLinkBuilderParams,
): BuilderReturnType<PublicUsernameOrBotLink> {
const {
username,
@ -618,6 +625,7 @@ function buildPublicUsernameOrBotLink(
appName,
choose,
ref,
direct,
} = params;
if (!username) {
return undefined;
@ -637,6 +645,7 @@ function buildPublicUsernameOrBotLink(
text,
choose,
ref,
isDirect: direct === '',
};
}

View File

@ -49,6 +49,7 @@ export const processDeepLink = (url: string, linkContext?: LinkContext): boolean
attach: parsedLink.attach,
choose,
originalParts: [parsedLink.username, parsedLink.appName],
isDirect: parsedLink.isDirect,
});
return true;
}