adjust animal avatar caching system and adjust size in the toolbar

pull/1/head
ansuz 3 years ago
parent b8c847bcce
commit c5e6ca646e

@ -200,6 +200,9 @@
.avatar_main(30px); .avatar_main(30px);
.cp-avatar-default, media-tag { .cp-avatar-default, media-tag {
margin-right: 5px; margin-right: 5px;
&.animal {
font-size: 20px;
}
} }
&.cp-userlist-clickable { &.cp-userlist-clickable {
cursor: pointer; cursor: pointer;

@ -80,7 +80,7 @@ define([
}; };
// https://emojipedia.org/nature/ // https://emojipedia.org/nature/
var ANIMALS = [ '🙈', '🦀', '🐞', '🦋', '🐬', '🐋', '🐢', '🦉', '🦆', '🐧', '🦡', '🦘', '🦨', '🦦', '🦥', '🐼', '🐻', '🦝', '🦄', '🐄', '🐷', '🐐', '🦙', '🦒', '🐘', '🦏', '🐁', '🐹', '🐰', '🦫', '🦔', '🐨']; var ANIMALS = '🙈 🦀 🐞 🦋 🐬 🐋 🐢 🦉 🦆 🐧 🦡 🦘 🦨 🦦 🦥 🐼 🐻 🦝 🦓 🐄 🐷 🐐 🦙 🦒 🐘 🦏 🐁 🐹 🐰 🦫 🦔 🐨 🐱 🐺 👺 👹 👽 👾 🤖'.split(/\s+/);
var getRandomAnimal = function () { var getRandomAnimal = function () {
return ANIMALS[Math.floor(Math.random() * ANIMALS.length)]; return ANIMALS[Math.floor(Math.random() * ANIMALS.length)];
@ -94,14 +94,13 @@ define([
return ANIMALS[seed % ANIMALS.length]; return ANIMALS[seed % ANIMALS.length];
}; };
var animal_avatars = {};
MT.displayAvatar = function (common, $container, href, name, _cb, uid) { MT.displayAvatar = function (common, $container, href, name, _cb, uid) {
var cb = Util.once(Util.mkAsync(_cb || function () {})); var cb = Util.once(Util.mkAsync(_cb || function () {}));
var displayDefault = function () { var displayDefault = function () {
if (avatars[uid]) { var animal_avatar;
var nodes = $.parseHTML(avatars[uid]); if (uid && animal_avatars[uid]) {
var $el = $(nodes[0]); animal_avatar = animal_avatars[uid]
$container.append($el);
return void cb($el);
} }
var animal = false; var animal = false;
@ -109,7 +108,11 @@ define([
var parts = name.split(/\s+/); var parts = name.split(/\s+/);
var text; var text;
if (name === Messages.anonymous) { if (name === Messages.anonymous) {
text = getPseudorandomAnimal(uid); if (animal_avatar) {
text = animal_avatar;
} else {
text = animal_avatar = getPseudorandomAnimal(uid);
}
animal = true; animal = true;
} else if (parts.length > 1) { } else if (parts.length > 1) {
text = parts.slice(0, 2).map(Util.getFirstCharacter).join(''); text = parts.slice(0, 2).map(Util.getFirstCharacter).join('');
@ -120,7 +123,9 @@ define([
var $avatar = $('<span>', {'class': 'cp-avatar-default' + (animal? ' animal': '')}).text(text); var $avatar = $('<span>', {'class': 'cp-avatar-default' + (animal? ' animal': '')}).text(text);
$container.append($avatar); $container.append($avatar);
avatars[uid] = $avatar[0].outerHTML; if (uid && animal) {
animal_avatars[uid] = animal_avatar;
}
if (cb) { cb(); } if (cb) { cb(); }
}; };
if (!window.Symbol) { return void displayDefault(); } // IE doesn't have Symbol if (!window.Symbol) { return void displayDefault(); } // IE doesn't have Symbol

Loading…
Cancel
Save