Added message framework

This commit is contained in:
hydrabolt
2015-08-15 15:25:51 +01:00
parent b0fb506221
commit 4e3b6262ca
4 changed files with 191 additions and 81 deletions

View File

@@ -14,7 +14,7 @@ exports.Channel = function(name, server, type, id, isPrivate){
this.type = type;
this.id = id;
this.isPrivate = isPrivate;
this.messages = new List("id", "5000");
}
exports.Channel.equals = function(otherChannel){

View File

@@ -1,20 +1,32 @@
exports.List = function( discriminator ) {
exports.List = function( discriminator, cap ) {
this.discriminator = discriminator;
this.cap = cap || Number.MAX_SAFE_INTEGER;
this.contents = [];
}
exports.List.prototype.add = function( child ) {
var self = this;
if ( child.constructor === Array ) {
children = child;
for ( child of children ) {
if ( this.filter( this.discriminator, child[ this.discriminator ] ).length === 0 )
this.contents.push( child );
addChild(child);
}
} else {
if ( this.filter( this.discriminator, child[ this.discriminator ] ).length === 0 )
this.contents.push( child );
addChild(child);
}
function addChild(child){
if(self.length() > cap){
self.splice(0, 1);
}
if ( self.filter( self.discriminator, child[ self.discriminator ] ).length === 0 )
self.contents.push( child );
}
}