2019-07-05 03:19:24 +08:00
|
|
|
import { StorageResultType, Notification } from 'Common/Enums';
|
|
|
|
import { i18n, getNotification } from 'Common/Translator';
|
|
|
|
import { setFolderHash } from 'Common/Cache';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import MessageStore from 'Stores/User/Message';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
import { command } from 'Knoin/Knoin';
|
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
|
|
|
|
|
|
|
class FolderClearPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('FolderClear');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
selectedFolder: null,
|
|
|
|
clearingProcess: false,
|
|
|
|
clearingError: ''
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addComputables({
|
|
|
|
folderFullNameForClear: () => {
|
|
|
|
const folder = this.selectedFolder();
|
|
|
|
return folder ? folder.printableFullName() : '';
|
|
|
|
},
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
folderNameForClear: () => {
|
|
|
|
const folder = this.selectedFolder();
|
|
|
|
return folder ? folder.localName() : '';
|
|
|
|
},
|
|
|
|
|
|
|
|
dangerDescHtml: () => i18n('POPUPS_CLEAR_FOLDER/DANGER_DESC_HTML_1', { 'FOLDER': this.folderNameForClear() })
|
|
|
|
});
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@command((self) => {
|
2019-07-05 03:19:24 +08:00
|
|
|
const folder = self.selectedFolder(),
|
2016-09-10 06:38:16 +08:00
|
|
|
isClearing = self.clearingProcess();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
return !isClearing && null !== folder;
|
|
|
|
})
|
|
|
|
clearCommand() {
|
|
|
|
const folderToClear = this.selectedFolder();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folderToClear) {
|
2016-09-10 06:38:16 +08:00
|
|
|
MessageStore.message(null);
|
|
|
|
MessageStore.messageList([]);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
this.clearingProcess(true);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
folderToClear.messageCountAll(0);
|
|
|
|
folderToClear.messageCountUnread(0);
|
2014-08-26 23:24:47 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
setFolderHash(folderToClear.fullNameRaw, '');
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
Remote.folderClear((result, data) => {
|
|
|
|
this.clearingProcess(false);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (StorageResultType.Success === result && data && data.Result) {
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.reloadMessageList(true);
|
2016-09-10 06:38:16 +08:00
|
|
|
this.cancelCommand();
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
|
|
|
if (data && data.ErrorCode) {
|
2016-09-10 06:38:16 +08:00
|
|
|
this.clearingError(getNotification(data.ErrorCode));
|
2019-07-05 03:19:24 +08:00
|
|
|
} else {
|
2016-09-10 06:38:16 +08:00
|
|
|
this.clearingError(getNotification(Notification.MailServerError));
|
2013-11-16 06:21:12 +08:00
|
|
|
}
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
}, folderToClear.fullNameRaw);
|
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearPopup() {
|
|
|
|
this.clearingProcess(false);
|
|
|
|
this.selectedFolder(null);
|
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow(folder) {
|
|
|
|
this.clearPopup();
|
2019-07-05 03:19:24 +08:00
|
|
|
if (folder) {
|
2016-08-17 06:01:20 +08:00
|
|
|
this.selectedFolder(folder);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { FolderClearPopupView, FolderClearPopupView as default };
|