Skip to content

Chat reactions: react to a DM or group message with an emoji - #302

Closed
svaka2000 wants to merge 10 commits into
Open-Coding-Society:masterfrom
svaka2000:feat/message-reactions
Closed

svaka2000 wants to merge 10 commits into
Open-Coding-Society:masterfrom
svaka2000:feat/message-reactions

Conversation

@svaka2000

@svaka2000 svaka2000 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

People can react to a message in a DM or a group chat with one of six emoji: like, love, haha, wow, sad and celebrate. This is the backend half. The frontend half is a separate PR on the pages repo, and it needs this one deployed first.

  • I added a message_reaction table in a new mvc/reactions package, with one row for each person, message and reaction.
  • MessageReactionTableInitializer creates the table at startup if it's missing. If that fails, Spring still starts, like it does for the other tables, and the log shows an error saying reactions won't work.
  • Reaction is an enum of the six keys. Spring stores the key, not the emoji, and an unknown key answers 400.
  • DMs: GET /api/dm/conversations/{id}/reactions gives the reactions on every message in the conversation. PUT or DELETE /api/dm/conversations/{id}/messages/{messageId}/reactions/{reaction} adds or takes back yours and answers with that message's reactions. Only the conversation's two people can use them (403 for anyone else, 404 if the conversation doesn't exist). The message has to be in that conversation (404), and a deleted message can't get one (409).
  • Groups: the same three routes under /api/groups/chat/{groupId}. They follow the group chat's own rule: any signed-in account, with no membership check, same as reading and posting on master.
  • Group messages live in an S3 file, so I only check that the message id looks like a lowercase UUID. I don't read the file to confirm the message exists.
  • Every change broadcasts the message's new reactions over the chat's WebSocket topic, the one the chat already uses, so everyone in the chat sees it live. Group chats send a reactionsServer frame, and DMs send one with type: "reactions". A DM's frame goes out once the change is saved, with the reactions read again then, so two people reacting at the same moment both show up.
  • A reaction sends no phone notification, doesn't make anything unread, and doesn't touch the group's S3 chat file. Deleting a message takes its reactions with it.

Other notes:

How to try it: run ./mvnw test -Dtest='*Reaction*Test,PermissionsPolicyTest'. To try it by hand, start Spring and send the new requests in api/groups.http: PUT a reaction, then GET the group's reactions.

PermissionsPolicyTest checks permissions.json against every request the
controllers answer. The reaction routes for direct messages and group
chats go with the other /api/dm and /api/groups/chat requests: any
signed-in admin, student, teacher or user, as the filter chain answers
today.
…se group ids

A remove read the row and then deleted it, so a second remove at the same
moment could fail. Removing one reaction and clearing a deleted message's
reactions are now single delete statements. The names of the people who
reacted come from one query for id, uid and name, instead of whole Person
rows that also loaded each person's eager links. A group message id has to
be a lowercase UUID, like the ids Spring saves, so an uppercase copy can't
match some lookups and miss others on MySQL.
…in then

The frame was sent inside the change's transaction with the reactions read
there, so two people reacting at the same moment could each send a list
missing the other's reaction, and everyone in the chat would keep one of
them. It is now sent once the transaction commits, with the reactions read
in a transaction of their own. A group's reactions were already read after
their change had committed.
Spring still starts, as it does when the calls or calendar tables can't
be made, but the log now says reactions won't work instead of a warning
that is easy to miss.
The group chat fixes (Open-Coding-Society#296 to Open-Coding-Society#299) each add a line after the chat
regression tests, so the reactions line goes above it and the two
change different places.
svaka2000 added a commit to svaka2000/Spring-JJ that referenced this pull request Nov 26, 2026
…or's types

GroupChatSendTest built GroupChatApiController, GroupChatRealtimeService and
GroupChatReadService by naming their constructors. Open PRs add constructor
dependencies to the controller and the realtime service (Open-Coding-Society#302 a
MessageReactionService, Open-Coding-Society#303 a MentorAccess), so once one of them and this
test were both on master, the tests would stop compiling, with no merge
conflict to show it.

TestBeans builds a class through its biggest constructor: each parameter gets
the first object the test passes that fits it, and a Mockito mock otherwise.
The test then keeps compiling and running whatever dependencies those classes
gain.
@svaka2000

Copy link
Copy Markdown
Contributor Author

Combined into #314 with the same commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant