Channel: Support direct messages deeplink (#6175)
This commit is contained in:
parent
3f64201451
commit
dbe78ad9e7
@ -1654,7 +1654,7 @@ addActionHandler('acceptChatInvite', async (global, actions, payload): Promise<v
|
|||||||
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
|
addActionHandler('openChatByUsername', async (global, actions, payload): Promise<void> => {
|
||||||
const {
|
const {
|
||||||
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts,
|
username, messageId, commentId, startParam, startAttach, attach, threadId, originalParts,
|
||||||
startApp, shouldStartMainApp, mode,
|
startApp, shouldStartMainApp, mode, isDirect,
|
||||||
text, onChatChanged, choose, ref, timestamp, linkContext,
|
text, onChatChanged, choose, ref, timestamp, linkContext,
|
||||||
tabId = getCurrentTabId(),
|
tabId = getCurrentTabId(),
|
||||||
} = payload;
|
} = payload;
|
||||||
@ -3433,7 +3433,13 @@ async function openChatByUsername<T extends GlobalState>(
|
|||||||
return;
|
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) {
|
if (!isCurrentChat) {
|
||||||
// Open temporary empty chat to make the click response feel faster
|
// Open temporary empty chat to make the click response feel faster
|
||||||
@ -3459,7 +3465,12 @@ async function openChatByUsername<T extends GlobalState>(
|
|||||||
return;
|
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,
|
isCurrentChat,
|
||||||
threadId,
|
threadId,
|
||||||
messageId: channelPostId,
|
messageId: channelPostId,
|
||||||
|
|||||||
@ -70,6 +70,7 @@ interface PublicUsernameOrBotLink {
|
|||||||
attach?: string;
|
attach?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
choose?: string;
|
choose?: string;
|
||||||
|
isDirect?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PrivateChannelLink {
|
interface PrivateChannelLink {
|
||||||
@ -146,6 +147,10 @@ type PublicMessageLinkBuilderParams = Omit<BuilderParams<PublicMessageLink>, 'is
|
|||||||
single?: string;
|
single?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type PublicUsernameOrBotLinkBuilderParams = Omit<BuilderParams<PublicUsernameOrBotLink>, 'isDirect'> & {
|
||||||
|
direct?: string;
|
||||||
|
};
|
||||||
|
|
||||||
const ELIGIBLE_HOSTNAMES = new Set(['t.me', 'telegram.me', 'telegram.dog']);
|
const ELIGIBLE_HOSTNAMES = new Set(['t.me', 'telegram.me', 'telegram.dog']);
|
||||||
|
|
||||||
export function isDeepLink(link: string): boolean {
|
export function isDeepLink(link: string): boolean {
|
||||||
@ -249,6 +254,7 @@ function parseTgLink(url: URL) {
|
|||||||
attach: queryParams.attach,
|
attach: queryParams.attach,
|
||||||
choose: queryParams.choose,
|
choose: queryParams.choose,
|
||||||
ref: queryParams.ref,
|
ref: queryParams.ref,
|
||||||
|
direct: queryParams.direct,
|
||||||
});
|
});
|
||||||
case 'privateChannelLink': {
|
case 'privateChannelLink': {
|
||||||
return buildPrivateChannelLink({ channelId: queryParams.channel });
|
return buildPrivateChannelLink({ channelId: queryParams.channel });
|
||||||
@ -355,6 +361,7 @@ function parseHttpLink(url: URL) {
|
|||||||
attach: queryParams.attach,
|
attach: queryParams.attach,
|
||||||
choose: queryParams.choose,
|
choose: queryParams.choose,
|
||||||
ref: queryParams.ref,
|
ref: queryParams.ref,
|
||||||
|
direct: queryParams.direct,
|
||||||
});
|
});
|
||||||
case 'privateChannelLink': {
|
case 'privateChannelLink': {
|
||||||
return buildPrivateChannelLink({ channelId: pathParams[1] });
|
return buildPrivateChannelLink({ channelId: pathParams[1] });
|
||||||
@ -605,7 +612,7 @@ function buildTelegramPassportLink(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildPublicUsernameOrBotLink(
|
function buildPublicUsernameOrBotLink(
|
||||||
params: BuilderParams<PublicUsernameOrBotLink>,
|
params: PublicUsernameOrBotLinkBuilderParams,
|
||||||
): BuilderReturnType<PublicUsernameOrBotLink> {
|
): BuilderReturnType<PublicUsernameOrBotLink> {
|
||||||
const {
|
const {
|
||||||
username,
|
username,
|
||||||
@ -618,6 +625,7 @@ function buildPublicUsernameOrBotLink(
|
|||||||
appName,
|
appName,
|
||||||
choose,
|
choose,
|
||||||
ref,
|
ref,
|
||||||
|
direct,
|
||||||
} = params;
|
} = params;
|
||||||
if (!username) {
|
if (!username) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -637,6 +645,7 @@ function buildPublicUsernameOrBotLink(
|
|||||||
text,
|
text,
|
||||||
choose,
|
choose,
|
||||||
ref,
|
ref,
|
||||||
|
isDirect: direct === '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,7 @@ export const processDeepLink = (url: string, linkContext?: LinkContext): boolean
|
|||||||
attach: parsedLink.attach,
|
attach: parsedLink.attach,
|
||||||
choose,
|
choose,
|
||||||
originalParts: [parsedLink.username, parsedLink.appName],
|
originalParts: [parsedLink.username, parsedLink.appName],
|
||||||
|
isDirect: parsedLink.isDirect,
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user