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

Function fetchMessageNotifyType

lib/push/utils.js:108–168  ·  view source on GitHub ↗
(
  inputData: FetchMessageNotifyTypeInputData,
)

Source from the content-addressed store, hash-verified

106 +messageData: MessageData,
107};
108async function fetchMessageNotifyType(
109 inputData: FetchMessageNotifyTypeInputData,
110): Promise<Map<string, Array<FetchMessageNotifyTypeReturnInstance>>> {
111 const {
112 newMessageInfos,
113 messageDatas,
114 threadsToMessageIndices,
115 userNotMemberOfSubthreads,
116 fetchMessageInfoByID,
117 userID,
118 } = inputData;
119
120 const promises: Array<Promise<?FetchMessageNotifyTypeReturnInstance>> = [];
121 for (const [, messageIndices] of threadsToMessageIndices) {
122 promises.push(
123 ...messageIndices.map(async messageIndex => {
124 const messageInfo = newMessageInfos[messageIndex];
125 const { type } = messageInfo;
126 const { getMessageNotifyType } = messageSpecs[type];
127
128 let messageNotifyType: MessageNotifyType =
129 messageNotifyTypes.SET_UNREAD;
130 if (messageInfo.creatorID === userID) {
131 // We don't need to notify the message author about their message
132 messageNotifyType = messageNotifyTypes.NONE;
133 } else if (getMessageNotifyType) {
134 messageNotifyType = await getMessageNotifyType(messageInfo, {
135 notifTargetUserID: userID,
136 userNotMemberOfSubthreads,
137 fetchMessageInfoByID,
138 });
139 }
140
141 const messageData = messageDatas[messageIndex];
142 return {
143 messageNotifyType,
144 messageInfo,
145 messageData,
146 };
147 }),
148 );
149 }
150 const results = await Promise.all(promises);
151
152 const returnMap = new Map<
153 string,
154 Array<FetchMessageNotifyTypeReturnInstance>,
155 >();
156 for (const result of results) {
157 if (!result) {
158 continue;
159 }
160 let resultsForThread = returnMap.get(result.messageInfo.threadID);
161 if (!resultsForThread) {
162 resultsForThread = [];
163 returnMap.set(result.messageInfo.threadID, resultsForThread);
164 }
165 resultsForThread.push(result);

Callers 2

postMessageSendFunction · 0.90
getPushUserInfoFunction · 0.90

Calls 3

pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected