handle single-character usernames when deriving initials from usernames

and use emoji avatar in user admin button
pull/1/head
ansuz 3 years ago
parent 46e545a976
commit 385cd4e947

@ -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;

@ -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 = $('<span>', {'class': 'cp-avatar-default' + (animal? ' animal': '')}).text(text);

@ -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);

Loading…
Cancel
Save