Created ChannelPermissions class

This commit is contained in:
hydrabolt
2015-10-03 20:36:32 +01:00
parent 6d36977f94
commit 6b091128cb
4 changed files with 98 additions and 45 deletions

View File

@@ -0,0 +1,9 @@
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ChannelPermissions = function ChannelPermissions(data) {
_classCallCheck(this, ChannelPermissions);
};
module.exports = ChannelPermissions;

View File

@@ -4,6 +4,8 @@ var _createClass = (function () { function defineProperties(target, props) { for
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ChannelPermissions = require("./ChannelPermissions.js");
var Channel = (function () { var Channel = (function () {
function Channel(data, server) { function Channel(data, server) {
_classCallCheck(this, Channel); _classCallCheck(this, Channel);
@@ -15,7 +17,33 @@ var Channel = (function () {
this.id = data.id; this.id = data.id;
this.messages = []; this.messages = [];
this.roles = []; this.roles = [];
//this.isPrivate = isPrivate; //not sure about the implementation of this...
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = data.permission_overwrites[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var role = _step.value;
this.roles.push(new ChannelPermissions());
}
//this.isPrivate = isPrivate; //not sure about the implementation of this...
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"]) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} }
_createClass(Channel, [{ _createClass(Channel, [{
@@ -40,29 +68,29 @@ var Channel = (function () {
}, { }, {
key: "getMessage", key: "getMessage",
value: function getMessage(key, value) { value: function getMessage(key, value) {
var _iteratorNormalCompletion = true; var _iteratorNormalCompletion2 = true;
var _didIteratorError = false; var _didIteratorError2 = false;
var _iteratorError = undefined; var _iteratorError2 = undefined;
try { try {
for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { for (var _iterator2 = this.messages[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var message = _step.value; var message = _step2.value;
if (message[key] === value) { if (message[key] === value) {
return message; return message;
} }
} }
} catch (err) { } catch (err) {
_didIteratorError = true; _didIteratorError2 = true;
_iteratorError = err; _iteratorError2 = err;
} finally { } finally {
try { try {
if (!_iteratorNormalCompletion && _iterator["return"]) { if (!_iteratorNormalCompletion2 && _iterator2["return"]) {
_iterator["return"](); _iterator2["return"]();
} }
} finally { } finally {
if (_didIteratorError) { if (_didIteratorError2) {
throw _iteratorError; throw _iteratorError2;
} }
} }
} }

View File

@@ -0,0 +1,7 @@
class ChannelPermissions{
constructor(data){
}
}
module.exports = ChannelPermissions;

View File

@@ -1,3 +1,5 @@
var ChannelPermissions = require("./ChannelPermissions.js");
class Channel { class Channel {
constructor(data, server) { constructor(data, server) {
@@ -8,14 +10,21 @@ class Channel {
this.id = data.id; this.id = data.id;
this.messages = []; this.messages = [];
this.roles = []; this.roles = [];
for (var role of data.permission_overwrites) {
this.roles.push( new ChannelPermissions() );
}
//this.isPrivate = isPrivate; //not sure about the implementation of this... //this.isPrivate = isPrivate; //not sure about the implementation of this...
} }
get permissionOverwrites(){ get permissionOverwrites() {
return this.roles; return this.roles;
} }
get permissions(){ get permissions() {
return this.roles; return this.roles;
} }
@@ -27,41 +36,41 @@ class Channel {
return (object && object.id === this.id); return (object && object.id === this.id);
} }
addMessage(data){ addMessage(data) {
if(this.messages.length > 1000){ if (this.messages.length > 1000) {
this.messages.splice(0,1); this.messages.splice(0, 1);
} }
if(!this.getMessage("id", data.id)){ if (!this.getMessage("id", data.id)) {
this.messages.push(data); this.messages.push(data);
} }
return this.getMessage("id", data.id); return this.getMessage("id", data.id);
} }
getMessage(key, value){ getMessage(key, value) {
for(var message of this.messages){ for (var message of this.messages) {
if(message[key] === value){ if (message[key] === value) {
return message; return message;
} }
} }
return null; return null;
} }
toString(){ toString() {
return "<#" + this.id + ">"; return "<#" + this.id + ">";
} }
get isPrivate(){ get isPrivate() {
return false; return false;
} }
get users(){ get users() {
return this.server.members; return this.server.members;
} }
get members(){ get members() {
return this.server.members; return this.server.members;
} }
} }