Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3381057
D7053.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D7053.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D7053: [lib] introduce getAvatarForUser in avatar-utils
Attached
Detach File
Event Timeline
Log In to Comment