diff --git a/js/glowingbear.js b/js/glowingbear.js index 83b9850..5922cff 100644 --- a/js/glowingbear.js +++ b/js/glowingbear.js @@ -40,8 +40,8 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc var handleBufferClosing = function(message) { var bufferMessage = message.objects[0].content[0]; - var buffer = new models.Buffer(bufferMessage); - models.closeBuffer(buffer); + var bufferId = bufferMessage.pointers[0]; + models.closeBuffer(bufferId); }; var handleLine = function(line, manually) { diff --git a/js/models.js b/js/models.js index fe3f7e8..c4a7770 100644 --- a/js/models.js +++ b/js/models.js @@ -506,11 +506,16 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter) * @return undefined */ this.closeBuffer = function(bufferId) { - var wasActive = this.model.buffers[bufferId.id].active; - if (wasActive) { + var buffer = this.getBuffer(bufferId); + // Check if the buffer really exists, just in case + if (buffer === undefined) { + return; + } + if (buffer.active) { var firstBuffer = _.keys(this.model.buffers)[0]; this.setActiveBuffer(firstBuffer); } - delete(this.model.buffers[bufferId.id]); + // Can't use `buffer` here, needs to be deleted from the list + delete(this.model.buffers[bufferId]); }; }]);