diff options
Diffstat (limited to '')
-rw-r--r-- | lang/js/src/Message.js | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js index 06ac8db2..4d242277 100644 --- a/lang/js/src/Message.js +++ b/lang/js/src/Message.js @@ -19,13 +19,34 @@ */ import { permittedOperations } from './permittedOperations' import { gpgme_error } from './Errors' -export class GPGME_Message { + +export function createMessage(operation){ + if (typeof(operation) !== 'string'){ + return gpgme_error('PARAM_WRONG'); + } + if (permittedOperations.hasOwnProperty(operation)){ + return new GPGME_Message(operation); + } else { + return gpgme_error('MSG_WRONG_OP'); + } +} + +/** + * Prepares a communication request. It checks operations and parameters in + * ./permittedOperations. + * @param {String} operation + */ +class GPGME_Message { //TODO getter constructor(operation){ - setOperation(this, operation); + this.operation = operation; } + set operation (op){ + + + } get operation(){ return this._msg.op; } @@ -41,9 +62,6 @@ export class GPGME_Message { if (!param || typeof(param) !== 'string'){ return gpgme_error('PARAM_WRONG'); } - if (!this._msg || !this._msg.op){ - return gpgme_error('MSG_OP_PENDING'); - } let po = permittedOperations[this._msg.op]; if (!po){ return gpgme_error('MSG_WRONG_OP'); @@ -90,22 +108,3 @@ export class GPGME_Message { } } - -/** - * Defines the operation this message will have - * @param {String} operation Must be defined in permittedOperations - * TODO: move to constructor? - */ -function setOperation (scope, operation){ - if (!operation || typeof(operation) !== 'string'){ - return gpgme_error('PARAM_WRONG'); - } - if (permittedOperations.hasOwnProperty(operation)){ - if (!scope._msg){ - scope._msg = {}; - } - scope._msg.op = operation; - } else { - return gpgme_error('MSG_WRONG_OP'); - } -}
\ No newline at end of file |