MCPcopy Create free account
hub / github.com/CommE2E/comm / useThreadInfoForPossiblyPendingThread

Function useThreadInfoForPossiblyPendingThread

web/utils/thread-utils.js:37–118  ·  view source on GitHub ↗
(
  activeChatThreadID: ?string,
  selectedProtocol: ?ProtocolName,
)

Source from the content-addressed store, hash-verified

35}
36
37function useThreadInfoForPossiblyPendingThread(
38 activeChatThreadID: ?string,
39 selectedProtocol: ?ProtocolName,
40): ?ThreadInfo {
41 const { isChatCreation, selectedUserInfos } = useInfosForPendingThread();
42
43 const loggedInUserInfo = useLoggedInUserInfo();
44 const currentUserSupportsDCs = useCurrentUserSupportsDCs();
45
46 const pendingThread = React.useMemo(() => {
47 if (!loggedInUserInfo) {
48 return null;
49 }
50 return createPendingThread({
51 viewerID: loggedInUserInfo.id,
52 threadType: dmThreadProtocol.pendingThreadType(1),
53 members: [loggedInUserInfo],
54 });
55 }, [loggedInUserInfo]);
56
57 const newThreadID = 'pending/new_thread';
58 const pendingNewThread = React.useMemo(() => {
59 if (!loggedInUserInfo) {
60 return null;
61 }
62 return {
63 ...createPendingThread({
64 viewerID: loggedInUserInfo.id,
65 threadType: dmThreadProtocol.pendingThreadType(1),
66 members: [loggedInUserInfo],
67 name: 'New thread',
68 }),
69 id: newThreadID,
70 };
71 }, [loggedInUserInfo]);
72
73 const existingThreadInfoFinderForCreatingThread =
74 useExistingThreadInfoFinder(pendingThread);
75
76 const baseThreadInfo = useSelector(state => {
77 if (activeChatThreadID) {
78 const activeThreadInfo = threadInfoSelector(state)[activeChatThreadID];
79 if (activeThreadInfo) {
80 return activeThreadInfo;
81 }
82 }
83 return state.navInfo.pendingThread;
84 });
85 const existingThreadInfoFinder = useExistingThreadInfoFinder(baseThreadInfo);
86
87 const threadInfo = React.useMemo(() => {
88 if (isChatCreation) {
89 if (selectedUserInfos.length === 0) {
90 return pendingNewThread;
91 }
92 const searchingProtocol = getSearchingProtocol(
93 selectedUserInfos,
94 currentUserSupportsDCs,

Calls 7

useLoggedInUserInfoFunction · 0.90
createPendingThreadFunction · 0.90
useSelectorFunction · 0.90
getSearchingProtocolFunction · 0.90
useInfosForPendingThreadFunction · 0.85

Tested by

no test coverage detected