From 63d0de134400056988337acddc4a8bbeee3601fe Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Fri, 28 Feb 2014 18:38:38 +0100 Subject: [PATCH] Fixed loosing buddies in the buddy list when they there pushed before. --- static/js/services/buddydata.js | 6 +++++- static/js/services/buddylist.js | 17 ++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/static/js/services/buddydata.js b/static/js/services/buddydata.js index a289c537..704850dc 100644 --- a/static/js/services/buddydata.js +++ b/static/js/services/buddydata.js @@ -61,7 +61,7 @@ define(['underscore'], function(underscore) { get: function(id, createInParent, afterCreateCallback) { if (scopes.hasOwnProperty(id)) { return scopes[id]; - } else if (pushed.hasOwnProperty(id)) { + } else if (!createInParent && pushed.hasOwnProperty(id)) { return pushed[id].scope; } else { if (createInParent) { @@ -69,6 +69,10 @@ define(['underscore'], function(underscore) { var scope = scopes[id] = createInParent.$new(); scope.buddyIndex = ++count; scope.buddyIndexSortable = ("0000000" + scope.buddyIndex).slice(-7); + if (pushed.hasOwnProperty(id)) { + // Refresh pushed scope reference. + pushed[id].scope = scope; + } if (afterCreateCallback) { afterCreateCallback(scope); } diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index 13cf32f5..12813cd5 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -190,6 +190,10 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! } return scope.doCall(id); }; + scope.$on("$destroy", function() { + scope.element = null; + scope.killed = true; + }); }; @@ -220,10 +224,9 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! // Cleanup lefts. var lefts = this.lefts; if (!_.isEmpty(lefts)) { - _.each(lefts, function(v, k) { - if (v.element) { - v.element.remove(); - v.element = null; + _.each(lefts, function(element, k) { + if (element) { + element.remove(); } }); this.lefts = {}; @@ -367,7 +370,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! //console.log("Left", user); var id = user.Id; this.tree.remove(id); - var scope = buddyData.del(id); + var scope = buddyData.get(id); if (!scope) { //console.warn("Trying to remove buddy with no registered scope", user); return; @@ -375,11 +378,11 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! if (buddyCount>0) { buddyCount--; } - scope.killed = true; if (scope.element) { - this.lefts[id] = scope; + this.lefts[id] = scope.element; this.playSoundLeft = true; } + buddyData.del(id); delete this.actionElements[id]; };