diff --git a/keyserver/src/creators/message-creator.js b/keyserver/src/creators/message-creator.js --- a/keyserver/src/creators/message-creator.js +++ b/keyserver/src/creators/message-creator.js @@ -26,7 +26,10 @@ appendSQLArray, mergeOrConditions, } from '../database/database'; -import { fetchMessageInfoForLocalID } from '../fetchers/message-fetchers'; +import { + fetchMessageInfoForLocalID, + fetchMessageInfoByID, +} from '../fetchers/message-fetchers'; import { fetchOtherSessionsForViewer } from '../fetchers/session-fetchers'; import { fetchServerThreadInfos } from '../fetchers/thread-fetchers'; import { sendPushNotifs } from '../push/send'; @@ -365,6 +368,8 @@ const pushInfo = {}; const messageInfosPerUser = {}; const latestMessagesPerUser: LatestMessagesPerUser = new Map(); + let fetchTargetMessageInfoPromise: Promise; + for (const pair of perUserInfo) { const [userID, preUserPushInfo] = pair; const { subthreadsCanNotify } = preUserPushInfo; @@ -378,6 +383,12 @@ invariant(messageIndices, `indices should exist for thread ${threadID}`); for (const messageIndex of messageIndices) { const messageInfo = messageInfos[messageIndex]; + if (messageInfo.type === messageTypes.REACTION) { + fetchTargetMessageInfoPromise = fetchMessageInfoByID( + viewer, + messageInfo.targetMessageID, + ); + } if ( (messageInfo.type !== messageTypes.CREATE_SUB_THREAD || subthreadsCanNotify.has(messageInfo.childThreadID)) && @@ -388,12 +399,6 @@ } } } - if ( - userPushInfo.devices.length > 0 && - userPushInfo.messageInfos.length > 0 - ) { - pushInfo[userID] = userPushInfo; - } const userMessageInfos = []; for (const threadID of preUserPushInfo.threadIDs) { const messageIndices = threadsToMessageIndices.get(threadID); @@ -416,6 +421,23 @@ messageInfos, ), ); + + if ( + userPushInfo.devices.length === 0 || + userPushInfo.messageInfos.length === 0 + ) { + continue; + } + + if (fetchTargetMessageInfoPromise) { + const targetMessageInfo = await fetchTargetMessageInfoPromise; + const targetMessageCreatorID = targetMessageInfo?.creatorID; + if (targetMessageCreatorID && targetMessageCreatorID !== userID) { + continue; + } + } + + pushInfo[userID] = userPushInfo; } const latestMessages = flattenLatestMessagesPerUser(latestMessagesPerUser);