HomePhabricator
Diffusion Comm e9605efbb4b7

[lib] introduced reactions field to chatMessageItems

Description

[lib] introduced reactions field to chatMessageItems

Summary:
introduced reactions to chatMessageItems in the chat selectors. 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. If it isn't we return an empty Map of reactions, but if it is, we 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. If it doesn't we delete that reaction from the map of reactions.


Depends on D5782
Linear Task: ENG-2252

Test Plan:
Will be doing more tests in subsequent diffs. Ran mobile/web app locally and nothing crashes. I also was able to get to the point where I could add and remove a reaction and it would render on my local stack (see demo video below)

Reviewers: atul, tomek, rohan

Reviewed By: atul, tomek, rohan

Subscribers: ashoat, tomek, atul

Differential Revision: https://phab.comm.dev/D5811

Details

Provenance
ginsuAuthored on Dec 5 2022, 2:51 PM
Reviewer
atul
Differential Revision
D5811: [lib] introduced reactions field to chatMessageItems
Parents
rCOMM7116755f56ed: [lib] introduce sendReactionMessage success case to message reducers
Branches
Unknown
Tags
Unknown