Browse SDKs · iOS
Platform
SDKsiOS

Delete all messages from a user in a group chat

Delete every message sent by a specified user in a group chat with OpenIM iOS SDK.

Copy

In group administration or moderation scenarios, group owners and administrators can invoke deleteUserAllMessagesInConversation:userID:onSuccess:onFailure: on OIMManager to delete all historical messages sent by a specified member in a group conversation:

Parameters

ParameterTypeRequiredDescription
conversationIDNSString *YesTarget group conversation identifier.
userIDNSString *YesUser ID of the target group member whose messages will be removed.
onSuccessOIMSuccessCallbackYesSuccess callback confirming the deletion request was accepted.
onFailureOIMFailureCallbackYesFailure callback returning error code code and descriptive message msg (e.g. insufficient permissions).

Code example

[[OIMManager manager] deleteUserAllMessagesInConversation:conversationID
                                                   userID:targetUserID
                                                onSuccess:^(NSString * _Nullable data) {
    // Member messages deletion initiated successfully
}
                                                onFailure:^(NSInteger code, NSString * _Nullable msg) {
    // Handle deletion failure
}];

Return value

The onSuccess callback confirms that the deletion request was processed by the server.

Listen for user message cleanup events

When a member's messages are removed from a group conversation, the SDK notifies group members via onDeleteUserAllMsgsInConv:userID: in OIMAdvancedMsgListener:

- (void)onDeleteUserAllMsgsInConv:(NSString *)conversationID userID:(NSString *)userID {
    if (conversationID.length == 0 || userID.length == 0) {
        return;
    }
    // Remove all cached messages sent by this user in the specified conversation
    [self removeMessagesByConversationID:conversationID senderUserID:userID];
}

State changes after the call

  1. Composite state merge: The merge key is conversationID and sender userID. Because the event payload does not include individual clientMsgID values, filter out and remove all messages matching the sender in that conversation, or re-query conversation history to reconcile state.
  2. Permission validation: This is an administrative operation; the server validates whether the calling user has owner or administrator privileges in the group. For listener registration and lifecycle details, see Receive messages.