Page MenuHomePhabricator

[lib] introduce useUserProfileThreadInfo hook
ClosedPublic

Authored by ginsu on Sep 20 2023, 9:30 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 20, 7:46 AM
Unknown Object (File)
Tue, Nov 19, 5:41 PM
Unknown Object (File)
Tue, Nov 12, 12:28 PM
Unknown Object (File)
Fri, Nov 8, 7:18 AM
Unknown Object (File)
Fri, Nov 8, 7:18 AM
Unknown Object (File)
Sun, Nov 3, 1:47 PM
Unknown Object (File)
Sun, Nov 3, 5:22 AM
Unknown Object (File)
Fri, Nov 1, 12:48 PM
Subscribers

Details

Summary

The purpose of this hook is to take in a UserInfo and return a UserProfileThreadInfo. A UserProfileThreadInfo is an object that contains a PERSONAL and PRIVATE threadInfo and an optional pendingPersonalThreadUserInfo. Both of these are needed for the navigateToThread hook (for navigating to the thread between the viewer and the user in the profile) and the useRelationshipPrompt hook (for doing relationship actions like friending, unfriending, blocking etc. between the viewer and the user in the profile).

The hook first selects all the PERSONAL and PRIVATE threads from the thread store using the threadInfosSelectorForThreadType selector introduced in D9204 since these are the only relevant thread infos for user profiles. Then the hook checks if the userID passed through the userInfo is the same userID as the logged in user. If it is we just return the PRIVATE thread info.

If the userID is in usersWithPersonalThread (a set of userIDs that the logged in user has personal threads with) then we iterate through the personal thread infos until we find the case where the userID matches the other single user of that personal thread and return that threadInfo

Otherwise if no thread exists, we create a pending personal thread using the createPendingPersonalThread function which is introduced in D9235 and return that (this pending personal thread will include a threadInfo and a pendingPersonalThreadUserInfo).

Depends on D9204

Test Plan

Please see the demo videos below where I confirm that I was able to navigate to the correct thread and I could send friend requests (the introduction of these buttons will happen in subsequent diffs)

The logged in user is dan and dan is friends with ginsu, but not friends with cmoney

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

ginsu edited the test plan for this revision. (Show Details)
ginsu added reviewers: atul, inka.
ginsu requested review of this revision.Sep 20 2023, 9:47 AM

still need to write some comments + update test plan (will rerequest review when finished with that)

lib/shared/thread-utils.js
1795–1796 ↗(On Diff #31318)

First attempted to use the destructuring assignment syntax

const { id, username } = userInfo;

But since userInfo is optional I got the following flow errors:

Screenshot 2023-09-20 at 1.10.51 PM.png (638×1 px, 203 KB)

1801–1810 ↗(On Diff #31318)

These are the selectors introduced in D9204

1812 ↗(On Diff #31318)

This selector returns a set of user ids (as strings) of users that you have a personal thread with

https://github.com/CommE2E/comm/blob/master/lib/selectors/user-selectors.js#L185-L208

1820–1823 ↗(On Diff #31318)

We should always have a private thread info (it gets created whenever you first join Comm) but based off this comment in D9120, I wanted to be extra cautious here

1835–1837 ↗(On Diff #31318)

At this point we should always have a personalThreadInfo, but like the comment above I wanted to be extra cautious here

atul added inline comments.
lib/shared/thread-utils.js
1819–1828 ↗(On Diff #31318)

You could reduce indentation, but it gets formatted funny... up to you

1835–1841 ↗(On Diff #31318)

Can also reduce indentation

This revision is now accepted and ready to land.Sep 26 2023, 11:33 AM