Added delete cloud drafts button

This commit is contained in:
Eduard Kuzmenko 2021-07-03 18:31:57 +03:00
parent ae1482e970
commit 124388d878
4 changed files with 80 additions and 9 deletions

View File

@ -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<any>[] = [];
{
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() {

View File

@ -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[],

View File

@ -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",

View File

@ -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();