Overview
Zomato's customer support relies on efficient and intuitive communication tools. We are developing a new internal chat interface for our support agents to interact with customers. This problem focuses on building a performant and interactive chat message list, which is crucial for agent productivity and a seamless support experience.
What you need to do / Task
Your task is to build a React component that displays a list of chat messages with the following features:
- Message Rendering: Display individual chat messages, showing sender name, message text, and associated reactions.
- Message Grouping: Implement logic to group consecutive messages from the same sender within a short timeframe (e.g., 5 minutes) into a single visual block. Only the first message in a group should display the sender's avatar/name.
- Interactive Reactions: Each message can have multiple reactions (emojis) from different users. Display these reactions below the message. Allow the current user (
currentUserId) to toggle (add/remove) their own reactions on any message.
- Message Input & Sending: Provide a text input field and a 'Send' button to allow the
currentUserId to send new messages. These messages should appear immediately in the chat list.
UI/UX expectations
- Layout: The chat interface should be a fixed-height container with messages scrolling from bottom to top. A message input area should be present at the bottom.
- Message Grouping Visuals: When messages are grouped, subsequent messages from the same sender should appear without repeating the sender's avatar/name, and ideally, be slightly indented or styled to indicate they are part of a group.
- Reactions Display: Reactions should be displayed as small buttons or badges below each message. If multiple users react with the same emoji, display a count. The current user's active reactions should be visually distinct (e.g., highlighted).
- Scroll Behavior: The chat window should automatically scroll to the bottom on initial load and whenever the
currentUserId sends a new message. If the user has manually scrolled up, new messages (from any sender) should not force a scroll to the bottom until the user scrolls near the bottom again.
Acceptance criteria
- Messages are rendered correctly, displaying sender name, text, and timestamp (optional for display, but for grouping logic).
- Consecutive messages from the same sender within a 5-minute window are visually grouped as specified.
- New messages sent via the input field are added to the chat list and displayed correctly.
- Reactions are displayed below each message, showing counts for each emoji.
- Clicking a reaction emoji toggles its presence for the
currentUserId on that specific message.
- The chat container scrolls to the bottom on initial load.
- The chat container scrolls to the bottom when the
currentUserId sends a message.
- The chat container does not auto-scroll to the bottom if the user has manually scrolled up, unless the
currentUserId sends a message. (This implies a check for user's scroll position).
- Basic styling makes the chat interface usable and readable, distinguishing between sent/received messages.