mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-29 20:29:12 +01:00
Settings / Active Sessions: Add secret chats toggle (#1848)
This commit is contained in:
parent
5a9baa530b
commit
0c5b3e560e
@ -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',
|
||||
|
@ -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;
|
||||
|
@ -62,6 +62,7 @@ export interface ApiSession {
|
||||
country: string;
|
||||
region: string;
|
||||
areCallsEnabled: boolean;
|
||||
areSecretChatsEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface ApiSessionData {
|
||||
|
@ -34,10 +34,17 @@ const SettingsActiveSession: FC<OwnProps & StateProps> = ({
|
||||
|
||||
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<OwnProps & StateProps> = ({
|
||||
<dl className={styles.box}>
|
||||
<dt>{lang('SessionPreview.App')}</dt>
|
||||
<dd>
|
||||
{renderingSession?.appName} {renderingSession?.appVersion},
|
||||
{renderingSession?.appName} {renderingSession?.appVersion},{' '}
|
||||
{renderingSession?.platform} {renderingSession?.systemVersion}
|
||||
</dd>
|
||||
|
||||
@ -86,10 +93,18 @@ const SettingsActiveSession: FC<OwnProps & StateProps> = ({
|
||||
|
||||
<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}>
|
||||
<span className={styles.actionName}>{lang('SessionPreview.Accept.Calls')}</span>
|
||||
<Switcher
|
||||
id="darkmode"
|
||||
id="accept_calls"
|
||||
label="On"
|
||||
checked={renderingSession.areCallsEnabled}
|
||||
/>
|
||||
|
@ -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),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -603,7 +603,8 @@ export interface ActionPayloads {
|
||||
};
|
||||
changeSessionSettings: {
|
||||
hash: string;
|
||||
areCallsEnabled: boolean;
|
||||
areCallsEnabled?: boolean;
|
||||
areSecretChatsEnabled?: boolean;
|
||||
};
|
||||
changeSessionTtl: {
|
||||
days: number;
|
||||
|
Loading…
Reference in New Issue
Block a user