Message: Allow copying login code

This commit is contained in:
Alexander Zinchuk 2024-11-02 21:11:35 +04:00
parent d549ca49c0
commit ebe9377b41

View File

@ -2,8 +2,10 @@ import type {
ApiAttachment, ApiAttachment,
ApiMessage, ApiMessage,
ApiMessageEntityTextUrl, ApiMessageEntityTextUrl,
ApiPeer, ApiSponsoredMessage, ApiPeer,
ApiStory, MediaContainer, ApiSponsoredMessage,
ApiStory,
MediaContainer,
} from '../../api/types'; } from '../../api/types';
import type { MediaContent } from '../../api/types/messages'; import type { MediaContent } from '../../api/types/messages';
import type { LangFn } from '../../hooks/useOldLang'; import type { LangFn } from '../../hooks/useOldLang';
@ -27,10 +29,7 @@ import { isLocalMessageId } from '../../util/keys/messageKey';
import { getServerTime } from '../../util/serverTime'; import { getServerTime } from '../../util/serverTime';
import { getGlobal } from '../index'; import { getGlobal } from '../index';
import { import {
getChatTitle, getChatTitle, getCleanPeerId, isPeerUser, isUserId,
getCleanPeerId,
isPeerUser,
isUserId,
} from './chats'; } from './chats';
import { getMainUsername, getUserFullName } from './users'; import { getMainUsername, getUserFullName } from './users';
@ -280,14 +279,14 @@ export function extractMessageText(message: ApiMessage | ApiStory, inChatList =
const { text } = contentText; const { text } = contentText;
let { entities } = contentText; let { entities } = contentText;
if (text && inChatList && 'chatId' in message) { if (text && 'chatId' in message) {
if (message.chatId === SERVICE_NOTIFICATIONS_USER_ID) { if (message.chatId === SERVICE_NOTIFICATIONS_USER_ID) {
const authCode = text.match(/^\D*([\d-]{5,7})\D/)?.[1]; const authCode = text.match(/^\D*([\d-]{5,7})\D/)?.[1];
if (authCode) { if (authCode) {
entities = [ entities = [
...entities || [], ...entities || [],
{ {
type: ApiMessageEntityTypes.Spoiler, type: inChatList ? ApiMessageEntityTypes.Spoiler : ApiMessageEntityTypes.Code,
offset: text.indexOf(authCode), offset: text.indexOf(authCode),
length: authCode.length, length: authCode.length,
}, },
@ -296,7 +295,7 @@ export function extractMessageText(message: ApiMessage | ApiStory, inChatList =
} }
} }
if (message.chatId === VERIFICATION_CODES_USER_ID && entities) { if (inChatList && message.chatId === VERIFICATION_CODES_USER_ID && entities) {
// Wrap code entities in spoiler // Wrap code entities in spoiler
const hasCodeEntities = entities.some((entity) => entity.type === ApiMessageEntityTypes.Code); const hasCodeEntities = entities.some((entity) => entity.type === ApiMessageEntityTypes.Code);
if (hasCodeEntities) { if (hasCodeEntities) {