Page MenuHomePhabricator

D7053.diff
No OneTemporary

D7053.diff

diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/avatar-utils.js
@@ -0,0 +1,52 @@
+// @flow
+
+import stringHash from 'string-hash';
+
+import { selectedThreadColors } from './thread-utils.js';
+import type { ClientEmojiAvatar, ClientAvatar } from '../types/avatar-types.js';
+
+const defaultAnonymousUserEmojiAvatar: ClientEmojiAvatar = {
+ color: selectedThreadColors[4],
+ emoji: '👤',
+ type: 'emoji',
+};
+
+const defaultEmojiAvatars: $ReadOnlyArray<ClientEmojiAvatar> = [
+ { color: selectedThreadColors[7], emoji: '😀', type: 'emoji' },
+ { color: selectedThreadColors[0], emoji: '😆', type: 'emoji' },
+ { color: selectedThreadColors[1], emoji: '🤩', type: 'emoji' },
+ { color: selectedThreadColors[7], emoji: '🏈', type: 'emoji' },
+ { color: selectedThreadColors[2], emoji: '👻', type: 'emoji' },
+ { color: selectedThreadColors[3], emoji: '🧑‍🚀', type: 'emoji' },
+ { color: selectedThreadColors[4], emoji: '🎩', type: 'emoji' },
+ { color: selectedThreadColors[5], emoji: '🍦', type: 'emoji' },
+ { color: selectedThreadColors[6], emoji: '🚀', type: 'emoji' },
+ { color: selectedThreadColors[8], emoji: '🥰', type: 'emoji' },
+ { color: selectedThreadColors[3], emoji: '🐬', type: 'emoji' },
+ { color: selectedThreadColors[4], emoji: '🍀', type: 'emoji' },
+ { color: selectedThreadColors[9], emoji: '🍕', type: 'emoji' },
+ { color: selectedThreadColors[0], emoji: '🙄', type: 'emoji' },
+ { color: selectedThreadColors[1], emoji: '🥳', type: 'emoji' },
+ { color: selectedThreadColors[7], emoji: '🥸', type: 'emoji' },
+ { color: selectedThreadColors[2], emoji: '🦋', type: 'emoji' },
+ { color: selectedThreadColors[9], emoji: '🏆', type: 'emoji' },
+ { color: selectedThreadColors[5], emoji: '🎲', type: 'emoji' },
+ { color: selectedThreadColors[8], emoji: '🏀', type: 'emoji' },
+];
+
+function getAvatarForUser(
+ user: ?{ +avatar?: ?ClientAvatar, +username?: ?string, ... },
+): ClientAvatar {
+ if (user?.avatar) {
+ return user.avatar;
+ }
+
+ if (!user?.username) {
+ return defaultAnonymousUserEmojiAvatar;
+ }
+
+ const avatarIndex = stringHash(user.username) % defaultEmojiAvatars.length;
+ return defaultEmojiAvatars[avatarIndex];
+}
+
+export { getAvatarForUser };

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 29, 4:00 AM (21 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595659
Default Alt Text
D7053.diff (2 KB)

Event Timeline