getConversation static method
Future<Conversation?>
getConversation(
- String conversationWith,
- String conversationType, {
- required dynamic onSuccess(
- Conversation conversation
- required dynamic onError(
- CometChatException excep
In order to fetch a specific conversation
conversationWith : UID/GUID of the user/group whose conversation you want to fetch.
conversationType : user or group.
Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.
Android Reference: ConversationsRequest.getUserConversation() or ConversationsRequest.getGroupConversation()
The method could throw PlatformException with error codes specifying the cause
Implementation
static Future<Conversation?> getConversation(
String conversationWith, String conversationType,
{required Function(Conversation conversation)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call appropriate repository method based on conversation type
final conversation = conversationType == 'user'
? await sdk.conversations.getUserConversation(conversationWith)
: await sdk.conversations.getGroupConversation(conversationWith);
// Call success callback
if (onSuccess != null) onSuccess(conversation);
return conversation;
} 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);
}
return null;
}