Page Title: Allow to disable chat title display (#2691)

This commit is contained in:
Alexander Zinchuk 2023-02-28 18:43:49 +01:00
parent 9213919c55
commit 37b9836739
4 changed files with 33 additions and 4 deletions

View File

@ -29,6 +29,7 @@ type StateProps = {
canChangeSensitive?: boolean; canChangeSensitive?: boolean;
canDisplayAutoarchiveSetting: boolean; canDisplayAutoarchiveSetting: boolean;
shouldArchiveAndMuteNewNonContact?: boolean; shouldArchiveAndMuteNewNonContact?: boolean;
canDisplayChatInTitle?: boolean;
privacyPhoneNumber?: ApiPrivacySettings; privacyPhoneNumber?: ApiPrivacySettings;
privacyLastSeen?: ApiPrivacySettings; privacyLastSeen?: ApiPrivacySettings;
privacyProfilePhoto?: ApiPrivacySettings; privacyProfilePhoto?: ApiPrivacySettings;
@ -50,6 +51,7 @@ const SettingsPrivacy: FC<OwnProps & StateProps> = ({
canChangeSensitive, canChangeSensitive,
canDisplayAutoarchiveSetting, canDisplayAutoarchiveSetting,
shouldArchiveAndMuteNewNonContact, shouldArchiveAndMuteNewNonContact,
canDisplayChatInTitle,
privacyPhoneNumber, privacyPhoneNumber,
privacyLastSeen, privacyLastSeen,
privacyProfilePhoto, privacyProfilePhoto,
@ -71,6 +73,8 @@ const SettingsPrivacy: FC<OwnProps & StateProps> = ({
updateGlobalPrivacySettings, updateGlobalPrivacySettings,
loadWebAuthorizations, loadWebAuthorizations,
showNotification, showNotification,
setSettingOption,
updatePageTitle,
} = getActions(); } = getActions();
useEffect(() => { useEffect(() => {
@ -110,6 +114,13 @@ const SettingsPrivacy: FC<OwnProps & StateProps> = ({
} }
}, [isCurrentUserPremium, lang, onScreenSelect, showNotification]); }, [isCurrentUserPremium, lang, onScreenSelect, showNotification]);
const handleChatInTitleChange = useCallback((isChecked: boolean) => {
setSettingOption({
canDisplayChatInTitle: isChecked,
});
updatePageTitle();
}, []);
const handleUpdateContentSettings = useCallback((isChecked: boolean) => { const handleUpdateContentSettings = useCallback((isChecked: boolean) => {
updateContentSettings(isChecked); updateContentSettings(isChecked);
}, [updateContentSettings]); }, [updateContentSettings]);
@ -316,6 +327,17 @@ const SettingsPrivacy: FC<OwnProps & StateProps> = ({
</div> </div>
)} )}
<div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
{lang('lng_settings_window_system')}
</h4>
<Checkbox
label={lang('lng_settings_title_chat_name')}
checked={Boolean(canDisplayChatInTitle)}
onCheck={handleChatInTitleChange}
/>
</div>
{canChangeSensitive && ( {canChangeSensitive && (
<div className="settings-item"> <div className="settings-item">
<h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}> <h4 className="settings-item-header" dir={lang.isRtl ? 'rtl' : undefined}>
@ -340,6 +362,7 @@ export default memo(withGlobal<OwnProps>(
settings: { settings: {
byKey: { byKey: {
hasPassword, isSensitiveEnabled, canChangeSensitive, shouldArchiveAndMuteNewNonContact, hasPassword, isSensitiveEnabled, canChangeSensitive, shouldArchiveAndMuteNewNonContact,
canDisplayChatInTitle,
}, },
privacy, privacy,
}, },
@ -368,6 +391,7 @@ export default memo(withGlobal<OwnProps>(
privacyGroupChats: privacy.chatInvite, privacyGroupChats: privacy.chatInvite,
privacyPhoneCall: privacy.phoneCall, privacyPhoneCall: privacy.phoneCall,
privacyPhoneP2P: privacy.phoneP2P, privacyPhoneP2P: privacy.phoneP2P,
canDisplayChatInTitle,
}; };
}, },
)(SettingsPrivacy)); )(SettingsPrivacy));

View File

@ -23,7 +23,7 @@ import setPageTitle from '../../../util/updatePageTitle';
import { updateTabState } from '../../reducers/tabs'; import { updateTabState } from '../../reducers/tabs';
import { getIsMobile, getIsTablet } from '../../../hooks/useAppLayout'; import { getIsMobile, getIsTablet } from '../../../hooks/useAppLayout';
import * as langProvider from '../../../util/langProvider'; import * as langProvider from '../../../util/langProvider';
import { getAllowedAttachmentOptions } from '../../helpers'; import { getAllowedAttachmentOptions, getChatTitle } from '../../helpers';
export const APP_VERSION_URL = 'version.txt'; export const APP_VERSION_URL = 'version.txt';
const MAX_STORED_EMOJIS = 8 * 4; // Represents four rows of recent emojis const MAX_STORED_EMOJIS = 8 * 4; // Represents four rows of recent emojis
@ -658,6 +658,8 @@ addActionHandler('onTabFocusChange', (global, actions, payload): ActionReturnTyp
addActionHandler('updatePageTitle', (global, actions, payload): ActionReturnType => { addActionHandler('updatePageTitle', (global, actions, payload): ActionReturnType => {
const { isInactive, notificationCount, tabId = getCurrentTabId() } = payload || {}; const { isInactive, notificationCount, tabId = getCurrentTabId() } = payload || {};
const { canDisplayChatInTitle } = global.settings.byKey;
const currentUserId = global.currentUserId;
if (isInactive) { if (isInactive) {
setPageTitle(`${PAGE_TITLE} ${INACTIVE_MARKER}`); setPageTitle(`${PAGE_TITLE} ${INACTIVE_MARKER}`);
@ -670,16 +672,17 @@ addActionHandler('updatePageTitle', (global, actions, payload): ActionReturnType
} }
const messageList = selectCurrentMessageList(global, tabId); const messageList = selectCurrentMessageList(global, tabId);
if (messageList) { if (messageList && canDisplayChatInTitle) {
const { chatId, threadId } = messageList; const { chatId, threadId } = messageList;
const currentChat = selectChat(global, chatId); const currentChat = selectChat(global, chatId);
if (currentChat) { if (currentChat) {
const title = getChatTitle(langProvider.translate, currentChat, undefined, chatId === currentUserId);
if (currentChat.isForum && currentChat.topics?.[threadId]) { if (currentChat.isForum && currentChat.topics?.[threadId]) {
setPageTitle(`${currentChat.title} ${currentChat.topics[threadId].title}`); setPageTitle(`${title} ${currentChat.topics[threadId].title}`);
return; return;
} }
setPageTitle(currentChat.title); setPageTitle(title);
return; return;
} }
} }

View File

@ -168,6 +168,7 @@ export const INITIAL_GLOBAL_STATE: GlobalState = {
canTranslate: false, canTranslate: false,
canTranslateChats: true, canTranslateChats: true,
doNotTranslate: [], doNotTranslate: [],
canDisplayChatInTitle: true,
}, },
themes: { themes: {
light: { light: {

View File

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