Experimental: Add "Don't hide login code in chat list" toggle (#3147)

This commit is contained in:
Alexander Zinchuk 2023-05-03 21:33:24 +04:00
parent 829080a98f
commit dda81b5962
3 changed files with 28 additions and 6 deletions

View File

@ -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<OwnProps> = ({
type StateProps = {
shouldShowLoginCodeInChatList?: boolean;
};
const SettingsExperimental: FC<OwnProps & StateProps> = ({
isActive,
onReset,
shouldShowLoginCodeInChatList,
}) => {
const { requestConfetti } = getActions();
const { requestConfetti, setSettingOption } = getActions();
const lang = useLang();
useHistoryBack({
@ -38,7 +44,7 @@ const SettingsExperimental: FC<OwnProps> = ({
nonInteractive
noLoop={false}
/>
<p className="settings-item-description" dir="auto">{lang('lng_settings_experimental_about')}</p>
<p className="settings-item-description pt-3" dir="auto">{lang('lng_settings_experimental_about')}</p>
</div>
<div className="settings-item">
<ListItem
@ -48,9 +54,22 @@ const SettingsExperimental: FC<OwnProps> = ({
>
<div className="title">Launch some confetti!</div>
</ListItem>
<Checkbox
label="Show login code in chat list"
checked={Boolean(shouldShowLoginCodeInChatList)}
// eslint-disable-next-line react/jsx-no-bind
onCheck={() => setSettingOption({ shouldShowLoginCodeInChatList: !shouldShowLoginCodeInChatList })}
/>
</div>
</div>
);
};
export default memo(SettingsExperimental);
export default memo(withGlobal(
(global): StateProps => {
return {
shouldShowLoginCodeInChatList: global.settings.byKey.shouldShowLoginCodeInChatList,
};
},
)(SettingsExperimental));

View File

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

View File

@ -99,6 +99,7 @@ export interface ISettings extends NotifySettings, Record<string, any> {
canTranslateChats: boolean;
doNotTranslate: string[];
canDisplayChatInTitle: boolean;
shouldShowLoginCodeInChatList?: boolean;
}
export interface ApiPrivacySettings {