Page MenuHomePhabricator

[lib] introduce getUserAvatarForThread function
ClosedPublic

Authored by ginsu on Mar 25 2023, 10:50 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Apr 7, 10:21 PM
Unknown Object (File)
Thu, Mar 28, 8:33 AM
Unknown Object (File)
Thu, Mar 28, 8:33 AM
Unknown Object (File)
Thu, Mar 28, 8:33 AM
Unknown Object (File)
Thu, Mar 28, 8:32 AM
Unknown Object (File)
Thu, Mar 28, 8:30 AM
Unknown Object (File)
Feb 21 2024, 1:35 PM
Unknown Object (File)
Feb 11 2024, 2:17 PM
Subscribers

Details

Summary

The getUserAvatarForThread function returns the user avatar for threads that are either PERSONAL or PRIVATE. We inject the user avatars in threadInfoFromRawThreadInfo so that it is already set, and when we later call useGetAvatarForThread (introduced in D7132) we will just return that

Depends on D7177

Test Plan

Please see the screenshots below to see that the correct user avatar is being rendered on to a PERSONAL and PRIVATE thread

For reference my friend's avatar:

Screenshot 2023-03-26 at 2.03.53 AM.png (1×1 px, 750 KB)

For reference my avatar:

Screenshot 2023-03-26 at 2.03.55 AM.png (1×1 px, 810 KB)

Personal Threads:

Screenshot 2023-03-26 at 2.05.59 AM.png (1×1 px, 929 KB)

Private Thread:

Screenshot 2023-03-26 at 2.05.44 AM.png (262×704 px, 59 KB)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ginsu edited the test plan for this revision. (Show Details)
ginsu added reviewers: ashoat, atul.
ginsu added inline comments.
lib/shared/avatar-utils.js
68 ↗(On Diff #24138)

This function was heavily inspired by how we used to get the uiName of a thread before we introduced all the logic for entities.

https://github.com/CommE2E/comm/blob/5cfc7a2966c7929872af3fa1ed901413532ba745/lib/shared/thread-utils.js#L695-L717

83 ↗(On Diff #24138)

I didn't want to return your own user avatar since that might cause confusion where the user thinks they are on their PRIVATE thread, so defaulted to this, but maybe we could also just do a random generated thread avatar too..

lib/shared/thread-utils.js
884 ↗(On Diff #24138)

We inject the user avatar here so that it is preset and when we later call useGetAvatarForThread (introduced in D7132) we will just return that

lib/types/thread-types.js
303 ↗(On Diff #24138)

We needed to include avatar in ClientDBThreadInfo to make flow happy

ashoat added inline comments.
lib/shared/avatar-utils.js
77 ↗(On Diff #24138)

If getUserAvatarForThread is only meant to be used for PRIVATE and PERSONAL, can you add an invariant here that threadInfo.type === threadTypes.PERSONAL? That way it will be more clear to the reader

83 ↗(On Diff #24138)

No this is good. I think this should only happen if somebody has a PERSONAL chat with you and then they delete their account. defaultAnonymousUserEmojiAvatar is a good default for that

This revision is now accepted and ready to land.Mar 26 2023, 5:53 AM
lib/shared/thread-utils.js
884 ↗(On Diff #24138)

This was where we got the circular dependency issue from D7177 when all the color logic was initially located in this file. Again this was because getUserAvatarForThread attempted to access selectedThreadColor before it got initialized.