-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add emoji reactions to task messages #5291
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Emoji Reactions Feature Implementation | ||
|
|
||
| ## Overview | ||
| Successfully implemented an emoji reaction feature that allows users to add emoji reactions to any task messages they can see in the Roo Code VS Code extension. | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### 1. Message Type Extension | ||
| **File:** `packages/types/src/message.ts` | ||
| - Extended `ClineMessage` schema to include `reactions?: Record<string, number>` | ||
| - Reactions map emoji strings to reaction counts | ||
|
|
||
| ### 2. EmojiReactions Component | ||
| **File:** `webview-ui/src/components/chat/EmojiReactions.tsx` | ||
| - Standalone React component for displaying and managing reactions | ||
| - Features: | ||
| - 16 common emoji picker (👍, 👎, ❤️, 😂, 😮, 😢, 😡, 🎉, 🚀, 👀, 💯, 🔥, ⭐, ✅, ❌, 🤔) | ||
| - Click-to-toggle reactions (click existing to remove, click new to add) | ||
| - Displays reaction counts as clickable buttons | ||
| - Outside-click to close picker functionality | ||
|
|
||
| ### 3. Message Protocol Extension | ||
| **File:** `src/shared/WebviewMessage.ts` | ||
| - Added `"addReaction"` and `"removeReaction"` message types | ||
| - Added `messageTs?: number` and `emoji?: string` properties for reaction data | ||
|
|
||
| ### 4. Backend Message Handling | ||
| **File:** `src/core/webview/webviewMessageHandler.ts` | ||
| - Added handlers for `addReaction` and `removeReaction` messages | ||
| - Delegates to Task class methods for processing | ||
|
|
||
| ### 5. Task Class Methods | ||
| **File:** `src/core/task/Task.ts` | ||
| - `addReaction(messageTs: number, emoji: string)`: Increments reaction count | ||
| - `removeReaction(messageTs: number, emoji: string)`: Decrements reaction count | ||
| - Automatic persistence and webview state synchronization | ||
|
|
||
| ### 6. UI Integration | ||
| **File:** `webview-ui/src/components/chat/ChatRow.tsx` | ||
| - Integrated EmojiReactions component into key message types: | ||
| - Text messages (`message.say === "text"`) | ||
| - Completion results (`message.say === "completion_result"` and `message.ask === "completion_result"`) | ||
| - User feedback messages (`message.say === "user_feedback"`) | ||
| - Reactions only display for complete (non-partial) messages | ||
| - Handlers for adding/removing reactions via VSCode message passing | ||
|
|
||
| ## Key Features | ||
|
|
||
| ### User Experience | ||
| - **Intuitive interaction**: Click existing reactions to remove, click new emojis to add | ||
| - **Visual feedback**: Reaction counts displayed on buttons | ||
| - **Easy access**: Emoji picker appears on hover with smiling face icon | ||
| - **Persistent**: Reactions are saved with messages and persist across sessions | ||
|
|
||
| ### Technical Features | ||
| - **Real-time updates**: Changes sync immediately across the interface | ||
| - **Proper persistence**: Reactions saved to task message storage | ||
| - **Type safety**: Full TypeScript support with proper type definitions | ||
| - **Performance**: Minimal re-renders with proper React optimization | ||
|
|
||
| ### Message Types Supporting Reactions | ||
| 1. **Text responses** from the AI assistant | ||
| 2. **Task completion results** (both ask and say types) | ||
| 3. **User feedback messages** that users send | ||
|
|
||
| ## Usage | ||
| Users can now: | ||
| 1. See a small 😊 button appear on eligible messages | ||
| 2. Click it to open an emoji picker with 16 common reaction emojis | ||
| 3. Click any emoji to add a reaction | ||
| 4. Click existing reaction buttons to remove their reaction | ||
| 5. See reaction counts update in real-time | ||
|
|
||
| The feature seamlessly integrates into the existing chat interface without disrupting the current user experience while adding a new dimension of interaction and feedback capability. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | ||||||
| import React, { useState, useRef, useEffect } from "react" | ||||||
| import { Button } from "@src/components/ui" | ||||||
| import { cn } from "@src/lib/utils" | ||||||
|
|
||||||
| interface EmojiReactionsProps { | ||||||
| messageTs: number | ||||||
| reactions?: Record<string, number> | ||||||
| onAddReaction: (emoji: string) => void | ||||||
| onRemoveReaction: (emoji: string) => void | ||||||
| className?: string | ||||||
| } | ||||||
|
|
||||||
| const COMMON_EMOJIS = [ | ||||||
| "👍", "👎", "❤️", "😂", "😮", "😢", "😡", "🎉", | ||||||
| "🚀", "👀", "💯", "🔥", "⭐", "✅", "❌", "🤔" | ||||||
| ] | ||||||
|
|
||||||
| export const EmojiReactions = ({ | ||||||
| messageTs, | ||||||
| reactions = {}, | ||||||
| onAddReaction, | ||||||
| onRemoveReaction, | ||||||
| className, | ||||||
| }) => { | ||||||
| const [showPicker, setShowPicker] = useState(false) | ||||||
| const pickerRef = useRef<HTMLDivElement>(null) | ||||||
|
|
||||||
| // Close picker when clicking outside | ||||||
| useEffect(() => { | ||||||
| const handleClickOutside = (event: MouseEvent) => { | ||||||
| if (pickerRef.current && !pickerRef.current.contains(event.target as Node)) { | ||||||
| setShowPicker(false) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (showPicker) { | ||||||
| document.addEventListener("mousedown", handleClickOutside) | ||||||
| } | ||||||
|
|
||||||
| return () => { | ||||||
| document.removeEventListener("mousedown", handleClickOutside) | ||||||
| } | ||||||
| }, [showPicker]) | ||||||
|
|
||||||
| const handleEmojiClick = (emoji: string) => { | ||||||
| if (reactions && reactions[emoji] && reactions[emoji] > 0) { | ||||||
| onRemoveReaction(emoji) | ||||||
| } else { | ||||||
| onAddReaction(emoji) | ||||||
| } | ||||||
| setShowPicker(false) | ||||||
| } | ||||||
|
|
||||||
| const hasReactions = Object.keys(reactions).some(emoji => reactions[emoji] > 0) | ||||||
|
|
||||||
| return ( | ||||||
| <div className={cn("relative flex items-center gap-1 mt-2", className)}> | ||||||
| {/* Existing reactions */} | ||||||
| {reactions && Object.entries(reactions) | ||||||
| .filter(([_, count]) => (count as number) > 0) | ||||||
| .map(([emoji, count]) => ( | ||||||
| <Button | ||||||
| key={emoji} | ||||||
| variant="outline" | ||||||
| size="sm" | ||||||
| className="h-6 px-2 py-0 text-xs bg-vscode-button-secondaryBackground hover:bg-vscode-button-secondaryHoverBackground border-vscode-button-border" | ||||||
| onClick={() => handleEmojiClick(emoji)} | ||||||
| > | ||||||
| <span className="mr-1">{emoji}</span> | ||||||
| <span>{count as number}</span> | ||||||
| </Button> | ||||||
| ))} | ||||||
|
|
||||||
| {/* Add reaction button */} | ||||||
| <div className="relative" ref={pickerRef}> | ||||||
| <Button | ||||||
| variant="ghost" | ||||||
| size="sm" | ||||||
| className="h-6 w-6 p-0 text-xs hover:bg-vscode-button-secondaryHoverBackground" | ||||||
| onClick={() => setShowPicker(!showPicker)} | ||||||
| title="Add reaction" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider localizing the 'Add reaction' button title instead of hardcoding it. Use a translation function (e.g., t('emojiReactions.add')) to support multiple languages.
Suggested change
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX. |
||||||
| > | ||||||
| <span className="text-sm">😊</span> | ||||||
| </Button> | ||||||
|
|
||||||
| {/* Emoji picker */} | ||||||
| {showPicker && ( | ||||||
| <div className="absolute top-full left-0 mt-1 p-2 bg-vscode-dropdown-background border border-vscode-dropdown-border rounded shadow-lg z-50 grid grid-cols-8 gap-1 max-w-64"> | ||||||
| {COMMON_EMOJIS.map((emoji) => ( | ||||||
| <Button | ||||||
| key={emoji} | ||||||
| variant="ghost" | ||||||
| size="sm" | ||||||
| className="h-8 w-8 p-0 hover:bg-vscode-list-hoverBackground" | ||||||
| onClick={() => handleEmojiClick(emoji)} | ||||||
| > | ||||||
| {emoji} | ||||||
| </Button> | ||||||
| ))} | ||||||
| </div> | ||||||
| )} | ||||||
| </div> | ||||||
| </div> | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| export default EmojiReactions | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The computed variable 'hasReactions' is declared but not used. Remove it to simplify the code.