From babbfdb3d784976789125618d6478aebe79a1782 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sat, 3 Jul 2021 18:31:57 +0300 Subject: [PATCH] Added delete cloud drafts button --- .../sidebarLeft/tabs/privacyAndSecurity.ts | 62 ++++++++++++++++--- src/config/app.ts | 2 +- src/lang.ts | 7 +++ src/lib/appManagers/appDraftsManager.ts | 18 ++++++ 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/components/sidebarLeft/tabs/privacyAndSecurity.ts b/src/components/sidebarLeft/tabs/privacyAndSecurity.ts index 992c9235..a784d65c 100644 --- a/src/components/sidebarLeft/tabs/privacyAndSecurity.ts +++ b/src/components/sidebarLeft/tabs/privacyAndSecurity.ts @@ -7,7 +7,7 @@ import { SliderSuperTabEventable } from "../../sliderTab"; import { SettingSection } from ".."; import Row from "../../row"; -import { AccountPassword, Authorization, InputPrivacyKey } from "../../../layer"; +import { AccountPassword, Authorization, InputPrivacyKey, Updates } from "../../../layer"; import appPrivacyManager, { PrivacyType } from "../../../lib/appManagers/appPrivacyManager"; import AppPrivacyPhoneNumberTab from "./privacy/phoneNumber"; import AppTwoStepVerificationTab from "./2fa"; @@ -28,12 +28,15 @@ import { convertKeyToInputKey } from "../../../helpers/string"; import { i18n, LangPackKey, _i18n } from "../../../lib/langPack"; import replaceContent from "../../../helpers/dom/replaceContent"; import CheckboxField from "../../checkboxField"; +import PopupPeer from "../../popups/peer"; +import appDraftsManager from "../../../lib/appManagers/appDraftsManager"; +import Button from "../../button"; export default class AppPrivacyAndSecurityTab extends SliderSuperTabEventable { private activeSessionsRow: Row; private authorizations: Authorization.authorization[]; - protected async init() { + protected init() { this.container.classList.add('dont-u-dare-block-me'); this.setTitle('PrivacySettings'); @@ -226,14 +229,16 @@ export default class AppPrivacyAndSecurityTab extends SliderSuperTabEventable { }); } + const promises: Promise[] = []; { - await apiManager.invokeApi('account.getContentSettings').then(settings => { + const section = new SettingSection({name: 'Privacy.SensitiveContent'}); + + promises.push(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}), @@ -243,21 +248,62 @@ export default class AppPrivacyAndSecurityTab extends SliderSuperTabEventable { 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); - }); + })); + + this.scrollable.append(section.container); + } + + { + const section = new SettingSection({name: 'FilterChats'}); + + const onDeleteClick = () => { + const popup = new PopupPeer('popup-delete-drafts', { + buttons: [{ + langKey: 'Delete', + callback: () => { + appDraftsManager.clearAllDrafts(); + }, + isDanger: true, + }], + titleLangKey: 'AreYouSureClearDraftsTitle', + descriptionLangKey: 'AreYouSureClearDrafts' + }); + + popup.show(); + }; + + const deleteButton = Button('btn-primary btn-transparent', {icon: 'delete', text: 'PrivacyDeleteCloudDrafts'}); + this.listenerSetter.add(deleteButton, 'click', onDeleteClick); + section.content.append(deleteButton); + + /* promises.push(apiManager.invokeApi('messages.getAllDrafts').then(drafts => { + const draftsRow = new Row({ + titleLangKey: 'PrivacyDeleteCloudDrafts', + subtitleLangKey: 'Drafts', + subtitleLangArgs: [(drafts as Updates.updates).updates.length], + icon: 'delete', + clickable: onDeleteClick + }); + + section.content.append(draftsRow.container); + })); */ + + this.scrollable.append(section.container); } + + return Promise.all(promises); } public updateActiveSessions() { diff --git a/src/config/app.ts b/src/config/app.ts index c91153fa..86cabb4b 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -17,7 +17,7 @@ const App = { id: 1025907, hash: '452b0359b988148995f22ff0f4229750', version: '0.5.9', - langPackVersion: '0.2.9', + langPackVersion: '0.3.0', langPack: 'macos', langPackCode: 'en', domains: [MAIN_DOMAIN] as string[], diff --git a/src/lang.ts b/src/lang.ts index fb249918..fc90b727 100644 --- a/src/lang.ts +++ b/src/lang.ts @@ -54,6 +54,10 @@ const lang = { "ConnectionStatus.Waiting": "Waiting for network...", "Deactivated.Title": "Too many tabs...", "Deactivated.Subtitle": "Telegram supports only one active tab with the app.\nClick anywhere to continue using this tab.", + /* "Drafts": { + "one_value": "%d draft", + "other_value": "%d drafts", + }, */ "General.Keyboard": "Keyboard", "General.SendShortcut.Enter": "Send by Enter", "General.SendShortcut.CtrlEnter": "Send by %s + Enter", @@ -486,6 +490,9 @@ const lang = { "ViaBot": "via", "InviteExpired": "This invite link has expired.", "NoUsernameFound": "There is no Telegram account with this username.", + "PrivacyDeleteCloudDrafts": "Delete All Cloud Drafts", + "AreYouSureClearDraftsTitle": "Delete cloud drafts", + "AreYouSureClearDrafts": "Are you sure you want to delete all cloud drafts?", // * macos "AccountSettings.Filters": "Chat Folders", diff --git a/src/lib/appManagers/appDraftsManager.ts b/src/lib/appManagers/appDraftsManager.ts index 759f844c..bb91acf8 100644 --- a/src/lib/appManagers/appDraftsManager.ts +++ b/src/lib/appManagers/appDraftsManager.ts @@ -227,6 +227,24 @@ export class AppDraftsManager { return true; } + + public clearAllDrafts() { + return apiManager.invokeApi('messages.clearAllDrafts').then(bool => { + if(!bool) { + return; + } + + for(const peerId in this.drafts) { + const splitted = peerId.split('_'); + const threadId = splitted[1]; + rootScope.dispatchEvent('draft_updated', { + peerId: +splitted[0], + threadId: threadId ? +threadId : undefined, + draft: undefined + }); + } + }); + } } const appDraftsManager = new AppDraftsManager();