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.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | NSString * | Yes | Target group conversation identifier. |
userID | NSString * | Yes | User ID of the target group member whose messages will be removed. |
onSuccess | OIMSuccessCallback | Yes | Success callback confirming the deletion request was accepted. |
onFailure | OIMFailureCallback | Yes | Failure 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
- Composite state merge: The merge key is
conversationIDand senderuserID. Because the event payload does not include individualclientMsgIDvalues, filter out and remove all messages matching the sender in that conversation, or re-query conversation history to reconcile state. - 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.
Was this page helpful?