diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js --- a/lib/selectors/chat-selectors.js +++ b/lib/selectors/chat-selectors.js @@ -26,6 +26,7 @@ type MessageInfo, type MessageStore, type ComposableMessageInfo, + type ReactionMessageInfo, type RobotextMessageInfo, type LocalMessageInfo, messageTypes, @@ -272,6 +273,7 @@ endsCluster: boolean, +robotext: string, +threadCreatedFromMessage: ?ThreadInfo, + +reactions?: $ReadOnlyArray, }; export type ChatMessageInfoItem = | RobotextChatMessageInfoItem @@ -283,6 +285,7 @@ +startsCluster: boolean, endsCluster: boolean, +threadCreatedFromMessage: ?ThreadInfo, + +reactions?: $ReadOnlyArray, }; export type ChatMessageItem = { itemType: 'loader' } | ChatMessageInfoItem; const msInFiveMinutes = 5 * 60 * 1000; @@ -304,6 +307,21 @@ ? sortMessageInfoList([...threadMessageInfos, ...additionalMessages]) : threadMessageInfos; + const reactionsMap = new Map>(); + + for (let i = 0; i < messages.length; i++) { + const messageInfo = messages[i]; + if (messageInfo.type !== messageTypes.REACTION) { + continue; + } + + if (reactionsMap.has(messageInfo.targetMessageID)) { + reactionsMap.get(messageInfo.targetMessageID)?.push(messageInfo); + } else { + reactionsMap.set(messageInfo.targetMessageID, [messageInfo]); + } + } + const chatMessageItems = []; let lastMessageInfo = null; for (let i = messages.length - 1; i >= 0; i--) { @@ -358,6 +376,12 @@ ); const localMessageInfo = messageStore.local[messageKey(originalMessageInfo)]; + + let reactions; + if (originalMessageInfo.id) { + reactions = reactionsMap.get(originalMessageInfo.id); + } + chatMessageItems.push({ itemType: 'message', messageInfo: originalMessageInfo, @@ -366,6 +390,7 @@ startsCluster, endsCluster: false, threadCreatedFromMessage, + reactions, }); } else { invariant( @@ -386,6 +411,7 @@ endsCluster: false, threadCreatedFromMessage, robotext, + reactions: reactionsMap.get(originalMessageInfo.id), }); } lastMessageInfo = originalMessageInfo;