Skip to main content

Overview

Returns an async function that marks a conversation as read up to a specific message. The unread count for the conversation is cleared in Redux immediately (optimistic update). The server is then notified to advance the user’s lastReadAt timestamp.
Requires ChatProvider in the component tree.

Usage Example

import { useMarkConversationAsRead } from "@replyke/react-js";
import { useEffect } from "react";

function ConversationView({
  conversationId,
  messages,
}: {
  conversationId: string;
  messages: { id: string }[];
}) {
  const mark = useMarkConversationAsRead({ conversationId });

  useEffect(() => {
    const lastMessage = messages[messages.length - 1];
    if (lastMessage) {
      mark({ messageId: lastMessage.id });
    }
  }, [messages]);

  // ...
}

Props

conversationId
string
required
The ID of the conversation to mark as read.

Parameters

The hook returns a function. That function accepts:
messageId
string
required
The ID of the message to mark as read up to. The server sets lastReadAt to this message’s createdAt.

Returns

Promise<void>

Notes

  • The failure to mark as read on the server (e.g. network error) is non-critical. The local Redux count is already cleared and will re-sync on the next ChatProvider mount.
  • For integration guidance, see Chat: Real-time.