Deep Link: Show notification when user has not access to the chat (#4443)

This commit is contained in:
Alexander Zinchuk 2024-03-30 22:42:35 +01:00
parent 8d2a2a5be1
commit aa588c8308
2 changed files with 19 additions and 22 deletions

View File

@ -1263,20 +1263,12 @@ addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnTyp
tabId = getCurrentTabId(), tabId = getCurrentTabId(),
} = payload; } = payload;
if (isDeepLink(url)) {
const isProcessed = processDeepLink(url);
if (isProcessed || url.match(RE_TG_LINK)) {
return;
}
}
const { const {
openChatByPhoneNumber, openChatByPhoneNumber,
openChatByInvite, openChatByInvite,
openStickerSet, openStickerSet,
openChatWithDraft, openChatWithDraft,
joinVoiceChatByLink, joinVoiceChatByLink,
showNotification,
focusMessage, focusMessage,
openInvoice, openInvoice,
processAttachBotParameters, processAttachBotParameters,
@ -1287,6 +1279,13 @@ addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnTyp
checkGiftCode, checkGiftCode,
} = actions; } = actions;
if (isDeepLink(url)) {
const isProcessed = processDeepLink(url);
if (isProcessed || url.match(RE_TG_LINK)) {
return;
}
}
const uri = new URL(url.toLowerCase().startsWith('http') ? url : `https://${url}`); const uri = new URL(url.toLowerCase().startsWith('http') ? url : `https://${url}`);
if (TME_WEB_DOMAINS.has(uri.hostname) && uri.pathname === '/') { if (TME_WEB_DOMAINS.has(uri.hostname) && uri.pathname === '/') {
window.open(uri.toString(), '_blank', 'noopener'); window.open(uri.toString(), '_blank', 'noopener');
@ -1397,20 +1396,11 @@ addActionHandler('openTelegramLink', (global, actions, payload): ActionReturnTyp
tabId, tabId,
}); });
} else if (part1 === 'c' && chatOrChannelPostId && messageId) { } else if (part1 === 'c' && chatOrChannelPostId && messageId) {
const chatId = toChannelId(chatOrChannelPostId); focusMessage({
const chat = selectChat(global, chatId); chatId: toChannelId(chatOrChannelPostId),
if (!chat) { messageId,
showNotification({ message: 'Chat does not exist', tabId }); tabId,
return; });
}
if (messageId) {
focusMessage({
chatId: chat.id,
messageId,
tabId,
});
}
} else if (part1.startsWith('$')) { } else if (part1.startsWith('$')) {
openInvoice({ openInvoice({
slug: part1.substring(1), slug: part1.substring(1),

View File

@ -16,6 +16,7 @@ import { copyHtmlToClipboard } from '../../../util/clipboard';
import { getCurrentTabId } from '../../../util/establishMultitabRole'; import { getCurrentTabId } from '../../../util/establishMultitabRole';
import { compact, findLast } from '../../../util/iteratees'; import { compact, findLast } from '../../../util/iteratees';
import * as langProvider from '../../../util/langProvider'; import * as langProvider from '../../../util/langProvider';
import { translate } from '../../../util/langProvider';
import parseHtmlAsFormattedText from '../../../util/parseHtmlAsFormattedText'; import parseHtmlAsFormattedText from '../../../util/parseHtmlAsFormattedText';
import { getServerTime } from '../../../util/serverTime'; import { getServerTime } from '../../../util/serverTime';
import { IS_TOUCH_ENV } from '../../../util/windowEnvironment'; import { IS_TOUCH_ENV } from '../../../util/windowEnvironment';
@ -402,6 +403,12 @@ addActionHandler('focusMessage', (global, actions, payload): ActionReturnType =>
let { messageId } = payload; let { messageId } = payload;
const chat = selectChat(global, chatId);
if (!chat) {
actions.showNotification({ message: translate('Conversation.ErrorInaccessibleMessage'), tabId });
return undefined;
}
if (groupedId !== undefined) { if (groupedId !== undefined) {
const ids = selectForwardedMessageIdsByGroupId(global, groupedChatId!, groupedId); const ids = selectForwardedMessageIdsByGroupId(global, groupedChatId!, groupedId);
if (ids?.length) { if (ids?.length) {