[lib] Introduce useThreadHasPermission hook
Summary:
- Currently, getCurrentUser handles mutating currentUser.permissions if threadFrozenDueToBlock(...) is true.
- The current threadFrozenDueToBlock(...) logic depends on memberHasAdminPowers which depends on sketchy CHANGE_ROLE check.
- We want to update memberHasAdminPowers to instead determine whether member is admin based on whether they have ADMIN_ROLE in community thread.
- Determining whether a member has ADMIN_ROLE in community thread is straightforward from React context, but not practical from non-React context.
- As a result, we want to move threadFrozenDueToBlock from getCurrentUser to useThreadHasPermission where we can compute derived permissions "on demand" from React context.
- As part of that, we're going to update threadHasPermission callsites ON CLIENT (ThreadInfo only) to use useThreadHasPermission.
- Once we've refactored all callsites to be able to use useThreadHasPermission, we will update it to use an updated version of threadFrozenDueToBlock which looks at community thread to determine ADMIN_ROLE using specialRole vs. sketchy CHANGE_ROLE check.
This diff introduces a "hook version" of threadHasPermission that can be used throughout client components. It only handles ThreadInfo and handles filtering of disabled permissions using threadFrozenDueToBlock check.
The next diffs in the stack aim to update all client permission checks to use this hook so we can remove the permission mutation logic from getCurrentUser.
Depends on D11742
Test Plan:
Added log statements to tooltipActionUtils to ensure that result of useThreadHasPermission and threadHasPermission are identical.
Will also test block scenario to ensure that permissions are correctly filtered out.
Reviewers: ashoat, ginsu, tomek, varun, will
Reviewed By: tomek
Differential Revision: https://phab.comm.dev/D11746