Browse SDKs · WASM
SDKsWASM

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.

Copy
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.

The complete listener for SdkEvent.OnDeleteUserAllMsgsInConv is provided on this page. Its event data is { conversationID, userID }. When the event arrives, use these fields to remove that sender's messages from the current list. If you need to confirm the final result, reload conversation history and use the latest data.

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.