From 73d030dd69c926fe44b9ffc2f43471e829f92022 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Tue, 22 Jun 2021 05:11:17 +0300 Subject: [PATCH] Privacy: sensitive content --- .../sidebarLeft/tabs/privacyAndSecurity.ts | 40 +++++++++++++++++-- src/config/app.ts | 2 +- src/lang.ts | 3 ++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/components/sidebarLeft/tabs/privacyAndSecurity.ts b/src/components/sidebarLeft/tabs/privacyAndSecurity.ts index 5a387bd4..0da731a4 100644 --- a/src/components/sidebarLeft/tabs/privacyAndSecurity.ts +++ b/src/components/sidebarLeft/tabs/privacyAndSecurity.ts @@ -4,7 +4,7 @@ * https://github.com/morethanwords/tweb/blob/master/LICENSE */ -import { SliderSuperTab } from "../../slider"; +import { SliderSuperTabEventable } from "../../sliderTab"; import { SettingSection } from ".."; import Row from "../../row"; import { AccountPassword, Authorization, InputPrivacyKey } from "../../../layer"; @@ -27,12 +27,13 @@ import rootScope from "../../../lib/rootScope"; import { convertKeyToInputKey } from "../../../helpers/string"; import { i18n, LangPackKey, _i18n } from "../../../lib/langPack"; import replaceContent from "../../../helpers/dom/replaceContent"; +import CheckboxField from "../../checkboxField"; -export default class AppPrivacyAndSecurityTab extends SliderSuperTab { +export default class AppPrivacyAndSecurityTab extends SliderSuperTabEventable { private activeSessionsRow: Row; private authorizations: Authorization.authorization[]; - protected init() { + protected async init() { this.container.classList.add('privacy-container'); this.setTitle('PrivacySettings'); @@ -224,6 +225,39 @@ export default class AppPrivacyAndSecurityTab extends SliderSuperTab { updatePrivacyRow(convertKeyToInputKey(update.key._) as any); }); } + + { + await apiManager.invokeApi('account.getContentSettings').then(settings => { + if(!settings.pFlags.sensitive_can_change) { + return; + } + + const enabled = settings.pFlags.sensitive_enabled; + const section = new SettingSection({name: 'Privacy.SensitiveContent'}); + + const sensitiveRow = new Row({ + checkboxField: new CheckboxField({text: 'PrivacyAndSecurity.SensitiveText', checked: enabled}), + subtitleLangKey: 'PrivacyAndSecurity.SensitiveDesc', + noCheckboxSubtitle: true + }); + + section.content.append(sensitiveRow.container); + + this.scrollable.append(section.container); + + this.eventListener.addEventListener('destroy', () => { + const _enabled = sensitiveRow.checkboxField.checked; + const isChanged = _enabled !== enabled; + if(!isChanged) { + return; + } + + apiManager.invokeApi('account.setContentSettings', { + sensitive_enabled: _enabled + }); + }, true); + }); + } } public updateActiveSessions() { diff --git a/src/config/app.ts b/src/config/app.ts index f04c962d..651695c9 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -15,7 +15,7 @@ const App = { id: 1025907, hash: '452b0359b988148995f22ff0f4229750', version: '0.5.7', - langPackVersion: '0.2.4', + langPackVersion: '0.2.5', langPack: 'macos', langPackCode: 'en', domains: [] as string[], diff --git a/src/lang.ts b/src/lang.ts index 96af6d5c..b00c0896 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -82,6 +82,7 @@ const lang = { "one_value": "%1$d device", "other_value": "%1$d devices" }, + "Privacy.SensitiveContent": "Sensitive Content", "PrivacyModal.Search.Placeholder": "Add Users or Groups...", "Permissions.NoExceptions": "No exceptions", "Permissions.ExceptionsCount": { @@ -683,6 +684,8 @@ const lang = { }, "PrivacyAndSecurity.Item.On": "On", "PrivacyAndSecurity.Item.Off": "Off", + "PrivacyAndSecurity.SensitiveText": "Disable filtering", + "PrivacyAndSecurity.SensitiveDesc": "Display sensitive media in public channels on all your Telegram devices.", "PrivacySettings.VoiceCalls": "Calls", "PrivacySettings.Forwards": "Forwarded Messages", "PrivacySettings.Groups": "Groups and Channels",