Support t.me links to private chats (#1334)

This commit is contained in:
Alexander Zinchuk 2021-07-28 17:09:38 +03:00
parent 4c1595b0f7
commit 0c9fdd1faf
2 changed files with 9 additions and 3 deletions

View File

@ -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

View File

@ -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);
}
}
});