getConversation method

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

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

没有找到会返回空值。

Param conversationId 会话 ID。

Param type 会话类型,详见 ChatConversationType

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

  • (默认)true 表示自动创建会话。
  • false 表示不创建会话。

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

Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 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;
  }
}