Browse SDKs · Android
Platform
SDKsAndroid

Delete all messages from a user in a group chat

Delete every message sent by a specified user in a group chat with the Android SDK.

Copy

Group owners and administrators can clear every historical message sent by a designated member in a group chat. This is commonly used to remove spam, moderate rule violations, or ban abusive accounts across a group conversation.

Code example

String conversationID = "g_group_123";
String targetUserID = "user_spammer";

OpenIMClient.getInstance().messageManager.deleteUserAllMessagesInConv(
    conversationID,
    targetUserID,
    new OnBase<String>() {
        @Override
        public void onSuccess(String data) {
            // Deletion request processed successfully
        }

        @Override
        public void onError(int code, String error) {
            // Failed to delete user messages (e.g. insufficient permissions)
        }
    }
);

Parameters

ParameterTypeRequiredDescription
conversationIDStringYesGlobally unique ID of the target group conversation. Group conversations only.
targetUserIDStringYesUser ID of the member whose messages should be cleared.
baseOnBase<String>YesCallback handler for the asynchronous request.

Return value

Upon success, data in onSuccess returns a confirmation message.

State changes after the call

  1. Callback confirmation: The onSuccess callback indicates that the server has executed the purge across the specified group conversation.
  2. Asynchronous event delivery: All online group members receive an event via OnAdvanceMsgListener.onDeleteUserAllMsgsInConv:
   @Override
   public void onDeleteUserAllMsgsInConv(DeleteUserAllMsgsListenerMsg event) {
       // Filter by event.getConversationID() and event.getUserID()
       // Remove all messages sent by this user from the local timeline
   }

Group members filter messages by conversationID and sendID == targetUserID, removing all matching bubbles from their active UI timeline.

  1. Re-query calibration: If UI state diverges after reconnecting, reload the message history using Load older messages.

For complete listener registration and lifecycle management, see Receive messages.