deleteConversation static method
dynamic
deleteConversation(
- String conversationWith,
- String conversationType, {
- required dynamic onSuccess(
- String message
- required dynamic onError(
- CometChatException excep
Method deletes the conversation only for the logged-in user.
conversationWith The ID of the message above which all messages for a particular conversation are to be marked as read.
conversationType The type of conversation you want to delete . It can be either user or group
Migration Note: Migrated from platform channels to native Dart implementation. Uses ConversationRepository for deleting conversations. Behavior and signature remain identical for backward compatibility.
Android Reference: ConversationsRequest.deleteConversation()
method could throw PlatformException with error codes specifying the cause
Implementation
static deleteConversation(String conversationWith, String conversationType,
{required Function(String message)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call appropriate repository method based on conversation type
if (conversationType == 'user') {
await sdk.conversations.deleteUserConversation(conversationWith);
} else {
await sdk.conversations.deleteGroupConversation(conversationWith);
}
final result = 'Conversation deleted successfully';
if (onSuccess != null) onSuccess(result);
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
} catch (e) {
_errorCallbackHandler(null, null, e, onError);
}
}