2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2020-10-15 01:16:37 +08:00
|
|
|
import { delegateRunOnDestroy } from 'Common/UtilsUser';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { PgpUserStore } from 'Stores/User/Pgp';
|
|
|
|
import { SettingsUserStore } from 'Stores/User/Settings';
|
2017-06-29 00:25:53 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/User/Fetch';
|
2014-10-04 19:58:01 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { showScreenPopup } from 'Knoin/Knoin';
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-01-26 05:00:13 +08:00
|
|
|
import { AddOpenPgpKeyPopupView } from 'View/Popup/AddOpenPgpKey';
|
|
|
|
import { NewOpenPgpKeyPopupView } from 'View/Popup/NewOpenPgpKey';
|
|
|
|
import { ViewOpenPgpKeyPopupView } from 'View/Popup/ViewOpenPgpKey';
|
|
|
|
|
2021-01-22 23:32:08 +08:00
|
|
|
export class OpenPgpUserSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2021-03-11 05:41:35 +08:00
|
|
|
this.openpgpkeys = PgpUserStore.openpgpkeys;
|
|
|
|
this.openpgpkeysPublic = PgpUserStore.openpgpkeysPublic;
|
|
|
|
this.openpgpkeysPrivate = PgpUserStore.openpgpkeysPrivate;
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
this.openPgpKeyForDeletion = ko.observable(null).deleteAccessHelper();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
this.allowDraftAutosave = SettingsUserStore.allowDraftAutosave;
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
addOpenPgpKey() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(AddOpenPgpKeyPopupView);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
generateOpenPgpKey() {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(NewOpenPgpKeyPopupView);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
viewOpenPgpKey(openPgpKey) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (openPgpKey) {
|
2021-01-26 05:00:13 +08:00
|
|
|
showScreenPopup(ViewOpenPgpKeyPopupView, [openPgpKey]);
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
/**
|
|
|
|
* @param {OpenPgpKeyModel} openPgpKeyToRemove
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
deleteOpenPgpKey(openPgpKeyToRemove) {
|
2019-07-05 03:19:24 +08:00
|
|
|
if (openPgpKeyToRemove && openPgpKeyToRemove.deleteAccess()) {
|
2016-07-16 05:29:42 +08:00
|
|
|
this.openPgpKeyForDeletion(null);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
if (openPgpKeyToRemove && PgpUserStore.openpgpKeyring) {
|
|
|
|
const findedItem = PgpUserStore.openpgpkeys.find(key => openPgpKeyToRemove === key);
|
2019-07-05 03:19:24 +08:00
|
|
|
if (findedItem) {
|
2021-03-11 05:41:35 +08:00
|
|
|
PgpUserStore.openpgpkeys.remove(findedItem);
|
2016-07-16 05:29:42 +08:00
|
|
|
delegateRunOnDestroy(findedItem);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
PgpUserStore.openpgpKeyring[findedItem.isPrivate ? 'privateKeys' : 'publicKeys'].removeForId(findedItem.guid);
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
PgpUserStore.openpgpKeyring.store();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-15 15:29:25 +08:00
|
|
|
rl.app.reloadOpenPgpKeys();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 00:25:53 +08:00
|
|
|
|
|
|
|
onBuild() {
|
2020-07-23 02:28:25 +08:00
|
|
|
setTimeout(() => {
|
2020-07-30 03:49:41 +08:00
|
|
|
this.allowDraftAutosave.subscribe(Remote.saveSettingsHelper('AllowDraftAutosave', v=>v?'1':'0'));
|
2020-08-14 04:58:41 +08:00
|
|
|
}, 50);
|
2017-06-29 00:25:53 +08:00
|
|
|
}
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|