From 0c9fdd1faf844b7375161fdf54aec3ed909c989c Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 28 Jul 2021 17:09:38 +0300 Subject: [PATCH] Support t.me links to private chats (#1334) --- src/config.ts | 2 +- src/modules/actions/api/chats.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index df50eee9..5a2f9933 100644 --- a/src/config.ts +++ b/src/config.ts @@ -126,7 +126,7 @@ export const CONTENT_TYPES_FOR_QUICK_UPLOAD = new Set([ // eslint-disable-next-line max-len 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_TME_LINK = /^(?:https?:\/\/)?(?:t\.me\/)([\d\w_]+)(?:\/([\d]+))?$/gm; +export const RE_TME_LINK = /^(?:https?:\/\/)?(?:t\.me\/)([\d\w_]+)(?:\/([\d]+))?(?:\/([\d]+))?$/gm; export const RE_TME_INVITE_LINK = /^(?:https?:\/\/)?(?:t\.me\/joinchat\/)([\d\w_-]+)?$/gm; // MTProto constants diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 4094c53d..03feb0ff 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -436,9 +436,15 @@ addReducer('openTelegramLink', (global, actions, payload) => { match = RE_TME_LINK.exec(url)!; const username = match[1]; - const channelPostId = match[2] ? Number(match[2]) : undefined; + const chatOrChannelPostId = match[2] ? Number(match[2]) : undefined; + const messageId = match[3] ? Number(match[3]) : undefined; - void openChatByUsername(actions, username, channelPostId); + // Open message in private chat + if (username === 'c' && chatOrChannelPostId && messageId) { + actions.focusMessage({ chatId: -chatOrChannelPostId, messageId }); + } else { + void openChatByUsername(actions, username, chatOrChannelPostId); + } } });