Support t.me subdomains (#2023)

This commit is contained in:
Alexander Zinchuk 2022-09-12 11:06:00 +02:00
parent 50dc91d71d
commit 1a89181e1d
4 changed files with 14 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import { getActions, withGlobal } from '../../../global';
import { ApiMediaFormat } from '../../../api/types';
import { ProfileEditProgress } from '../../../types';
import { TME_LINK_PREFIX } from '../../../config';
import { throttle } from '../../../util/schedulers';
import { selectUser } from '../../../global/selectors';
import { getChatAvatarHash } from '../../../global/helpers';
@ -228,7 +229,7 @@ const SettingsEditProfile: FC<OwnProps & StateProps> = ({
{username && (
<p className="settings-item-description" dir={lang.isRtl ? 'rtl' : undefined}>
{lang('lng_username_link')}<br />
<span className="username-link">https://t.me/{username}</span>
<span className="username-link">{TME_LINK_PREFIX}{username}</span>
</p>
)}
</div>

View File

@ -7,7 +7,7 @@ import { getActions, withGlobal } from '../../../global';
import type { ApiChat, ApiExportedInvite } from '../../../api/types';
import { ManagementScreens } from '../../../types';
import { STICKER_SIZE_INVITES } from '../../../config';
import { STICKER_SIZE_INVITES, TME_LINK_PREFIX } from '../../../config';
import { LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets';
import useHistoryBack from '../../../hooks/useHistoryBack';
import useLang from '../../../hooks/useLang';
@ -100,7 +100,7 @@ const ManageInvites: FC<OwnProps & StateProps> = ({
}, hasDetailedCountdown ? 1000 : undefined);
const primaryInvite = exportedInvites?.find(({ isPermanent }) => isPermanent);
const primaryInviteLink = chat?.username ? `t.me/${chat.username}` : primaryInvite?.link;
const primaryInviteLink = chat?.username ? `${TME_LINK_PREFIX}${chat.username}` : primaryInvite?.link;
const temporalInvites = useMemo(() => {
const invites = chat?.username ? exportedInvites : exportedInvites?.filter(({ isPermanent }) => !isPermanent);
return invites?.sort(inviteComparator);

View File

@ -194,7 +194,7 @@ export const CONTENT_NOT_SUPPORTED = 'The message is not supported on this versi
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_TG_LINK = /^tg:(\/\/)?([?=&\d\w_-]+)?/;
export const RE_TME_LINK = /^(https?:\/\/)?t\.me\//;
export const RE_TME_LINK = /^(https?:\/\/)?([-a-zA-Z0-9@:%_+~#=]{1,32}\.)?t\.me/;
export const RE_TELEGRAM_LINK = /^(https?:\/\/)?telegram\.org\//;
export const TME_LINK_PREFIX = 'https://t.me/';

View File

@ -586,7 +586,15 @@ addActionHandler('openTelegramLink', (global, actions, payload) => {
}
const uri = new URL(url.startsWith('http') ? url : `https://${url}`);
const [part1, part2, part3] = uri.pathname.split('/').filter(Boolean).map((l) => decodeURI(l));
if (uri.hostname === 't.me' && uri.pathname === '/') {
window.open(uri.toString(), '_blank', 'noopener');
return;
}
const hostParts = uri.hostname.split('.');
if (hostParts.length > 3) return;
const pathname = hostParts.length === 3 ? `${hostParts[0]}/${uri.pathname}` : uri.pathname;
const [part1, part2, part3] = pathname.split('/').filter(Boolean).map((l) => decodeURI(l));
const params = Object.fromEntries(uri.searchParams);
let hash: string | undefined;