diff --git a/src/api/gramjs/apiBuilders/misc.ts b/src/api/gramjs/apiBuilders/misc.ts index 4813a13e5..790930ef8 100644 --- a/src/api/gramjs/apiBuilders/misc.ts +++ b/src/api/gramjs/apiBuilders/misc.ts @@ -53,6 +53,10 @@ export function buildPrivacyKey(key: GramJs.TypePrivacyKey): ApiPrivacyKey | und return 'lastSeen'; case 'PrivacyKeyProfilePhoto': return 'profilePhoto'; + case 'PrivacyKeyPhoneCall': + return 'phoneCall'; + case 'PrivacyKeyPhoneP2P': + return 'phoneP2P'; case 'PrivacyKeyForwards': return 'forwards'; case 'PrivacyKeyChatInvite': diff --git a/src/api/gramjs/gramjsBuilders/index.ts b/src/api/gramjs/gramjsBuilders/index.ts index 7bba98e90..e47199726 100644 --- a/src/api/gramjs/gramjsBuilders/index.ts +++ b/src/api/gramjs/gramjsBuilders/index.ts @@ -419,6 +419,12 @@ export function buildInputPrivacyKey(privacyKey: ApiPrivacyKey) { case 'chatInvite': return new GramJs.InputPrivacyKeyChatInvite(); + + case 'phoneCall': + return new GramJs.InputPrivacyKeyPhoneCall(); + + case 'phoneP2P': + return new GramJs.InputPrivacyKeyPhoneP2P(); } return undefined; diff --git a/src/api/types/updates.ts b/src/api/types/updates.ts index 095aa4c6d..e5fdda734 100644 --- a/src/api/types/updates.ts +++ b/src/api/types/updates.ts @@ -2,7 +2,8 @@ import type { GroupCallConnectionData, GroupCallParticipant, GroupCallConnectionState, - VideoState, VideoRotation, + VideoState, + VideoRotation, } from '../../lib/secret-sauce'; import { ApiChat, @@ -16,13 +17,13 @@ import { } from './messages'; import { ApiUser, ApiUserFullInfo, ApiUserStatus } from './users'; import { - ApiEmojiInteraction, - ApiError, ApiInviteInfo, ApiNotifyException, ApiSessionData, + ApiEmojiInteraction, ApiError, ApiInviteInfo, ApiNotifyException, ApiSessionData, } from './misc'; import { ApiGroupCall, ApiPhoneCall, } from './calls'; import { ApiBotMenuButton } from './bots'; +import type { ApiPrivacyKey, PrivacyVisibility } from '../../types'; export type ApiUpdateReady = { '@type': 'updateApiReady'; @@ -398,9 +399,9 @@ export type ApiUpdatePaymentStateCompleted = { export type ApiUpdatePrivacy = { '@type': 'updatePrivacy'; - key: 'phoneNumber' | 'lastSeen' | 'profilePhoto' | 'forwards' | 'chatInvite'; + key: ApiPrivacyKey; rules: { - visibility: 'everybody' | 'contacts' | 'nonContacts' | 'nobody'; + visibility: PrivacyVisibility; allowUserIds: string[]; allowChatIds: string[]; blockUserIds: string[]; diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index 2df0b76bd..7aabaed89 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -136,6 +136,8 @@ const LeftColumn: FC = ({ case SettingsScreens.PrivacyPhoneNumber: case SettingsScreens.PrivacyLastSeen: case SettingsScreens.PrivacyProfilePhoto: + case SettingsScreens.PrivacyPhoneCall: + case SettingsScreens.PrivacyPhoneP2P: case SettingsScreens.PrivacyForwarding: case SettingsScreens.PrivacyGroupChats: case SettingsScreens.PrivacyBlockedUsers: @@ -156,6 +158,14 @@ const LeftColumn: FC = ({ case SettingsScreens.PrivacyProfilePhotoDeniedContacts: setSettingsScreen(SettingsScreens.PrivacyProfilePhoto); return; + case SettingsScreens.PrivacyPhoneCallAllowedContacts: + case SettingsScreens.PrivacyPhoneCallDeniedContacts: + setSettingsScreen(SettingsScreens.PrivacyPhoneCall); + return; + case SettingsScreens.PrivacyPhoneP2PAllowedContacts: + case SettingsScreens.PrivacyPhoneP2PDeniedContacts: + setSettingsScreen(SettingsScreens.PrivacyPhoneP2P); + return; case SettingsScreens.PrivacyForwardingAllowedContacts: case SettingsScreens.PrivacyForwardingDeniedContacts: setSettingsScreen(SettingsScreens.PrivacyForwarding); diff --git a/src/components/left/settings/Settings.tsx b/src/components/left/settings/Settings.tsx index 861b7ef55..cb70b5c2d 100644 --- a/src/components/left/settings/Settings.tsx +++ b/src/components/left/settings/Settings.tsx @@ -80,6 +80,16 @@ const PRIVACY_PROFILE_PHOTO_SCREENS = [ SettingsScreens.PrivacyProfilePhotoDeniedContacts, ]; +const PRIVACY_PHONE_CALL_SCREENS = [ + SettingsScreens.PrivacyPhoneCallAllowedContacts, + SettingsScreens.PrivacyPhoneCallDeniedContacts, +]; + +const PRIVACY_PHONE_P2P_SCREENS = [ + SettingsScreens.PrivacyPhoneP2PAllowedContacts, + SettingsScreens.PrivacyPhoneP2PDeniedContacts, +]; + const PRIVACY_FORWARDING_SCREENS = [ SettingsScreens.PrivacyForwardingAllowedContacts, SettingsScreens.PrivacyForwardingDeniedContacts, @@ -150,6 +160,8 @@ const Settings: FC = ({ [SettingsScreens.PrivacyPhoneNumber]: PRIVACY_PHONE_NUMBER_SCREENS.includes(screen), [SettingsScreens.PrivacyLastSeen]: PRIVACY_LAST_SEEN_PHONE_SCREENS.includes(screen), [SettingsScreens.PrivacyProfilePhoto]: PRIVACY_PROFILE_PHOTO_SCREENS.includes(screen), + [SettingsScreens.PrivacyPhoneCall]: PRIVACY_PHONE_CALL_SCREENS.includes(screen), + [SettingsScreens.PrivacyPhoneP2P]: PRIVACY_PHONE_P2P_SCREENS.includes(screen), [SettingsScreens.PrivacyForwarding]: PRIVACY_FORWARDING_SCREENS.includes(screen), [SettingsScreens.PrivacyGroupChats]: PRIVACY_GROUP_CHATS_SCREENS.includes(screen), }; @@ -241,6 +253,8 @@ const Settings: FC = ({ case SettingsScreens.PrivacyPhoneNumber: case SettingsScreens.PrivacyLastSeen: case SettingsScreens.PrivacyProfilePhoto: + case SettingsScreens.PrivacyPhoneCall: + case SettingsScreens.PrivacyPhoneP2P: case SettingsScreens.PrivacyForwarding: case SettingsScreens.PrivacyGroupChats: return ( @@ -255,6 +269,8 @@ const Settings: FC = ({ case SettingsScreens.PrivacyPhoneNumberAllowedContacts: case SettingsScreens.PrivacyLastSeenAllowedContacts: case SettingsScreens.PrivacyProfilePhotoAllowedContacts: + case SettingsScreens.PrivacyPhoneCallAllowedContacts: + case SettingsScreens.PrivacyPhoneP2PAllowedContacts: case SettingsScreens.PrivacyForwardingAllowedContacts: case SettingsScreens.PrivacyGroupChatsAllowedContacts: return ( @@ -270,6 +286,8 @@ const Settings: FC = ({ case SettingsScreens.PrivacyPhoneNumberDeniedContacts: case SettingsScreens.PrivacyLastSeenDeniedContacts: case SettingsScreens.PrivacyProfilePhotoDeniedContacts: + case SettingsScreens.PrivacyPhoneCallDeniedContacts: + case SettingsScreens.PrivacyPhoneP2PDeniedContacts: case SettingsScreens.PrivacyForwardingDeniedContacts: case SettingsScreens.PrivacyGroupChatsDeniedContacts: return ( diff --git a/src/components/left/settings/SettingsPrivacy.tsx b/src/components/left/settings/SettingsPrivacy.tsx index 227382671..4a91569b1 100644 --- a/src/components/left/settings/SettingsPrivacy.tsx +++ b/src/components/left/settings/SettingsPrivacy.tsx @@ -1,7 +1,7 @@ import React, { FC, memo, useEffect } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; -import { PrivacyVisibility, SettingsScreens } from '../../../types'; +import { ApiPrivacySettings, SettingsScreens } from '../../../types'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -20,11 +20,13 @@ type StateProps = { blockedCount: number; isSensitiveEnabled?: boolean; canChangeSensitive?: boolean; - visibilityPrivacyPhoneNumber?: PrivacyVisibility; - visibilityPrivacyLastSeen?: PrivacyVisibility; - visibilityPrivacyProfilePhoto?: PrivacyVisibility; - visibilityPrivacyForwarding?: PrivacyVisibility; - visibilityPrivacyGroupChats?: PrivacyVisibility; + privacyPhoneNumber?: ApiPrivacySettings; + privacyLastSeen?: ApiPrivacySettings; + privacyProfilePhoto?: ApiPrivacySettings; + privacyForwarding?: ApiPrivacySettings; + privacyGroupChats?: ApiPrivacySettings; + privacyPhoneCall?: ApiPrivacySettings; + privacyPhoneP2P?: ApiPrivacySettings; }; const SettingsPrivacy: FC = ({ @@ -35,11 +37,13 @@ const SettingsPrivacy: FC = ({ blockedCount, isSensitiveEnabled, canChangeSensitive, - visibilityPrivacyPhoneNumber, - visibilityPrivacyLastSeen, - visibilityPrivacyProfilePhoto, - visibilityPrivacyForwarding, - visibilityPrivacyGroupChats, + privacyPhoneNumber, + privacyLastSeen, + privacyProfilePhoto, + privacyForwarding, + privacyGroupChats, + privacyPhoneCall, + privacyPhoneP2P, }) => { const { @@ -64,16 +68,25 @@ const SettingsPrivacy: FC = ({ onBack: onReset, }); - function getVisibilityValue(visibility?: PrivacyVisibility) { + function getVisibilityValue(setting?: ApiPrivacySettings) { + const { visibility } = setting || {}; + const blockCount = setting ? setting.blockChatIds.length + setting.blockUserIds.length : 0; + const allowCount = setting ? setting.allowChatIds.length + setting.allowUserIds.length : 0; + const total = []; + if (blockCount) total.push(`-${blockCount}`); + if (allowCount) total.push(`+${allowCount}`); + + const exceptionString = total.length ? `(${total.join(',')})` : ''; + switch (visibility) { case 'everybody': - return lang('P2PEverybody'); + return `${lang('P2PEverybody')} ${exceptionString}`; case 'contacts': - return lang('P2PContacts'); + return `${lang('P2PContacts')} ${exceptionString}`; case 'nobody': - return lang('P2PNobody'); + return `${lang('P2PNobody')} ${exceptionString}`; } return undefined; @@ -126,7 +139,7 @@ const SettingsPrivacy: FC = ({
{lang('PrivacyPhoneTitle')} - {getVisibilityValue(visibilityPrivacyPhoneNumber)} + {getVisibilityValue(privacyPhoneNumber)}
@@ -139,7 +152,7 @@ const SettingsPrivacy: FC = ({
{lang('LastSeenTitle')} - {getVisibilityValue(visibilityPrivacyLastSeen)} + {getVisibilityValue(privacyLastSeen)}
@@ -152,7 +165,33 @@ const SettingsPrivacy: FC = ({
{lang('PrivacyProfilePhotoTitle')} - {getVisibilityValue(visibilityPrivacyProfilePhoto)} + {getVisibilityValue(privacyProfilePhoto)} + +
+ + onScreenSelect(SettingsScreens.PrivacyPhoneCall)} + > +
+ {lang('WhoCanCallMe')} + + {getVisibilityValue(privacyPhoneCall)} + +
+
+ onScreenSelect(SettingsScreens.PrivacyPhoneP2P)} + > +
+ {lang('PrivacyP2P')} + + {getVisibilityValue(privacyPhoneP2P)}
@@ -165,7 +204,7 @@ const SettingsPrivacy: FC = ({
{lang('PrivacyForwardsTitle')} - {getVisibilityValue(visibilityPrivacyForwarding)} + {getVisibilityValue(privacyForwarding)}
@@ -178,7 +217,7 @@ const SettingsPrivacy: FC = ({
{lang('WhoCanAddMe')} - {getVisibilityValue(visibilityPrivacyGroupChats)} + {getVisibilityValue(privacyGroupChats)}
@@ -217,11 +256,13 @@ export default memo(withGlobal( blockedCount: blocked.totalCount, isSensitiveEnabled, canChangeSensitive, - visibilityPrivacyPhoneNumber: privacy.phoneNumber?.visibility, - visibilityPrivacyLastSeen: privacy.lastSeen?.visibility, - visibilityPrivacyProfilePhoto: privacy.profilePhoto?.visibility, - visibilityPrivacyForwarding: privacy.forwards?.visibility, - visibilityPrivacyGroupChats: privacy.chatInvite?.visibility, + privacyPhoneNumber: privacy.phoneNumber, + privacyLastSeen: privacy.lastSeen, + privacyProfilePhoto: privacy.profilePhoto, + privacyForwarding: privacy.forwards, + privacyGroupChats: privacy.chatInvite, + privacyPhoneCall: privacy.phoneCall, + privacyPhoneP2P: privacy.phoneP2P, }; }, )(SettingsPrivacy)); diff --git a/src/components/left/settings/SettingsPrivacyVisibility.tsx b/src/components/left/settings/SettingsPrivacyVisibility.tsx index 65a4a3ed3..c05b2a256 100644 --- a/src/components/left/settings/SettingsPrivacyVisibility.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibility.tsx @@ -79,6 +79,10 @@ const SettingsPrivacyVisibility: FC = ({ return lang('PrivacyForwardsTitle'); case SettingsScreens.PrivacyGroupChats: return lang('WhoCanAddMe'); + case SettingsScreens.PrivacyPhoneCall: + return lang('WhoCanCallMe'); + case SettingsScreens.PrivacyPhoneP2P: + return lang('PrivacyP2P'); default: return undefined; } @@ -108,6 +112,10 @@ const SettingsPrivacyVisibility: FC = ({ return SettingsScreens.PrivacyProfilePhotoAllowedContacts; case SettingsScreens.PrivacyForwarding: return SettingsScreens.PrivacyForwardingAllowedContacts; + case SettingsScreens.PrivacyPhoneCall: + return SettingsScreens.PrivacyPhoneCallAllowedContacts; + case SettingsScreens.PrivacyPhoneP2P: + return SettingsScreens.PrivacyPhoneP2PAllowedContacts; default: return SettingsScreens.PrivacyGroupChatsAllowedContacts; } @@ -123,6 +131,10 @@ const SettingsPrivacyVisibility: FC = ({ return SettingsScreens.PrivacyProfilePhotoDeniedContacts; case SettingsScreens.PrivacyForwarding: return SettingsScreens.PrivacyForwardingDeniedContacts; + case SettingsScreens.PrivacyPhoneCall: + return SettingsScreens.PrivacyPhoneCallDeniedContacts; + case SettingsScreens.PrivacyPhoneP2P: + return SettingsScreens.PrivacyPhoneP2PDeniedContacts; default: return SettingsScreens.PrivacyGroupChatsDeniedContacts; } @@ -186,7 +198,7 @@ const SettingsPrivacyVisibility: FC = ({ >
{allowedCount > 0 && +{allowedCount}} - {lang('AlwaysShareWith')} + {lang('AlwaysAllow')} {lang('EditAdminAddUsers')}
@@ -202,7 +214,7 @@ const SettingsPrivacyVisibility: FC = ({ >
{blockCount > 0 && −{blockCount}} - {lang('NeverShareWith')} + {lang('NeverAllow')} {lang('EditAdminAddUsers')}
@@ -234,6 +246,14 @@ export default memo(withGlobal( privacySettings = privacy.profilePhoto; break; + case SettingsScreens.PrivacyPhoneCall: + privacySettings = privacy.phoneCall; + break; + + case SettingsScreens.PrivacyPhoneP2P: + privacySettings = privacy.phoneP2P; + break; + case SettingsScreens.PrivacyForwarding: privacySettings = privacy.forwards; break; diff --git a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx index fd65c83e1..5b32193f1 100644 --- a/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx +++ b/src/components/left/settings/SettingsPrivacyVisibilityExceptionList.tsx @@ -103,7 +103,7 @@ const SettingsPrivacyVisibilityExceptionList: FC = ({ itemIds={displayedIds || []} selectedIds={newSelectedContactIds} filterValue={searchQuery} - filterPlaceholder={isAllowList ? lang('AlwaysShareWithPlaceholder') : lang('NeverShareWithPlaceholder')} + filterPlaceholder={isAllowList ? lang('AlwaysAllowPlaceholder') : lang('NeverAllowPlaceholder')} searchInputId="new-group-picker-search" onSelectedIdsChange={handleSelectedContactIdsChange} onFilterChange={setSearchQuery} @@ -112,7 +112,7 @@ const SettingsPrivacyVisibilityExceptionList: FC = ({ @@ -132,6 +132,12 @@ function getCurrentPrivacySettings(global: GlobalState, screen: SettingsScreens) case SettingsScreens.PrivacyProfilePhotoAllowedContacts: case SettingsScreens.PrivacyProfilePhotoDeniedContacts: return privacy.profilePhoto; + case SettingsScreens.PrivacyPhoneCallAllowedContacts: + case SettingsScreens.PrivacyPhoneCallDeniedContacts: + return privacy.phoneCall; + case SettingsScreens.PrivacyPhoneP2PAllowedContacts: + case SettingsScreens.PrivacyPhoneP2PDeniedContacts: + return privacy.phoneP2P; case SettingsScreens.PrivacyForwardingAllowedContacts: case SettingsScreens.PrivacyForwardingDeniedContacts: return privacy.forwards; diff --git a/src/components/left/settings/helpers/privacy.ts b/src/components/left/settings/helpers/privacy.ts index 45a833509..3cb303041 100644 --- a/src/components/left/settings/helpers/privacy.ts +++ b/src/components/left/settings/helpers/privacy.ts @@ -22,6 +22,14 @@ export function getPrivacyKey(screen: SettingsScreens): ApiPrivacyKey | undefine case SettingsScreens.PrivacyGroupChatsAllowedContacts: case SettingsScreens.PrivacyGroupChatsDeniedContacts: return 'chatInvite'; + case SettingsScreens.PrivacyPhoneCall: + case SettingsScreens.PrivacyPhoneCallAllowedContacts: + case SettingsScreens.PrivacyPhoneCallDeniedContacts: + return 'phoneCall'; + case SettingsScreens.PrivacyPhoneP2P: + case SettingsScreens.PrivacyPhoneP2PAllowedContacts: + case SettingsScreens.PrivacyPhoneP2PDeniedContacts: + return 'phoneP2P'; } return undefined; diff --git a/src/global/actions/api/settings.ts b/src/global/actions/api/settings.ts index 14dfa5b2e..bd3e31525 100644 --- a/src/global/actions/api/settings.ts +++ b/src/global/actions/api/settings.ts @@ -308,17 +308,31 @@ addActionHandler('loadLanguages', async () => { addActionHandler('loadPrivacySettings', async (global) => { const [ - phoneNumberSettings, lastSeenSettings, profilePhotoSettings, forwardsSettings, chatInviteSettings, + phoneNumberSettings, + lastSeenSettings, + profilePhotoSettings, + forwardsSettings, + chatInviteSettings, + phoneCallSettings, + phoneP2PSettings, ] = await Promise.all([ callApi('fetchPrivacySettings', 'phoneNumber'), callApi('fetchPrivacySettings', 'lastSeen'), callApi('fetchPrivacySettings', 'profilePhoto'), callApi('fetchPrivacySettings', 'forwards'), callApi('fetchPrivacySettings', 'chatInvite'), + callApi('fetchPrivacySettings', 'phoneCall'), + callApi('fetchPrivacySettings', 'phoneP2P'), ]); if ( - !phoneNumberSettings || !lastSeenSettings || !profilePhotoSettings || !forwardsSettings || !chatInviteSettings + !phoneNumberSettings + || !lastSeenSettings + || !profilePhotoSettings + || !forwardsSettings + || !chatInviteSettings + || !phoneCallSettings + || !phoneP2PSettings ) { return; } @@ -335,6 +349,8 @@ addActionHandler('loadPrivacySettings', async (global) => { profilePhoto: profilePhotoSettings, forwards: forwardsSettings, chatInvite: chatInviteSettings, + phoneCall: phoneCallSettings, + phoneP2P: phoneP2PSettings, }, }, }); diff --git a/src/types/index.ts b/src/types/index.ts index 5b3c024b4..c860f90c8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -169,6 +169,8 @@ export enum SettingsScreens { PrivacyPhoneNumber, PrivacyLastSeen, PrivacyProfilePhoto, + PrivacyPhoneCall, + PrivacyPhoneP2P, PrivacyForwarding, PrivacyGroupChats, PrivacyPhoneNumberAllowedContacts, @@ -177,6 +179,10 @@ export enum SettingsScreens { PrivacyLastSeenDeniedContacts, PrivacyProfilePhotoAllowedContacts, PrivacyProfilePhotoDeniedContacts, + PrivacyPhoneCallAllowedContacts, + PrivacyPhoneCallDeniedContacts, + PrivacyPhoneP2PAllowedContacts, + PrivacyPhoneP2PDeniedContacts, PrivacyForwardingAllowedContacts, PrivacyForwardingDeniedContacts, PrivacyGroupChatsAllowedContacts, @@ -308,7 +314,8 @@ export enum NewChatMembersProgress { export type ProfileTabType = 'members' | 'commonChats' | 'media' | 'documents' | 'links' | 'audio' | 'voice'; export type SharedMediaType = 'media' | 'documents' | 'links' | 'audio' | 'voice'; -export type ApiPrivacyKey = 'phoneNumber' | 'lastSeen' | 'profilePhoto' | 'forwards' | 'chatInvite'; +export type ApiPrivacyKey = 'phoneNumber' | 'lastSeen' | 'profilePhoto' | +'forwards' | 'chatInvite' | 'phoneCall' | 'phoneP2P'; export type PrivacyVisibility = 'everybody' | 'contacts' | 'nonContacts' | 'nobody'; export enum ProfileState {