Fix buffer closing

0cbf5fc4 uncovered an old bug
Thanks for noticing, @torhve
This commit is contained in:
Lorenz Hübschle-Schneider 2014-05-08 11:05:08 +01:00
parent 60b1c48f14
commit a2073d893e
2 changed files with 10 additions and 5 deletions

View file

@ -40,8 +40,8 @@ weechat.factory('handlers', ['$rootScope', 'models', 'plugins', function($rootSc
var handleBufferClosing = function(message) { var handleBufferClosing = function(message) {
var bufferMessage = message.objects[0].content[0]; var bufferMessage = message.objects[0].content[0];
var buffer = new models.Buffer(bufferMessage); var bufferId = bufferMessage.pointers[0];
models.closeBuffer(buffer); models.closeBuffer(bufferId);
}; };
var handleLine = function(line, manually) { var handleLine = function(line, manually) {

View file

@ -506,11 +506,16 @@ models.service('models', ['$rootScope', '$filter', function($rootScope, $filter)
* @return undefined * @return undefined
*/ */
this.closeBuffer = function(bufferId) { this.closeBuffer = function(bufferId) {
var wasActive = this.model.buffers[bufferId.id].active; var buffer = this.getBuffer(bufferId);
if (wasActive) { // Check if the buffer really exists, just in case
if (buffer === undefined) {
return;
}
if (buffer.active) {
var firstBuffer = _.keys(this.model.buffers)[0]; var firstBuffer = _.keys(this.model.buffers)[0];
this.setActiveBuffer(firstBuffer); 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]);
}; };
}]); }]);