Browse SDKs · WASM
Platform
SDKsWASM

Mark a conversation as read

Mark the messages in a conversation as read with the WASM SDK.

Copy

Call markConversationMessageAsRead() after the user opens a conversation and finishes reading the currently visible messages. Do not mark them as read merely because a notification was previewed or the message arrived in the background.

await openimsdk.markConversationMessageAsRead(conversationID);

A successful Promise means that the mark-read request has completed, not that a conversation event has arrived. SdkEvent.OnConversationChanged subsequently provides a new ConversationItem[]; use conversationID to update the matching conversation's unread count. See Get the conversation list for the complete listener. Query the conversation again when the latest result must be confirmed immediately.

In one-to-one chats, when the current user marks messages as read, the counterparty receives SdkEvent.OnRecvC2CReadReceipt. Listen for this event to update message read state in the UI. The event payload data is MessageReadReceipt[]; match the one-to-one conversation by the counterpart's userID, then update the read status for each message identified in msgIDList by clientMsgID.

import { SdkEvent } from '@openim/wasm-client-sdk';

const handleC2CReadReceipt = ({ data }) => {
  mergeC2CReadReceipts(data);
};

openimsdk.on(SdkEvent.OnRecvC2CReadReceipt, handleC2CReadReceipt);

function removeC2CReadReceiptListener() {
  openimsdk.off(SdkEvent.OnRecvC2CReadReceipt, handleC2CReadReceipt);
}

Call removeC2CReadReceiptListener() when the component unmounts, the user signs out, or the account changes. In a group chat, this API clears only the current account's conversation unread count. To report member-level group read state, see Send group message read receipts.