podchat
Version:
Javascript SDK to use POD's Chat Service
47 lines (39 loc) • 1.26 kB
JavaScript
import {errorList} from "../errorHandler";
class TypeCodes {
constructor({
app,
current = {typeCode: 'default', ownerId: undefined},
whiteList = null
}) {
this._list = whiteList || [];
this._current = current;
this._app = app;
}
hasWhiteList() {
return this._list.length;
}
getActiveTypeCode() {
return this._current;
}
setActiveTypeCode(typeCode) {
if (this.hasWhiteList()) {
let existObject = this._list.find(it => it.typeCode == typeCode)
if (existObject) {
this._current = existObject;
} else {
this._app.errorHandler.raiseError(errorList.INVALID_CONTACT_TYPE, null, true, {});
}
} else {
this._current = {typeCode, ownerId: undefined};
}
}
isAllowed(typeCode) {
if (this._current.typeCode == typeCode)
return true;
let existObject = this._list.find(it => it.typeCode == typeCode);
if (this.hasWhiteList() && !!existObject)
return true;
return false;
}
}
export default TypeCodes