HomePhabricator
Diffusion Comm 25680afe29ab

[lib] Introduce `useThreadsWithPermission` to filter `ThreadInfo`s

Description

[lib] Introduce useThreadsWithPermission to filter ThreadInfos

Summary:
There are places where we want to check which ThreadInfos in a collection have a given ThreadPermission. In these situations, we call threadHasPermission in some sort of for-loop or in the body of a .filter. See onScreenEntryEditableThreadInfos below as an example:

ef4a70.png (476×1 px, 98 KB)

Now that we're moving from threadHasPermission to useThreadHasPermission, we have the issue where calling useThreadHasPermission within a for-loop or .filter for each ThreadInfo would violate the rules of hooks. Instead, we introduce a new hook that takes in a $ReadOnlyArray<ThreadInfo> and filters out ThreadInfos that don't have a given ThreadPermission.

The original implementation of useThreadsWithPermission was 90% the same as useThreadHasPermission, so it made sense to consume useThreadsWithPermission within useThreadHasPermission to reduce duplication. Also considered pulling logic out into helper function, but thought this approach was cleaner.


Depends on D11916

Test Plan:
flow + close reading + some log statements as sanity checks for now

Put log statements in both useThreadHasPermission and useThreadsWithPermission to ensure that return values were as expected. Specifically that return values of useThreadHasPermission remained the same.

Reviewers: ashoat, ginsu, tomek, varun, will

Reviewed By: ashoat

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

Details

Provenance
atulAuthored on May 14 2024, 1:47 PM
Reviewer
ashoat
Differential Revision
D11924: [lib] Introduce `useThreadsWithPermission` to filter `ThreadInfo`s
Parents
rCOMMd90270ac68f8: [native] Consume `useThreadInChatList` in `native/ThreadSettings`
Branches
Unknown
Tags
Unknown