Mark a conversation as read
Mark the messages in a conversation as read with the WASM SDK.
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.
For a one-to-one chat, after the current user marks the conversation as read, the other client can receive message read receipts through SdkEvent.OnRecvC2CReadReceipt. This page provides the complete listener. data is MessageReadReceipt[]; first locate the one-to-one conversation by the other user, then update read state by each clientMsgID in the item's msgIDList.
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.
Was this page helpful?