( inputData: FetchMessageNotifyTypeInputData, )
| 106 | +messageData: MessageData, |
| 107 | }; |
| 108 | async 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); |
no test coverage detected