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"); } }
var ChannelPermissions = require("./ChannelPermissions.js");
var Channel = (function () {
function Channel(data, server) {
_classCallCheck(this, Channel);
@@ -15,7 +17,33 @@ var Channel = (function () {
this.id = data.id;
this.messages = [];
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, [{
@@ -40,29 +68,29 @@ var Channel = (function () {
}, {
key: "getMessage",
value: function getMessage(key, value) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator = this.messages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var message = _step.value;
for (var _iterator2 = this.messages[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var message = _step2.value;
if (message[key] === value) {
return message;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"]) {
_iterator["return"]();
if (!_iteratorNormalCompletion2 && _iterator2["return"]) {
_iterator2["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
if (_didIteratorError2) {
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 {
constructor(data, server) {
@@ -8,14 +10,21 @@ class Channel {
this.id = data.id;
this.messages = [];
this.roles = [];
for (var role of data.permission_overwrites) {
this.roles.push( new ChannelPermissions() );
}
//this.isPrivate = isPrivate; //not sure about the implementation of this...
}
get permissionOverwrites(){
get permissionOverwrites() {
return this.roles;
}
get permissions(){
get permissions() {
return this.roles;
}
@@ -26,42 +35,42 @@ class Channel {
equals(object) {
return (object && object.id === this.id);
}
addMessage(data){
if(this.messages.length > 1000){
this.messages.splice(0,1);
}
if(!this.getMessage("id", data.id)){
this.messages.push(data);
}
return this.getMessage("id", data.id);
}
getMessage(key, value){
for(var message of this.messages){
if(message[key] === value){
return message;
}
}
return null;
}
toString(){
addMessage(data) {
if (this.messages.length > 1000) {
this.messages.splice(0, 1);
}
if (!this.getMessage("id", data.id)) {
this.messages.push(data);
}
return this.getMessage("id", data.id);
}
getMessage(key, value) {
for (var message of this.messages) {
if (message[key] === value) {
return message;
}
}
return null;
}
toString() {
return "<#" + this.id + ">";
}
get isPrivate(){
get isPrivate() {
return false;
}
get users(){
get users() {
return this.server.members;
}
get members(){
get members() {
return this.server.members;
}
}