Skip to main content

Delete Conversations

To remove one or multiple conversations from the conversation list, you can use the SDK's conversation deletion feature. The client's conversation list is generated based on local messages, and deleting a conversation refers to removing the local conversation.

Delete a Specific Conversation

Calling removeConversation achieves a soft deletion effect. This interface does not actually delete messages within the conversation but only removes the conversation item from the SDK's conversation list. After successfully deleting the conversation, the App can refresh the UI to no longer display the conversation item to users.

Interface Prototype

- (void)removeConversation:(RCConversationType)conversationType
targetId:(NSString *)targetId
completion:(nullable void(^)(BOOL ret))completion;

Parameter Description

ParameterTypeDescription
conversationTypeRCConversationTypeConversation type. For one-to-one chat, use ConversationType_PRIVATE.
targetIdNSStringThe targetId of the conversation.
completionBlockReturns the result of the deletion operation.

Example Code

[[RCCoreClient sharedCoreClient] removeConversation:ConversationType_PRIVATE targetId:@"targetId"
completion:^(BOOL ret) {

}];

If a new message arrives after the conversation is deleted, the conversation will reappear in the conversation list, and the App user can view both historical and new messages within the conversation.

The SDK does not provide an interface to simultaneously delete a specific conversation item and its historical messages. If you need to delete both, you can call the message deletion interface while deleting the specified conversation. For details, see Delete Messages.

Delete Conversations by Type

To clear all conversations of a specific type, such as all group chats, the SDK supports clearing all conversations of specified types along with their local historical messages. Multiple conversation types can be cleared at once.

Interface Prototype

- (void)clearConversations:(NSArray<NSNumber *> *)conversationTypeList
completion:(nullable void(^)(BOOL ret))completion;

Parameter Description

ParameterTypeDescription
conversationTypeListNSArrayAn array of conversation types. Convert RCConversationType to NSNumber to build the array.
completionBlockReturns the result of the deletion operation.

Example Code

[[RCCoreClient sharedCoreClient] clearConversations::@[@(ConversationType_PRIVATE),@(ConversationType_SYSTEM),@(ConversationType_GROUP)]
completion:^(BOOL ret) {

}];

This interface only clears messages stored in the local database on the current user's device. If the App has enabled the Cloud Storage for One-to-One and Group Messages service, the historical messages stored on the server for this user will not be affected. If the user retrieves historical messages from the server, they will receive messages that were deleted locally. If you need to simultaneously delete the server-side historical messages of the conversation, you can call the interface that supports deleting remote historical messages after deleting the conversation. For details, see Delete Messages.

Batch Delete Conversations

Starting from version 5.26.0, IMLib introduces the batch conversation deletion feature. The SDK supports deleting specified conversations and allows control over whether the remote deletion is performed via parameters.

Interface Prototype

- (void)batchDeleteConversations:(RCConversationBatchDeletionParams *)params
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode errorCode))errorBlock;

Parameter Description

ParameterTypeDescription
paramsRCConversationBatchDeletionParamsBatch conversation parameters. See RCConversationBatchDeletionParams definition.
successBlockBlockCalled when deletion succeeds.
errorBlockBlockCalled when deletion fails.

Example Code

// Test batch conversation deletion
RCConversationBatchDeletionParams *params = [[RCConversationBatchDeletionParams alloc] init];

RCConversationIdentifier *identifier1 = [[RCConversationIdentifier alloc] init];
identifier1.type = ConversationType_PRIVATE;
identifier1.targetId = @"user1";

RCConversationIdentifier *identifier2 = [[RCConversationIdentifier alloc] init];
identifier2.type = ConversationType_PRIVATE;
identifier2.targetId = @"user2";

params.identifiers = @[identifier1, identifier2];
params.deleteMessages = YES; // Whether to delete messages within the conversation
params.deleteRemotely = YES; // Whether to delete the conversation on the server

[[RCCoreClient sharedCoreClient] batchDeleteConversations:params success:^{
NSLog(@"batchDeleteConversations success");
} error:^(RCErrorCode errorCode) {
NSLog(@"batchDeleteConversations error: %@", @(errorCode));
}];

Delete All Conversations

The SDK does not have a built-in method to clear all conversations. If needed, you can achieve this through either of the following methods:

  • If the App involves ultra group business, you can use Delete Conversations by Type and pass all conversation types. This method clears local messages. Note: Starting from version 5.20.0, clearing ultra group type conversations is supported (this feature requires submitting a ticket to enable).
  • First, retrieve the conversation list and then loop through to delete specified conversations.