diff --git a/src/api/gramjs/methods/index.ts b/src/api/gramjs/methods/index.ts index a11701927..b99e3d773 100644 --- a/src/api/gramjs/methods/index.ts +++ b/src/api/gramjs/methods/index.ts @@ -47,7 +47,7 @@ export { fetchAuthorizations, terminateAuthorization, terminateAllAuthorizations, fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings, fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice, - updateIsOnline, + updateIsOnline, fetchContentSettings, updateContentSettings, } from './settings'; export { diff --git a/src/api/gramjs/methods/settings.ts b/src/api/gramjs/methods/settings.ts index 3d2083817..e18f0d287 100644 --- a/src/api/gramjs/methods/settings.ts +++ b/src/api/gramjs/methods/settings.ts @@ -375,6 +375,24 @@ export async function updateIsOnline(isOnline: boolean) { await invokeRequest(new GramJs.account.UpdateStatus({ offline: !isOnline })); } +export async function fetchContentSettings() { + const result = await invokeRequest(new GramJs.account.GetContentSettings()); + if (!result) { + return undefined; + } + + return { + isSensitiveEnabled: Boolean(result.sensitiveEnabled), + canChangeSensitive: Boolean(result.sensitiveCanChange), + }; +} + +export function updateContentSettings(isEnabled: boolean) { + return invokeRequest(new GramJs.account.SetContentSettings({ + sensitiveEnabled: isEnabled || undefined, + })); +} + function updateLocalDb( result: ( GramJs.account.PrivacyRules | GramJs.contacts.Blocked | GramJs.contacts.BlockedSlice | diff --git a/src/components/left/settings/SettingsGeneral.tsx b/src/components/left/settings/SettingsGeneral.tsx index 103e51fae..2e3e4e13e 100644 --- a/src/components/left/settings/SettingsGeneral.tsx +++ b/src/components/left/settings/SettingsGeneral.tsx @@ -24,12 +24,28 @@ type OwnProps = { onScreenSelect: (screen: SettingsScreens) => void; }; -type StateProps = ISettings['byKey'] & { +type StateProps = Pick & { stickerSetIds?: string[]; stickerSetsById?: Record; }; -type DispatchProps = Pick; +type DispatchProps = Pick; const ANIMATION_LEVEL_OPTIONS = [ 'Solid and Steady', @@ -52,9 +68,13 @@ const SettingsGeneral: FC = ({ shouldAutoPlayVideos, shouldSuggestStickers, shouldLoopStickers, + isSensitiveEnabled, + canChangeSensitive, setSettingOption, loadStickerSets, loadAddedStickers, + loadContentSettings, + updateContentSettings, }) => { // eslint-disable-next-line no-null/no-null const stickerSettingsRef = useRef(null); @@ -75,7 +95,8 @@ const SettingsGeneral: FC = ({ useEffect(() => { loadStickerSets(); - }, [loadStickerSets]); + loadContentSettings(); + }, [loadContentSettings, loadStickerSets]); useEffect(() => { if (stickerSetIds && stickerSetIds.length) { @@ -104,7 +125,7 @@ const SettingsGeneral: FC = ({ const stickerSets = stickerSetIds && stickerSetIds.map((id: string) => { return stickerSetsById && stickerSetsById[id] && stickerSetsById[id].installedDate ? stickerSetsById[id] : false; - }).filter(Boolean); + }).filter(Boolean as any); return (
@@ -155,6 +176,19 @@ const SettingsGeneral: FC = ({
)} +
+

+ {lang('lng_settings_sensitive_title')} +

+ +
+

{lang('AutoDownloadMedia')}

@@ -234,25 +268,26 @@ const SettingsGeneral: FC = ({ export default memo(withGlobal( (global): StateProps => { return { - ...pick(global.settings.byKey, - [ - 'messageTextSize', - 'animationLevel', - 'messageSendKeyCombo', - 'shouldAutoDownloadMediaFromContacts', - 'shouldAutoDownloadMediaInPrivateChats', - 'shouldAutoDownloadMediaInGroups', - 'shouldAutoDownloadMediaInChannels', - 'shouldAutoPlayGifs', - 'shouldAutoPlayVideos', - 'shouldSuggestStickers', - 'shouldLoopStickers', - ]), + ...pick(global.settings.byKey, [ + 'messageTextSize', + 'animationLevel', + 'messageSendKeyCombo', + 'shouldAutoDownloadMediaFromContacts', + 'shouldAutoDownloadMediaInPrivateChats', + 'shouldAutoDownloadMediaInGroups', + 'shouldAutoDownloadMediaInChannels', + 'shouldAutoPlayGifs', + 'shouldAutoPlayVideos', + 'shouldSuggestStickers', + 'shouldLoopStickers', + 'isSensitiveEnabled', + 'canChangeSensitive', + ]), stickerSetIds: global.stickers.added.setIds, stickerSetsById: global.stickers.setsById, }; }, (setGlobal, actions): DispatchProps => pick(actions, [ - 'setSettingOption', 'loadStickerSets', 'loadAddedStickers', + 'setSettingOption', 'loadStickerSets', 'loadAddedStickers', 'loadContentSettings', 'updateContentSettings', ]), )(SettingsGeneral)); diff --git a/src/global/types.ts b/src/global/types.ts index 63da83d38..6f7368344 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -450,7 +450,8 @@ export type ActionTypes = ( 'loadAuthorizations' | 'terminateAuthorization' | 'terminateAllAuthorizations' | 'loadNotificationSettings' | 'updateContactSignUpNotification' | 'updateNotificationSettings' | 'loadLanguages' | 'loadPrivacySettings' | 'setPrivacyVisibility' | 'setPrivacySettings' | - 'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' | + 'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' | 'loadContentSettings' | + 'updateContentSettings' | // Stickers & GIFs 'loadStickerSets' | 'loadAddedStickers' | 'loadRecentStickers' | 'loadFavoriteStickers' | 'loadFeaturedStickers' | 'loadStickers' | 'setStickerSearchQuery' | 'loadSavedGifs' | 'setGifSearchQuery' | 'searchMoreGifs' | diff --git a/src/lib/gramjs/tl/apiTl.js b/src/lib/gramjs/tl/apiTl.js index 9f231b41f..70b8ccd58 100644 --- a/src/lib/gramjs/tl/apiTl.js +++ b/src/lib/gramjs/tl/apiTl.js @@ -942,6 +942,8 @@ account.getContactSignUpNotification#9f07c728 = Bool; account.setContactSignUpNotification#cff43f61 silent:Bool = Bool; account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates; account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper; +account.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool; +account.getContentSettings#8b9b4dae = account.ContentSettings; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; contacts.getContacts#c023849f hash:int = contacts.Contacts; diff --git a/src/lib/gramjs/tl/static/api.reduced.tl b/src/lib/gramjs/tl/static/api.reduced.tl index 14d70170a..dc6c105e5 100644 --- a/src/lib/gramjs/tl/static/api.reduced.tl +++ b/src/lib/gramjs/tl/static/api.reduced.tl @@ -942,6 +942,8 @@ account.getContactSignUpNotification#9f07c728 = Bool; account.setContactSignUpNotification#cff43f61 silent:Bool = Bool; account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates; account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper; +account.setContentSettings#b574b16b flags:# sensitive_enabled:flags.0?true = Bool; +account.getContentSettings#8b9b4dae = account.ContentSettings; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; contacts.getContacts#c023849f hash:int = contacts.Contacts; diff --git a/src/modules/actions/api/settings.ts b/src/modules/actions/api/settings.ts index 6d30cf445..01c01537c 100644 --- a/src/modules/actions/api/settings.ts +++ b/src/modules/actions/api/settings.ts @@ -520,3 +520,23 @@ function buildInputPrivacyRules(global: GlobalState, { addReducer('updateIsOnline', (global, actions, payload) => { callApi('updateIsOnline', payload); }); + +addReducer('loadContentSettings', () => { + (async () => { + const result = await callApi('fetchContentSettings'); + if (!result) return; + + setGlobal(replaceSettings(getGlobal(), result)); + })(); +}); + +addReducer('updateContentSettings', (global, actions, payload) => { + (async () => { + setGlobal(replaceSettings(getGlobal(), { isSensitiveEnabled: payload })); + + const result = await callApi('updateContentSettings', payload); + if (!result) { + setGlobal(replaceSettings(getGlobal(), { isSensitiveEnabled: !payload })); + } + })(); +}); diff --git a/src/types/index.ts b/src/types/index.ts index e4c195e02..6d4bc96b8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -60,6 +60,8 @@ export interface ISettings extends NotifySettings, Record { hasPassword?: boolean; languages?: ApiLanguage[]; language: LangCode; + isSensitiveEnabled?: boolean; + canChangeSensitive?: boolean; } export interface ApiPrivacySettings {