-
-
Notifications
You must be signed in to change notification settings - Fork 313
made some changes in emoji reactions #4155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
""" WalkthroughThe changes update the chat message reactions feature in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DOM
participant JS
participant WebSocket
User->>DOM: Loads page (messages rendered with data-reactions)
JS->>DOM: On DOMContentLoaded, setup event listeners
User->>JS: Clicks reaction button or quick reaction
JS->>WebSocket: Sends add reaction request
WebSocket->>JS: Sends reaction update message
JS->>DOM: Updates data-reactions and calls updateReactions
JS->>DOM: Rebuilds reaction buttons, updates UI
Assessment against linked issues
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
website/templates/join_room.html (5)
28-28: Ensure safe JSON encoding for data attributes.Embedding reactions as a JSON string in
data-reactionsis a good approach for synchronizing state. However, ensure that theescapejsfilter is always used and that the data is never too large to fit comfortably in a data attribute. If reactions grow large, consider a more scalable approach (e.g., fetching on demand).
35-67: Server-rendered reactions logic is robust and user-friendly.The template logic for rendering both existing reactions and default quick reactions is clear and matches the new client-side approach. Good use of accessibility features (button, span, title). Consider adding
aria-labelattributes for better screen reader support.
406-467: updateReactions function is robust, but consider accessibility and performance.
- The function now robustly clears and rebuilds the reactions container, handling both existing and quick reactions.
- Good use of logging and error handling.
- Consider adding
aria-labelto dynamically created buttons for accessibility.- If the number of reactions grows, rebuilding the entire container on every update could be inefficient; consider diffing or partial updates if performance becomes an issue.
529-530: Debug logging for WebSocket messages is helpful for development.Consider gating these logs behind a debug flag or removing them in production for cleaner console output.
636-637: Console log on DOMContentLoaded is useful for debugging.As with other logs, consider removing or gating in production.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
website/templates/join_room.html(10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
🔇 Additional comments (6)
website/templates/join_room.html (6)
69-69: Emoji picker button change is clear and intuitive.Switching from a smiley to a "+" for the add reaction button is a sensible UI choice, making the action clearer to users.
475-476: Correct use of JSON.stringify for embedding reactions in new messages.This ensures consistency between server-rendered and client-side messages. Good practice.
522-523: Immediate initialization of reactions for new messages is correct.Calling
updateReactionsright after appending a new message ensures the UI is always in sync.
545-550: Synchronizing data-reactions attribute on reaction updates is correct.This ensures the DOM always reflects the latest state, which is important for consistency and debugging.
667-677: Event listeners for server-rendered reaction buttons are correctly set up.This ensures that all reaction buttons, even those rendered on page load, are interactive. No issues found.
705-721: CSS for reactions container improves layout and usability.The new styles ensure reactions are always visible and wrap as needed. Good use of flexbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (6)
website/templates/join_room.html (6)
408-424: Review debug logging and early exit checks inupdateReactions
You’ve addedconsole.logand twoconsole.warncalls to trace missing elements, then clear the container. For production, consider gating verbose logs behind a debug flag or removing them to avoid console clutter. The early returns are a good safety net.
451-462: DRY up common quick reaction button creation
The loop forcommonEmojisduplicates markup found elsewhere (e.g., inappendMessage). Extract a helper function or template to reduce duplication. Also, switch frominnerHTMLtotextContentwhen inserting the emoji to further mitigate XSS concerns.
465-468: Enhance error messaging in the catch block
The catch logs the raw error and shows a generic notification. Consider includingmessageIdor more context in the notification (e.g.,"Failed to update reactions for message ${messageId}") to aid debugging.
531-531: Remove or gate raw WebSocket message logging
console.log('Received websocket message:', data);is useful for debugging but may expose sensitive chat payloads in production. Wrap it in a debug check or remove once validated.
638-638: Remove initialization debug log
Theconsole.log('DOM loaded, initializing chat room...');is helpful during development but should be removed or wrapped under a verbose/debug flag in production.
680-687: Bind click handlers to “add reaction” buttons
Setting up the.add-reaction-btnevent listeners for pre-rendered messages duplicates logic inappendMessage. Extract this into a shared initializer to avoid drift if the handler signature changes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
website/templates/join_room.html(10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run Tests
- GitHub Check: docker-test
🔇 Additional comments (10)
website/templates/join_room.html (10)
27-28: Embed reaction metadata on each message element
You’ve addeddata-message-idanddata-reactionsattributes to the.message-itemdiv, embedding the JSON‐escaped reactions payload directly into the DOM. This aligns server‐rendered messages with the client‐side update logic.
35-36: Define a dedicated reactions container with min-height
The new<div class="reactions-container … min-h-[28px]">ensures consistent layout even when no reactions are present. This change stabilizes the UI across messages of varying reaction counts.
38-48: Render existing reactions server‐side
Looping overmessage.reactions.itemsto output buttons with counts puts initial state directly in the template, reducing the flash of empty state before JS hydrates. Ensure that theemojiandusers|lengthvalues are always safe (they are internal, so risk is low).
50-65: Provide default quick‐reaction buttons when no reactions exist
Good fallback logic. Note that the server‐rendered defaults are 👍, ❤️, 😊, whereas the client’scommonEmojisarray includes 👏 and 🔥 as well. Please verify that this divergence is intentional for UX consistency.
69-69: Switch “add reaction” icon from smiley to plus
Updating the emoji‐picker trigger to “+” simplifies the action affordance. This is a clear UX improvement.
477-478: Embed reactions dataset for dynamically appended messages
Mirroring the server rendering by settingmessageDiv.dataset.reactions = JSON.stringify(data.reactions || {});ensures that newly received messages have the same data structure for hydration. Well done.
525-526: Initialize reactions UI immediately after appending a message
CallingupdateReactions(data.message_id, data.reactions || {});right after insertion ensures the UI is up-to-date without waiting for a separate WS update. Clean and effective.
547-554: Fully handlereaction_updateevents
You correctly update the element’sdata-reactionsattribute and then callupdateReactions. This keeps both the DOM and JS state synchronized. Ensure incomingdata.reactionsis always a valid object to avoid JSON‐parsing errors.
669-677: Bind click handlers to existing reaction buttons
Attaching listeners to.reaction-btnelements at DOMContentLoaded ensures server‐rendered buttons work without additional calls toupdateReactions. Good use ofaddEventListener.
719-723: Append CSS to support flexible wrapping of reactions
Your injected style ensures.reactions-containerflex‐wraps and honors a minimum height, preventing layout shifts. This is a solid fix for responsive behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
website/templates/join_room.html (2)
441-447: AvoidinnerHTMLto prevent XSS.Building
reactionButton.innerHTMLwith${emoji}and${users.length}can introduce XSS risks if these values are ever user-controlled. Instead, create child<span>elements and assign.textContenttoemojiand the count to ensure safe insertion.
456-460: Sanitize quick reaction button labels.Similar to existing reactions, using
innerHTMLfor<span>${emoji}</span>could pose injection risks. Construct the<span>viadocument.createElement('span')and set.textContent = emoji. This change eliminates any potential for HTML injection.
🧹 Nitpick comments (6)
website/templates/join_room.html (6)
50-65: Fallback to default quick reactions.Providing default emojis when there are no reactions improves discoverability. However, the list here (👍, ❤️, 😊) differs from the JS-side
commonEmojis(['👍','❤️','😊','👏','🔥']). Consider centralizing the default emoji list in a shared context variable or constant to avoid discrepancies.
69-69: Improve accessibility for “add reaction” button.Changing the span from “😀” to “+” clarifies intent. To further improve accessibility, add an
aria-label="Add reaction"or visually hidden text so screen readers announce the button’s purpose.
408-415: Review debug logging in production.The initial
console.logandconsole.warncalls help during development but may clutter the console in production. Consider gating these logs behind a debug flag or using a logging library that can adjust verbosity levels.
638-639: Remove or guard initial debug log.
console.log('DOM loaded, initializing chat room...')is useful for debuggers. In production, wrap such logs under a debug condition or remove them to avoid unnecessary console noise.
669-677: Deduplicate event listener setup.Event listeners for
.reaction-btnand.add-reaction-btnare registered both here and inappendMessage. Consider extracting this into a helper (e.g.,initReactionButtons(container)) and calling it in both places to adhere to DRY principles.
719-723: Move inline style injection to a CSS file.Injecting styles via JavaScript can complicate maintenance and make them harder to override. It would be cleaner to place these
.reactions-containerstyles in your Tailwind config or a dedicated CSS file, leveraging existing build tooling.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
website/templates/join_room.html(9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Run Tests
- GitHub Check: docker-test
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
website/templates/join_room.html (4)
35-47: Server-render existing reaction buttons.This block directly renders existing reactions with counts, reducing the flash-of-unstyled-content before JS kicks in. The logic correctly skips empty user lists. Ensure CSS (
min-h-[28px]) and layout handle multiple reaction buttons gracefully.
477-478: Embed reactions for new messages.Embedding
data-reactionson dynamically added messages ensures thatupdateReactionshas the necessary initial state. Confirm thatdata.reactionsfrom the WebSocket payload is always a well-formed object to prevent runtime errors.
524-526: Initialize reactions after appending messages.Calling
updateReactionsimmediately after adding the new message populates both existing and quick-reaction buttons without additional logic elsewhere. This is concise and aligns with the server-rendered flow.
547-553: Synchronize dataset on reaction updates.Updating
messageElement.dataset.reactionsbefore callingupdateReactionskeeps the DOM attribute in sync with the latest state. This is helpful if any other logic relies on the attribute. Ensure JSON is stringified consistently.
fixes #3681
Summary by CodeRabbit
New Features
Improvements
Style