diff --git a/static/js/filters/buddyimagesrc.js b/static/js/filters/buddyimagesrc.js index cded8615..852a71c0 100644 --- a/static/js/filters/buddyimagesrc.js +++ b/static/js/filters/buddyimagesrc.js @@ -79,18 +79,18 @@ define(["underscore"], function(_) { var scope = buddyData.lookup(id); if (scope) { - var status = scope.status; - if (status) { - if (status.buddyPictureLocalUrl) { - return status.buddyPictureLocalUrl; - } else if (status.buddyPicture) { + var display = scope.display; + if (display) { + if (display.buddyPictureLocalUrl) { + return display.buddyPictureLocalUrl; + } else if (display.buddyPicture) { var url = urls[id]; if (url) { revokeURL(id, url); } // New data -> new url. - var blob = dataURLToBlob(status.buddyPicture); - url = status.buddyPictureLocalUrl = urls[id] = blobToObjectURL(blob); + var blob = dataURLToBlob(display.buddyPicture); + url = display.buddyPictureLocalUrl = urls[id] = blobToObjectURL(blob); return url; } } diff --git a/static/js/filters/displayname.js b/static/js/filters/displayname.js index ee104a19..f3695968 100644 --- a/static/js/filters/displayname.js +++ b/static/js/filters/displayname.js @@ -35,8 +35,8 @@ define([], function() { } var scope = buddyData.lookup(id); if (scope) { - if (scope.displayName) { - return scope.displayName; + if (scope.display.displayName) { + return scope.display.displayName; } return user_text + " " + scope.buddyIndex; } else { diff --git a/static/js/services/buddylist.js b/static/js/services/buddylist.js index 1d4b7f75..05e999f6 100644 --- a/static/js/services/buddylist.js +++ b/static/js/services/buddylist.js @@ -31,7 +31,8 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! BuddyTree.prototype.create = function(id, scope) { - var sort = scope.displayName ? scope.displayName : "session " + scope.buddyIndexSortable + " " + id; + var display = scope.display || {}; + var sort = display.displayName ? display.displayName : "session " + scope.buddyIndexSortable + " " + id; var data = { id: id, sort: sort + "z" + id @@ -196,9 +197,12 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; - Buddylist.prototype.onBuddyScopeCreated = function(scope) { + Buddylist.prototype.onBuddyScopeCreated = function(scope, data) { scope.element = null; + scope.display = {}; + scope.session = buddySession.create(data); + scope.doDefault = function() { var id = scope.session.Id; if (scope.status.isMixer) { @@ -383,13 +387,58 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }; + Buddylist.prototype.setDisplay = function(id, scope, data, queueName) { + + var status = data.Status; + var display = scope.display; + // Set display.name. + display.displayName = status.displayName; + // Set display.picture. + display.buddyPicture = status.buddyPicture; + this.updateBuddyPicture(display); + // Set display subline. + display.subLine = data.Ua; + // Add to render queue when no element exists. + if (!scope.element) { + var before = this.tree.add(id, scope); + this.queue.push([queueName, id, before]); + this.playSoundJoined = true; + } + + }; + + Buddylist.prototype.updateDisplay = function(id, scope, data, queueName) { + + var status = data.Status; + var display = scope.display; + // Update display name. + var displayName = display.displayName; + if (status.displayName) { + display.displayName = status.displayName; + } else { + display.displayName = null; + } + // Add to status queue if sorting has changed. + if (displayName !== status.displayName) { + var before = this.tree.update(id, scope); + this.queue.push([queueName, id, before]); + } + // Update display subline. + if (data.Ua) { + display.subLine = data.Ua; + } + // Update display picture. + display.buddyPicture = status.buddyPicture || null; + this.updateBuddyPicture(display); + + }; + Buddylist.prototype.onStatus = function(data) { //console.log("onStatus", data); var id = data.Id; var scope = buddyData.get(id, this.$scope, _.bind(function(scope) { - this.onBuddyScopeCreated(scope); - scope.session = buddySession.create(data); + this.onBuddyScopeCreated(scope, data); }, this), data.Userid); // Update session. var sessionData = scope.session.update(id, data, _.bind(function(session) { @@ -398,18 +447,7 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! }, this)); if (sessionData) { // onStatus for main session. - scope.status = sessionData.Status; - var displayName = scope.displayName; - if (sessionData.Status.displayName) { - scope.displayName = sessionData.Status.displayName; - } else { - scope.displayName = null; - } - if (displayName !== scope.displayName) { - var before = this.tree.update(id, scope); - this.queue.push(["status", id, before]); - } - this.updateBuddyPicture(sessionData.Status); + this.updateDisplay(id, scope, sessionData, "status"); } scope.$apply(); @@ -420,21 +458,13 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! //console.log("Joined", data); var id = data.Id; var scope = buddyData.get(id, this.$scope, _.bind(function(scope) { - this.onBuddyScopeCreated(scope); - scope.session = buddySession.create(data); + this.onBuddyScopeCreated(scope, data); }, this), data.Userid); // Update session. buddyCount++; var sessionData = scope.session.update(id, data); if (sessionData && sessionData.Status) { - scope.status = sessionData.Status; - scope.displayName = sessionData.Status.displayName; - this.updateBuddyPicture(sessionData.Status); - if (!scope.element) { - var before = this.tree.add(id, scope); - this.queue.push(["joined", id, before]); - this.playSoundJoined = true; - } + this.setDisplay(id, scope, sessionData, "joined"); } else { scope.$apply(); } @@ -474,7 +504,8 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! if (buddyCount > 0) { buddyCount--; } - if (scope.session.remove(id)) { + var session = scope.session; + if (session.remove(id)) { // No session left. Cleanup. this.tree.remove(id); if (scope.element) { @@ -482,11 +513,14 @@ define(['underscore', 'modernizr', 'avltree', 'text!partials/buddy.html', 'text! this.playSoundLeft = true; } buddyData.del(id); - if (scope.session.Userid) { - buddyData.del(scope.session.Userid); + if (session.Userid) { + buddyData.del(session.Userid); } delete this.actionElements[id]; } else { + // Update display stuff if session left. + var sessionData = session.get(); + this.setDisplay(id, scope, sessionData, "status"); scope.$apply(); } diff --git a/static/js/services/buddysession.js b/static/js/services/buddysession.js index cd240f57..97a43d3d 100644 --- a/static/js/services/buddysession.js +++ b/static/js/services/buddysession.js @@ -97,8 +97,9 @@ define(["underscore"], function(_) { } } if (data.Rev) { - sessionData.Rev = data.Rev; + sessionData.Rev = data.Rev; } + if (data.Status) { sessionData.Status = data.Status; } diff --git a/static/partials/buddy.html b/static/partials/buddy.html index 0fd87c54..2002cb7a 100644 --- a/static/partials/buddy.html +++ b/static/partials/buddy.html @@ -1,5 +1,5 @@ -