HomePhabricator
Diffusion Comm f5dd6833e19a

[lib] introduce useUserProfileThreadInfo hook

Description

[lib] introduce useUserProfileThreadInfo hook

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

Reviewers: atul, inka

Reviewed By: atul

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D9247

Details

Provenance
ginsuAuthored on Sep 27 2023, 11:00 PM
Reviewer
atul
Differential Revision
D9247: [lib] introduce useUserProfileThreadInfo hook
Parents
rCOMM879f563675f2: [web][keyserver] codeVersion -> 31
Branches
Unknown
Tags
Unknown