Support new t.me format (#1521)
This commit is contained in:
parent
394b91533b
commit
13de57df49
@ -3,7 +3,7 @@ import { getDispatch } from '../../lib/teact/teactn';
|
|||||||
import convertPunycode from '../../lib/punycode';
|
import convertPunycode from '../../lib/punycode';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DEBUG, RE_TG_LINK, RE_TME_ADDSTICKERS_LINK, RE_TME_INVITE_LINK, RE_TME_LINK,
|
DEBUG, RE_TG_LINK, RE_TME_LINK,
|
||||||
} from '../../config';
|
} from '../../config';
|
||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
|
|
||||||
@ -30,8 +30,7 @@ const SafeLink: FC<OwnProps> = ({
|
|||||||
const handleClick = useCallback((e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
const handleClick = useCallback((e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
||||||
if (
|
if (
|
||||||
e.ctrlKey || e.altKey || e.shiftKey || e.metaKey
|
e.ctrlKey || e.altKey || e.shiftKey || e.metaKey
|
||||||
|| !url || (!url.match(RE_TME_LINK) && !url.match(RE_TME_INVITE_LINK) && !url.match(RE_TG_LINK)
|
|| !url || (!url.match(RE_TME_LINK) && !url.match(RE_TG_LINK))
|
||||||
&& !url.match(RE_TME_ADDSTICKERS_LINK))
|
|
||||||
) {
|
) {
|
||||||
if (isNotSafe) {
|
if (isNotSafe) {
|
||||||
toggleSafeLinkModal({ url });
|
toggleSafeLinkModal({ url });
|
||||||
|
|||||||
@ -140,10 +140,7 @@ export const CONTENT_TYPES_WITH_PREVIEW = new Set([
|
|||||||
export const RE_LINK_TEMPLATE = '((ftp|https?):\\/\\/)?((www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,63})\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)';
|
export const RE_LINK_TEMPLATE = '((ftp|https?):\\/\\/)?((www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,63})\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)';
|
||||||
export const RE_MENTION_TEMPLATE = '(@[\\w\\d_-]+)';
|
export const RE_MENTION_TEMPLATE = '(@[\\w\\d_-]+)';
|
||||||
export const RE_TG_LINK = /^tg:(\/\/)?([?=&\d\w_-]+)?/gm;
|
export const RE_TG_LINK = /^tg:(\/\/)?([?=&\d\w_-]+)?/gm;
|
||||||
// eslint-disable-next-line max-len
|
export const RE_TME_LINK = /^(?:https?:\/\/)?(?:t\.me\/)/gm;
|
||||||
export const RE_TME_LINK = /^(?:https?:\/\/)?(?:t\.me\/)([\d\w_]+)(?:\/([\d]+))?(?:\/([\d]+)(?:\?([\w]+)=([\d]+))?)?$/gm;
|
|
||||||
export const RE_TME_INVITE_LINK = /^(?:https?:\/\/)?(?:t\.me\/joinchat\/)([\d\w_-]+)?$/gm;
|
|
||||||
export const RE_TME_ADDSTICKERS_LINK = /^(?:https?:\/\/)?(?:t\.me\/addstickers\/)([\d\w_-]+)$/gm;
|
|
||||||
|
|
||||||
// MTProto constants
|
// MTProto constants
|
||||||
export const SERVICE_NOTIFICATIONS_USER_ID = 777000;
|
export const SERVICE_NOTIFICATIONS_USER_ID = 777000;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { ApiChat } from '../../../api/types';
|
|||||||
import { InlineBotSettings } from '../../../types';
|
import { InlineBotSettings } from '../../../types';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
RE_TG_LINK, RE_TME_ADDSTICKERS_LINK, RE_TME_INVITE_LINK, RE_TME_LINK,
|
RE_TG_LINK, RE_TME_LINK,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { callApi } from '../../../api/gramjs';
|
import { callApi } from '../../../api/gramjs';
|
||||||
import {
|
import {
|
||||||
@ -30,8 +30,7 @@ addReducer('clickInlineButton', (global, actions, payload) => {
|
|||||||
actions.sendBotCommand({ command: button.value });
|
actions.sendBotCommand({ command: button.value });
|
||||||
break;
|
break;
|
||||||
case 'url':
|
case 'url':
|
||||||
if (button.value.match(RE_TME_INVITE_LINK) || button.value.match(RE_TME_LINK) || button.value.match(RE_TG_LINK)
|
if (button.value.match(RE_TME_LINK) || button.value.match(RE_TG_LINK)) {
|
||||||
|| button.value.match(RE_TME_ADDSTICKERS_LINK)) {
|
|
||||||
actions.openTelegramLink({ url: button.value });
|
actions.openTelegramLink({ url: button.value });
|
||||||
} else {
|
} else {
|
||||||
actions.toggleSafeLinkModal({ url: button.value });
|
actions.toggleSafeLinkModal({ url: button.value });
|
||||||
|
|||||||
@ -12,10 +12,8 @@ import {
|
|||||||
ARCHIVED_FOLDER_ID,
|
ARCHIVED_FOLDER_ID,
|
||||||
TOP_CHAT_MESSAGES_PRELOAD_LIMIT,
|
TOP_CHAT_MESSAGES_PRELOAD_LIMIT,
|
||||||
CHAT_LIST_LOAD_SLICE,
|
CHAT_LIST_LOAD_SLICE,
|
||||||
RE_TME_INVITE_LINK,
|
|
||||||
RE_TME_LINK,
|
|
||||||
TIPS_USERNAME,
|
TIPS_USERNAME,
|
||||||
LOCALIZED_TIPS, RE_TG_LINK, RE_TME_ADDSTICKERS_LINK, SERVICE_NOTIFICATIONS_USER_ID,
|
LOCALIZED_TIPS, RE_TG_LINK, SERVICE_NOTIFICATIONS_USER_ID,
|
||||||
} from '../../../config';
|
} from '../../../config';
|
||||||
import { callApi } from '../../../api/gramjs';
|
import { callApi } from '../../../api/gramjs';
|
||||||
import {
|
import {
|
||||||
@ -534,42 +532,50 @@ addReducer('openChatByInvite', (global, actions, payload) => {
|
|||||||
|
|
||||||
addReducer('openTelegramLink', (global, actions, payload) => {
|
addReducer('openTelegramLink', (global, actions, payload) => {
|
||||||
const { url } = payload!;
|
const { url } = payload!;
|
||||||
const stickersMatch = RE_TME_ADDSTICKERS_LINK.exec(url);
|
if (url.match(RE_TG_LINK)) {
|
||||||
if (stickersMatch) {
|
|
||||||
actions.openStickerSetShortName({
|
|
||||||
stickerSetShortName: stickersMatch[1],
|
|
||||||
});
|
|
||||||
} else if (url.match(RE_TG_LINK)) {
|
|
||||||
processDeepLink(url.match(RE_TG_LINK)[0]);
|
processDeepLink(url.match(RE_TG_LINK)[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uri = new URL(url.startsWith('http') ? url : `https://${url}`);
|
||||||
|
const [part1, part2, part3] = uri.pathname.split('/').filter(Boolean).map((l) => decodeURI(l));
|
||||||
|
const params = Object.fromEntries(uri.searchParams);
|
||||||
|
|
||||||
|
let hash: string | undefined;
|
||||||
|
if (part1 === 'joinchat') {
|
||||||
|
hash = part2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part1.startsWith(' ') || part1.startsWith('+')) {
|
||||||
|
hash = part1.substr(1, part1.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash) {
|
||||||
|
actions.openChatByInvite({ hash });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part1 === 'addstickers') {
|
||||||
|
actions.openStickerSetShortName({
|
||||||
|
stickerSetShortName: part2,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chatOrChannelPostId = part2 ? Number(part2) : undefined;
|
||||||
|
const messageId = part3 ? Number(part3) : undefined;
|
||||||
|
const commentId = params.comment ? Number(params.comment) : undefined;
|
||||||
|
if (part1 === 'c' && chatOrChannelPostId && messageId) {
|
||||||
|
actions.focusMessage({
|
||||||
|
chatId: -chatOrChannelPostId,
|
||||||
|
messageId,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
let match = RE_TME_INVITE_LINK.exec(url);
|
actions.openChatByUsername({
|
||||||
|
username: part1,
|
||||||
if (match) {
|
messageId: messageId || chatOrChannelPostId,
|
||||||
const hash = match[1];
|
commentId,
|
||||||
|
});
|
||||||
actions.openChatByInvite({ hash });
|
|
||||||
} else {
|
|
||||||
match = RE_TME_LINK.exec(url)!;
|
|
||||||
|
|
||||||
const username = match[1];
|
|
||||||
const chatOrChannelPostId = match[2] ? Number(match[2]) : undefined;
|
|
||||||
const messageId = match[3] ? Number(match[3]) : undefined;
|
|
||||||
const commentId = match[4] === 'comment' && match[5] ? Number(match[5]) : undefined;
|
|
||||||
|
|
||||||
// Open message in private group
|
|
||||||
if (username === 'c' && chatOrChannelPostId && messageId) {
|
|
||||||
actions.focusMessage({
|
|
||||||
chatId: -chatOrChannelPostId,
|
|
||||||
messageId,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
actions.openChatByUsername({
|
|
||||||
username,
|
|
||||||
messageId: messageId || chatOrChannelPostId,
|
|
||||||
commentId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,9 @@
|
|||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
|
"dom.iterable",
|
||||||
"webworker",
|
"webworker",
|
||||||
"es7"
|
"es2019"
|
||||||
],
|
],
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user