diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 8315768f1..a4d84796d 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -1993,9 +1993,11 @@ define([ var loadingAvatar; var to; var oldUrl = ''; + var oldUid = undefined; var updateButton = function () { var myData = metadataMgr.getUserData(); var privateData = metadataMgr.getPrivateData(); + var uid = myData.uid; if (!priv.plan && privateData.plan) { config.$initBlock.empty(); metadataMgr.off('change', updateButton); @@ -2013,15 +2015,16 @@ define([ var newName = myData.name; var url = myData.avatar; $displayName.text(newName || Messages.anonymous); - if (accountName && oldUrl !== url) { + if ((accountName && oldUrl !== url) || !accountName && uid !== oldUid) { $avatar.html(''); Common.displayAvatar($avatar, url, newName || Messages.anonymous, function ($img) { oldUrl = url; + oldUid = uid; $userAdmin.find('> button').removeClass('cp-avatar'); if ($img) { $userAdmin.find('> button').addClass('cp-avatar'); } loadingAvatar = false; - }); + }, uid); return; } loadingAvatar = false; diff --git a/www/common/inner/common-mediatag.js b/www/common/inner/common-mediatag.js index 3d4e82caf..bceb314b8 100644 --- a/www/common/inner/common-mediatag.js +++ b/www/common/inner/common-mediatag.js @@ -94,6 +94,21 @@ define([ return ANIMALS[seed % ANIMALS.length]; }; + var getPrettyInitials = function (name) { + var parts = name.split(/\s+/); + var text; + if (parts.length > 1) { + text = parts.slice(0, 2).map(Util.getFirstCharacter).join(''); + } else { + text = Util.getFirstCharacter(name); + var second = Util.getFirstCharacter(name.replace(text, '')); + if (second && second !== '?') { + text += second; + } + } + return text; + }; + var animal_avatars = {}; MT.displayAvatar = function (common, $container, href, name, _cb, uid) { var cb = Util.once(Util.mkAsync(_cb || function () {})); @@ -105,20 +120,16 @@ define([ var animal = false; name = (name || "").trim() || Messages.anonymous; - var parts = name.split(/\s+/); var text; - if (name === Messages.anonymous) { + if (name === Messages.anonymous && uid) { if (animal_avatar) { text = animal_avatar; } else { text = animal_avatar = getPseudorandomAnimal(uid); } animal = true; - } else if (parts.length > 1) { - text = parts.slice(0, 2).map(Util.getFirstCharacter).join(''); } else { - text = Util.getFirstCharacter(name); - text += Util.getFirstCharacter(name.replace(text, '')); + text = getPrettyInitials(name); } var $avatar = $('', {'class': 'cp-avatar-default' + (animal? ' animal': '')}).text(text); diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 791857049..7493d9996 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -362,7 +362,7 @@ MessengerUI, Messages, Pages) { }); } console.error("AVATAR", $span, data.uid); - Common.displayAvatar($span, data.avatar, name, function () { // XXX pass a little more info so we can display better (pseudo-random) defaults + Common.displayAvatar($span, data.avatar, name, function () { $span.append($rightCol); }, data.uid); $span.data('uid', data.uid);