From dda81b5962b0ca54c93f045cbd5c81bec0d80260 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Wed, 3 May 2023 21:33:24 +0400 Subject: [PATCH] Experimental: Add "Don't hide login code in chat list" toggle (#3147) --- .../left/settings/SettingsExperimental.tsx | 29 +++++++++++++++---- src/global/helpers/messages.ts | 4 ++- src/types/index.ts | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/components/left/settings/SettingsExperimental.tsx b/src/components/left/settings/SettingsExperimental.tsx index fd068039f..83fa046a2 100644 --- a/src/components/left/settings/SettingsExperimental.tsx +++ b/src/components/left/settings/SettingsExperimental.tsx @@ -2,7 +2,7 @@ import React, { memo } from '../../../lib/teact/teact'; import type { FC } from '../../../lib/teact/teact'; -import { getActions } from '../../../global'; +import { getActions, withGlobal } from '../../../global'; import { LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -10,17 +10,23 @@ import useLang from '../../../hooks/useLang'; import AnimatedIcon from '../../common/AnimatedIcon'; import ListItem from '../../ui/ListItem'; +import Checkbox from '../../ui/Checkbox'; type OwnProps = { isActive?: boolean; onReset: () => void; }; -const SettingsExperimental: FC = ({ +type StateProps = { + shouldShowLoginCodeInChatList?: boolean; +}; + +const SettingsExperimental: FC = ({ isActive, onReset, + shouldShowLoginCodeInChatList, }) => { - const { requestConfetti } = getActions(); + const { requestConfetti, setSettingOption } = getActions(); const lang = useLang(); useHistoryBack({ @@ -38,7 +44,7 @@ const SettingsExperimental: FC = ({ nonInteractive noLoop={false} /> -

{lang('lng_settings_experimental_about')}

+

{lang('lng_settings_experimental_about')}

= ({ >
Launch some confetti!
+ + setSettingOption({ shouldShowLoginCodeInChatList: !shouldShowLoginCodeInChatList })} + />
); }; -export default memo(SettingsExperimental); +export default memo(withGlobal( + (global): StateProps => { + return { + shouldShowLoginCodeInChatList: global.settings.byKey.shouldShowLoginCodeInChatList, + }; + }, +)(SettingsExperimental)); diff --git a/src/global/helpers/messages.ts b/src/global/helpers/messages.ts index 6d7ee5ba0..b4c1f0cd3 100644 --- a/src/global/helpers/messages.ts +++ b/src/global/helpers/messages.ts @@ -303,7 +303,9 @@ export function extractMessageText(message: ApiMessage, inChatList = false) { const { text } = contentText; let { entities } = contentText; - if (text && inChatList && message.chatId === SERVICE_NOTIFICATIONS_USER_ID) { + if (text && inChatList && message.chatId === SERVICE_NOTIFICATIONS_USER_ID + // eslint-disable-next-line eslint-multitab-tt/no-immediate-global + && !getGlobal().settings.byKey.shouldShowLoginCodeInChatList) { const authCode = text.match(/^\D*([\d-]{5,7})\D/)?.[1]; if (authCode) { entities = [ diff --git a/src/types/index.ts b/src/types/index.ts index 7b863e231..ea8f05c3b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -99,6 +99,7 @@ export interface ISettings extends NotifySettings, Record { canTranslateChats: boolean; doNotTranslate: string[]; canDisplayChatInTitle: boolean; + shouldShowLoginCodeInChatList?: boolean; } export interface ApiPrivacySettings {