Settings / Active Sessions: Add secret chats toggle (#1848)

This commit is contained in:
Alexander Zinchuk 2022-05-03 14:17:00 +01:00
parent 5a9baa530b
commit 0c5b3e560e
6 changed files with 30 additions and 9 deletions

View File

@ -37,6 +37,7 @@ export function buildApiSession(session: GramJs.Authorization): ApiSession {
isPasswordPending: Boolean(session.passwordPending), isPasswordPending: Boolean(session.passwordPending),
hash: String(session.hash), hash: String(session.hash),
areCallsEnabled: !session.callRequestsDisabled, areCallsEnabled: !session.callRequestsDisabled,
areSecretChatsEnabled: !session.encryptedRequestsDisabled,
...pick(session, [ ...pick(session, [
'deviceModel', 'platform', 'systemVersion', 'appName', 'appVersion', 'dateCreated', 'dateActive', 'deviceModel', 'platform', 'systemVersion', 'appName', 'appVersion', 'dateCreated', 'dateActive',
'ip', 'country', 'region', 'ip', 'country', 'region',

View File

@ -44,13 +44,14 @@ export async function reportProfilePhoto({
} }
export async function changeSessionSettings({ export async function changeSessionSettings({
hash, areCallsEnabled, hash, areCallsEnabled, areSecretChatsEnabled,
}: { }: {
hash: string; areCallsEnabled: boolean; hash: string; areCallsEnabled?: boolean; areSecretChatsEnabled?: boolean;
}) { }) {
const result = await invokeRequest(new GramJs.account.ChangeAuthorizationSettings({ const result = await invokeRequest(new GramJs.account.ChangeAuthorizationSettings({
hash: BigInt(hash), hash: BigInt(hash),
callRequestsDisabled: !areCallsEnabled, ...(areCallsEnabled !== undefined ? { callRequestsDisabled: !areCallsEnabled } : undefined),
...(areSecretChatsEnabled !== undefined ? { encryptedRequestsDisabled: !areSecretChatsEnabled } : undefined),
})); }));
return result; return result;

View File

@ -62,6 +62,7 @@ export interface ApiSession {
country: string; country: string;
region: string; region: string;
areCallsEnabled: boolean; areCallsEnabled: boolean;
areSecretChatsEnabled: boolean;
} }
export interface ApiSessionData { export interface ApiSessionData {

View File

@ -34,10 +34,17 @@ const SettingsActiveSession: FC<OwnProps & StateProps> = ({
const renderingSession = useCurrentOrPrev(session, true); const renderingSession = useCurrentOrPrev(session, true);
const handleSecretChatsStateChange = useCallback(() => {
changeSessionSettings({
hash: session!.hash,
areSecretChatsEnabled: !session!.areSecretChatsEnabled,
});
}, [changeSessionSettings, session]);
const handleCallsStateChange = useCallback(() => { const handleCallsStateChange = useCallback(() => {
changeSessionSettings({ changeSessionSettings({
hash: session!.hash, hash: session!.hash,
areCallsEnabled: !session?.areCallsEnabled, areCallsEnabled: !session!.areCallsEnabled,
}); });
}, [changeSessionSettings, session]); }, [changeSessionSettings, session]);
@ -71,7 +78,7 @@ const SettingsActiveSession: FC<OwnProps & StateProps> = ({
<dl className={styles.box}> <dl className={styles.box}>
<dt>{lang('SessionPreview.App')}</dt> <dt>{lang('SessionPreview.App')}</dt>
<dd> <dd>
{renderingSession?.appName} {renderingSession?.appVersion}, {renderingSession?.appName} {renderingSession?.appVersion},{' '}
{renderingSession?.platform} {renderingSession?.systemVersion} {renderingSession?.platform} {renderingSession?.systemVersion}
</dd> </dd>
@ -86,10 +93,18 @@ const SettingsActiveSession: FC<OwnProps & StateProps> = ({
<h4 className={styles.actionHeader}>{lang('SessionPreview.AcceptHeader')}</h4> <h4 className={styles.actionHeader}>{lang('SessionPreview.AcceptHeader')}</h4>
<ListItem onClick={handleSecretChatsStateChange}>
<span className={styles.actionName}>{lang('SessionPreview.Accept.Secret')}</span>
<Switcher
id="accept_secrets"
label="On"
checked={renderingSession.areSecretChatsEnabled}
/>
</ListItem>
<ListItem onClick={handleCallsStateChange}> <ListItem onClick={handleCallsStateChange}>
<span className={styles.actionName}>{lang('SessionPreview.Accept.Calls')}</span> <span className={styles.actionName}>{lang('SessionPreview.Accept.Calls')}</span>
<Switcher <Switcher
id="darkmode" id="accept_calls"
label="On" label="On"
checked={renderingSession.areCallsEnabled} checked={renderingSession.areCallsEnabled}
/> />

View File

@ -124,10 +124,11 @@ addActionHandler('terminateAllAuthorizations', async (global) => {
}); });
addActionHandler('changeSessionSettings', async (global, actions, payload) => { addActionHandler('changeSessionSettings', async (global, actions, payload) => {
const { hash, areCallsEnabled } = payload; const { hash, areCallsEnabled, areSecretChatsEnabled } = payload;
const result = await callApi('changeSessionSettings', { const result = await callApi('changeSessionSettings', {
hash, hash,
areCallsEnabled, areCallsEnabled,
areSecretChatsEnabled,
}); });
if (!result) { if (!result) {
@ -143,7 +144,8 @@ addActionHandler('changeSessionSettings', async (global, actions, payload) => {
...global.activeSessions.byHash, ...global.activeSessions.byHash,
[hash]: { [hash]: {
...global.activeSessions.byHash[hash], ...global.activeSessions.byHash[hash],
areCallsEnabled, ...(areCallsEnabled !== undefined ? { areCallsEnabled } : undefined),
...(areSecretChatsEnabled !== undefined ? { areSecretChatsEnabled } : undefined),
}, },
}, },
}, },

View File

@ -603,7 +603,8 @@ export interface ActionPayloads {
}; };
changeSessionSettings: { changeSessionSettings: {
hash: string; hash: string;
areCallsEnabled: boolean; areCallsEnabled?: boolean;
areSecretChatsEnabled?: boolean;
}; };
changeSessionTtl: { changeSessionTtl: {
days: number; days: number;