mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-11 00:14:50 +03:00
*.jsx -> *.js
This commit is contained in:
parent
0a2b826f71
commit
e88c193334
98 changed files with 341 additions and 340 deletions
87
dev/Model/OpenPgpKey.js
Normal file
87
dev/Model/OpenPgpKey.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
|
||||
import ko from 'ko';
|
||||
|
||||
import {isNonEmptyArray, log} from 'Common/Utils';
|
||||
|
||||
import {AbstractModel} from 'Knoin/AbstractModel';
|
||||
|
||||
import PgpStore from 'Stores/User/Pgp';
|
||||
|
||||
class OpenPgpKeyModel extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* @param {string} index
|
||||
* @param {string} guID
|
||||
* @param {string} ID
|
||||
* @param {array} IDs
|
||||
* @param {array} userIDs
|
||||
* @param {array} emails
|
||||
* @param {boolean} isPrivate
|
||||
* @param {string} armor
|
||||
* @param {string} userID
|
||||
*/
|
||||
constructor(index, guID, ID, IDs, userIDs, emails, isPrivate, armor, userID)
|
||||
{
|
||||
super('OpenPgpKeyModel');
|
||||
|
||||
this.index = index;
|
||||
this.id = ID;
|
||||
this.ids = isNonEmptyArray(IDs) ? IDs : [ID];
|
||||
this.guid = guID;
|
||||
this.user = '';
|
||||
this.users = userIDs;
|
||||
this.email = '';
|
||||
this.emails = emails;
|
||||
this.armor = armor;
|
||||
this.isPrivate = !!isPrivate;
|
||||
|
||||
this.selectUser(userID);
|
||||
|
||||
this.deleteAccess = ko.observable(false);
|
||||
}
|
||||
|
||||
getNativeKey() {
|
||||
let key = null;
|
||||
try
|
||||
{
|
||||
key = PgpStore.openpgp.key.readArmored(this.armor);
|
||||
if (key && !key.err && key.keys && key.keys[0])
|
||||
{
|
||||
return key;
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
log(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getNativeKeys() {
|
||||
const key = this.getNativeKey();
|
||||
return key && key.keys ? key.keys : null;
|
||||
}
|
||||
|
||||
select(pattern, property) {
|
||||
if (this[property])
|
||||
{
|
||||
const index = this[property].indexOf(pattern);
|
||||
if (-1 !== index)
|
||||
{
|
||||
this.user = this.users[index];
|
||||
this.email = this.emails[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectUser(user) {
|
||||
this.select(user, 'users');
|
||||
}
|
||||
|
||||
selectEmail(email) {
|
||||
this.select(email, 'emails');
|
||||
}
|
||||
}
|
||||
|
||||
export {OpenPgpKeyModel, OpenPgpKeyModel as default};
|
||||
Loading…
Add table
Add a link
Reference in a new issue