introduced `reactions` to `chatMessageItems` in the chat selectors. For this introduction,To handle and merge reactions into `chatMessageItems`, I created a map to hold all reactions messages, with the key being the `targetMessageID` and the values being another Map, and this map has the different types of reactions ('👍', '❤️', '😆') as the key, and some information about who used which reaction for that target message.
To populate this reaction map, I first filtered out all nonreaction messages
Then the first check is to see if the `targetMessageID` of the reaction message already exists in `targetMessageReactionsMap` . If it doesn't, then we then create a new `reactsMap` and a new `usersSet` (which holds the users who have reacted to the message), add the creator of the reaction message into the `usersSet` and package that along with `viewerCreated` to create `messageReactionInfo`. We then set the reaction string ('👍') as the key to `reactsMap` and set the value as the newly created `messageReactionInfo`. We lastly set the `targetMessageID` as a key of `targetMessageReactionsMap` and `reactsMap` as the value to the key.
The next check is to see if the target message has the reaction already. If it doesn't we do the same steps above minus the last step of setting a new key into `targetMessageReactionsMap`, since it already exists.
If the reaction message passes all of those check it then lastly checks if the reaction message `action` is `add_reaction` or `remove_reaction`. If it is `add_reaction`, then we add the creator of the reaction message to the users set (described above) and it also checks if the creator is a viewer and switches `viewerReacted` accordingly.
If the reaction message action is `remove_reaction` then we remove the creator of the reaction message from the users set, and checks if the creator is a viewer and switches `viewerReacted` accordingly.
Once we have all the reaction messages into `targetMessageReactionsMap`, we then want to merge it into `ChatMessageInfoItem` and `RobotextChatMessageInfoItem`. To make this merge happen we check to see if the message ID for a nonreaction message is a `targetMessageID` for a reaction message using `targetMessageReactionsMap`. I created a map with the `targetMessageID` as the key and an arrayIf it isn't we return an empty Map of reaction message infos as the values.ns, I then pass the array of reaction message infos as `reactions` into `chatMessageItems`.but if it is, Also please note this diff is only for adding likeswe return the fetched map of reactions using the message id key.
We also want to make sure that each reaction in the map of reactions has at least one user reacting to it. I will be working on extending this to unliking/multiple reactions in subsequent diffsIf it doesn't we delete that reaction from the map of reactions.
---
Depends on D5782
Linear Task: [[ https://linear.app/comm/issue/ENG-2252/modify-createchatmessageitems-method-to-handle-reactions | ENG-2252 ]]