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 a conversation is the specified conversation is not found:

  • true: Yes.
  • false: No.

Return The conversation object found according to the ID and type. 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 {
  Map req = {
    "convId": conversationId,
    "type": conversationTypeToInt(type),
    "createIfNeed": createIfNeed
  };
  Map result =
      await ChatChannel.invokeMethod(ChatMethodKeys.getConversation, req);
  try {
    ChatError.hasErrorFromResult(result);
    ChatConversation? ret;
    if (result[ChatMethodKeys.getConversation] != null) {
      ret = ChatConversation.fromJson(result[ChatMethodKeys.getConversation]);
    }
    return ret;
  } on ChatError catch (e) {
    throw e;
  }
}