getConversation method

Future<ChatConversation?> getConversation(
  1. String conversationId, {
  2. ChatConversationType type = ChatConversationType.Chat,
  3. bool createIfNeed = true,
})

Gets the conversation by conversation ID and conversation type.

Param conversationId The conversation ID.

Param type The conversation type: ChatConversationType.

Param createIfNeed Whether to create the conversation if the conversation is not found:

  • (Default) true: Yes.
  • false: No.

Return The conversation object found according to the conversation ID and type. The SDK returns null if the conversation is not found.

Throws A description of the exception. See ChatError.

Implementation

Future<ChatConversation?> getConversation(
  String conversationId, {
  ChatConversationType type = ChatConversationType.Chat,
  bool createIfNeed = true,
}) async {
  try {
    Map req = {
      "convId": conversationId,
      "type": type.index,
      "createIfNeed": createIfNeed
    };
    Map result = await platform_interface.Client.instance.chatManager
        .callNativeMethod(ChatMethodKeys.getConversation, req);
    ChatError.hasErrorFromResult(result);
    if (result.containsKey(ChatMethodKeys.getConversation)) {
      return ChatConversation.fromJson(result[ChatMethodKeys.getConversation]);
    } else {
      return null;
    }
  } catch (e) {
    rethrow;
  }
}