Delete all messages from a user in a group chat
Delete every message sent by a specified user in a group chat with the WASM SDK.
await openimsdk.deleteUserAllMessagesInConv({
conversationID,
userID: targetUserID,
});This API is available only for group chats and deletes every message sent by the specified user in the target group conversation. It is a high-impact group moderation action and should not appear in an ordinary single-message menu. OpenIMServer validates the operator's permission. Promise completion does not mean that the event has already arrived.
Listen for SdkEvent.OnDeleteUserAllMsgsInConv to remove messages from moderated members. The event data payload is { conversationID, userID }. When the event arrives, remove all messages sent by that user in the specified conversation. To recalibrate the chat view, reload conversation history:
import { SdkEvent } from '@openim/wasm-client-sdk';
const handleUserMessagesDeleted = ({ data }) => {
removeMessagesBySender(data.conversationID, data.userID);
};
openimsdk.on(
SdkEvent.OnDeleteUserAllMsgsInConv,
handleUserMessagesDeleted,
);
function removeUserMessagesDeletedListener() {
openimsdk.off(
SdkEvent.OnDeleteUserAllMsgsInConv,
handleUserMessagesDeleted,
);
}Call removeUserMessagesDeletedListener() when the component unmounts, the user logs out, or the active account changes. Promise completion, event arrival, and a new history query are three independent stages.
Was this page helpful?