[lib] Pull useCommunityRootMembersToRole out of useThreadSearchIndex
Summary: We want to use this logic in useThreadsWithPermission as well so it makes sense to pull it out as a hook instead of copy/pasting code. Especially since the code for creating nested dictionary isn't the easiest to read.
Test Plan:
Will add log statements to useThreadSearchIndex to make sure communityRootMemebersToRole gets computed as before.
Will also set breakpoints to check structure of communityRootMembersToRole to make sure it's as expected.
BEFORE (checking constructed communityRootMembersToRole within useSearchIndex with breakpoint):
AFTER (checking return value of useCommunityRootMembersToRole):
Note that I wasn't able to get breakpoints to hit in AFTER case for some reason, but I console.logged and made sure that the structure of object was the same.
Reviewers: ashoat, ginsu, tomek, varun
Reviewed By: tomek
Differential Revision: https://phab.comm.dev/D12145