From 0c5b3e560ea8c5c722407a2d91c369e2b0fc8491 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 3 May 2022 14:17:00 +0100 Subject: [PATCH] Settings / Active Sessions: Add secret chats toggle (#1848) --- src/api/gramjs/apiBuilders/misc.ts | 1 + src/api/gramjs/methods/account.ts | 7 ++++--- src/api/types/misc.ts | 1 + .../left/settings/SettingsActiveSession.tsx | 21 ++++++++++++++++--- src/global/actions/api/accounts.ts | 6 ++++-- src/global/types.ts | 3 ++- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/api/gramjs/apiBuilders/misc.ts b/src/api/gramjs/apiBuilders/misc.ts index 802858c7..4813a13e 100644 --- a/src/api/gramjs/apiBuilders/misc.ts +++ b/src/api/gramjs/apiBuilders/misc.ts @@ -37,6 +37,7 @@ export function buildApiSession(session: GramJs.Authorization): ApiSession { isPasswordPending: Boolean(session.passwordPending), hash: String(session.hash), areCallsEnabled: !session.callRequestsDisabled, + areSecretChatsEnabled: !session.encryptedRequestsDisabled, ...pick(session, [ 'deviceModel', 'platform', 'systemVersion', 'appName', 'appVersion', 'dateCreated', 'dateActive', 'ip', 'country', 'region', diff --git a/src/api/gramjs/methods/account.ts b/src/api/gramjs/methods/account.ts index 1922ff87..cc694fa8 100644 --- a/src/api/gramjs/methods/account.ts +++ b/src/api/gramjs/methods/account.ts @@ -44,13 +44,14 @@ export async function reportProfilePhoto({ } 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({ hash: BigInt(hash), - callRequestsDisabled: !areCallsEnabled, + ...(areCallsEnabled !== undefined ? { callRequestsDisabled: !areCallsEnabled } : undefined), + ...(areSecretChatsEnabled !== undefined ? { encryptedRequestsDisabled: !areSecretChatsEnabled } : undefined), })); return result; diff --git a/src/api/types/misc.ts b/src/api/types/misc.ts index 20f9125a..37e98f87 100644 --- a/src/api/types/misc.ts +++ b/src/api/types/misc.ts @@ -62,6 +62,7 @@ export interface ApiSession { country: string; region: string; areCallsEnabled: boolean; + areSecretChatsEnabled: boolean; } export interface ApiSessionData { diff --git a/src/components/left/settings/SettingsActiveSession.tsx b/src/components/left/settings/SettingsActiveSession.tsx index a838d3ac..d4101019 100644 --- a/src/components/left/settings/SettingsActiveSession.tsx +++ b/src/components/left/settings/SettingsActiveSession.tsx @@ -34,10 +34,17 @@ const SettingsActiveSession: FC = ({ const renderingSession = useCurrentOrPrev(session, true); + const handleSecretChatsStateChange = useCallback(() => { + changeSessionSettings({ + hash: session!.hash, + areSecretChatsEnabled: !session!.areSecretChatsEnabled, + }); + }, [changeSessionSettings, session]); + const handleCallsStateChange = useCallback(() => { changeSessionSettings({ hash: session!.hash, - areCallsEnabled: !session?.areCallsEnabled, + areCallsEnabled: !session!.areCallsEnabled, }); }, [changeSessionSettings, session]); @@ -71,7 +78,7 @@ const SettingsActiveSession: FC = ({
{lang('SessionPreview.App')}
- {renderingSession?.appName} {renderingSession?.appVersion}, + {renderingSession?.appName} {renderingSession?.appVersion},{' '} {renderingSession?.platform} {renderingSession?.systemVersion}
@@ -86,10 +93,18 @@ const SettingsActiveSession: FC = ({

{lang('SessionPreview.AcceptHeader')}

+ + {lang('SessionPreview.Accept.Secret')} + + {lang('SessionPreview.Accept.Calls')} diff --git a/src/global/actions/api/accounts.ts b/src/global/actions/api/accounts.ts index f3aff86e..1ef62213 100644 --- a/src/global/actions/api/accounts.ts +++ b/src/global/actions/api/accounts.ts @@ -124,10 +124,11 @@ addActionHandler('terminateAllAuthorizations', async (global) => { }); addActionHandler('changeSessionSettings', async (global, actions, payload) => { - const { hash, areCallsEnabled } = payload; + const { hash, areCallsEnabled, areSecretChatsEnabled } = payload; const result = await callApi('changeSessionSettings', { hash, areCallsEnabled, + areSecretChatsEnabled, }); if (!result) { @@ -143,7 +144,8 @@ addActionHandler('changeSessionSettings', async (global, actions, payload) => { ...global.activeSessions.byHash, [hash]: { ...global.activeSessions.byHash[hash], - areCallsEnabled, + ...(areCallsEnabled !== undefined ? { areCallsEnabled } : undefined), + ...(areSecretChatsEnabled !== undefined ? { areSecretChatsEnabled } : undefined), }, }, }, diff --git a/src/global/types.ts b/src/global/types.ts index 7f358199..aec87352 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -603,7 +603,8 @@ export interface ActionPayloads { }; changeSessionSettings: { hash: string; - areCallsEnabled: boolean; + areCallsEnabled?: boolean; + areSecretChatsEnabled?: boolean; }; changeSessionTtl: { days: number;