[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:
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