getConversation method

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

~english 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. ~end

~chinese 根据指定会话 ID 和会话类型获取会话对象。

没有找到会返回空值。

Param conversationId 会话 ID。

Param type 会话类型,详见 ChatConversationType

Param createIfNeed 没找到相应会话时是否自动创建。

  • (Default)true 表示没有找到相应会话时会自动创建会话;
  • false 表示没有找到相应会话时不创建会话。

Return 根据指定 ID 以及会话类型找到的会话对象,如果没有找到会返回空值。

Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。 ~end

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;
  }
}