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

Function useNewThickThread

lib/hooks/thread-hooks.js:101–169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99}
100
101function useNewThickThread(): (
102 input: NewThickThreadRequest,
103) => Promise<string> {
104 const processAndSendDMOperation = useProcessAndSendDMOperation();
105 const viewerID = useSelector(
106 state => state.currentUserInfo && state.currentUserInfo.id,
107 );
108
109 const threadInfos = useSelector(state => state.threadStore.threadInfos);
110
111 return React.useCallback(
112 async (input: NewThickThreadRequest) => {
113 invariant(viewerID, 'viewerID must be defined');
114 const threadID = input.id ?? uuid.v4();
115
116 let op;
117 let recipientIDs;
118 if (input.type === threadTypes.THICK_SIDEBAR) {
119 const { parentThreadID, sourceMessageID, initialMemberIDs } = input;
120 invariant(
121 parentThreadID,
122 'parentThreadID has to be defined for thick sidebar',
123 );
124 const sidebarOP: DMCreateSidebarOperation = {
125 creatorID: viewerID,
126 memberIDs: initialMemberIDs ?? [],
127 newCreateSidebarMessageID: uuid.v4(),
128 newSidebarSourceMessageID: uuid.v4(),
129 parentThreadID: parentThreadID,
130 roleID: uuid.v4(),
131 sourceMessageID: sourceMessageID,
132 threadID,
133 time: Date.now(),
134 type: 'create_sidebar',
135 };
136 op = sidebarOP;
137 recipientIDs = threadInfos[parentThreadID].members.map(
138 member => member.id,
139 );
140 } else {
141 const { type, initialMemberIDs } = input;
142
143 const threadOP: DMCreateThreadOperation = {
144 creatorID: viewerID,
145 memberIDs: initialMemberIDs ?? [],
146 newMessageID: uuid.v4(),
147 roleID: uuid.v4(),
148 threadID,
149 threadType: type,
150 time: Date.now(),
151 type: 'create_thread',
152 };
153 op = threadOP;
154 recipientIDs = [...(input.initialMemberIDs ?? []), viewerID];
155 }
156 const opSpecification: OutboundDMOperationSpecification = {
157 type: dmOperationSpecificationTypes.OUTBOUND,
158 op,

Calls 2

useSelectorFunction · 0.90

Tested by

no test coverage detected