diff --git a/index.js b/index.js index 605f91167..f6c928015 100644 --- a/index.js +++ b/index.js @@ -238,17 +238,18 @@ exports.Client.prototype.createServer = function( _name, _region, cb ) { } -exports.Client.prototype.leaveServer = function( server, cb ){ +exports.Client.prototype.leaveServer = function( server, cb ) { var client = this; request - .del( Endpoints.SERVERS + "/" + server.id) + .del( Endpoints.SERVERS + "/" + server.id ) .set( "authorization", client.token ) - .end( function(err, res){ + .end( function( err, res ) { if ( !res.ok ) { cb( err ); } else { + client.serverList.removeElement( server ); cb( null ); } } ); @@ -277,7 +278,7 @@ exports.Client.prototype.createInvite = function( channel, options, cb ) { if ( !res.ok ) { cb( err ); } else { - cb( false, new Invite(res.body) ); + cb( false, new Invite( res.body ) ); } } ) diff --git a/lib/list.js b/lib/list.js index a57c246e9..613261cd5 100644 --- a/lib/list.js +++ b/lib/list.js @@ -28,14 +28,14 @@ exports.List.prototype.removeIndex = function( index ) { exports.List.prototype.removeElement = function( child ) { - var index = this.contents.indexOf( child ); - - if ( index === -1 ) { - return false; + for ( _element in this.contents ) { + var element = this.contents[_element]; + if ( child[ this.discriminator ] == element[ this.discriminator ] ) { + this.removeIndex( _element, 1 ); + } } - this.removeIndex( index ); - + return false; } exports.List.prototype.concatSublists = function( whereList, discriminator ) { @@ -81,8 +81,8 @@ exports.List.prototype.deepFilter = function( keys, value, onlyOne ) { var child = this.contents[ index ]; var buffer = child; - for(key of keys){ - buffer = buffer[key]; + for ( key of keys ) { + buffer = buffer[ key ]; } if ( buffer == value ) {