AnP/Public/ecma/Models/SessionModel.ecma.js

70 lines
1.8 KiB
JavaScript

"use strict";
import {Common} from "../Utils/Common.ecma.js";
/**
* @class SessionModel
* @constructor
* @param {!(Object.<string, any|null>|Array.<any|null>)} inputs
* @return {void}
* @access private
* @static
*/
export const SessionModel = (function(){
/**
* @constructs SessionModel
* @param {!number} i
* @param {!(Object.<string, any|null>|Array.<any|null>)} inputs
* @return {void}
* @access private
* @static
*/
const SessionModel = function(i, inputs){
/** @type {SessionModel} */
const self = this;
/** @type {number|null} */
let id = null,
/** @type {Array.<string>} */
permissions = [],
/** @type {number} */
last_check = 0;
/** @type {string|null} */
this.nick = null;
/** @type {number} */
this.type = SessionModel.LOCAL;
/** @type {number} */
this.i = i;
/**
* @returns {void}
* @access private
*/
const constructor = () => {
id = Common.get_value("id", inputs, null);
permissions = Common.get_value("permissions", inputs, []);
self.nick = Common.get_value("nick", inputs, null);
self.type = Common.get_value("type", inputs, self.type);
last_check = Date.now();
};
/**
* @param {!(string|Array.<string>)} permissions
* @returns {boolean}
* @access public
*/
this.check_permissions = permissions => permissions.some(self.permissions.includes);
constructor();
};
/** @type {number} */
SessionModel.LOCAL = 1 << 0;
/** @type {number} */
SessionModel.REMOTE = 1 << 1;
return SessionModel;
})();