getConversation method

Future<EMConversation?> getConversation(
  1. String conversationId, {
  2. EMConversationType type = EMConversationType.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: EMConversationType.

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

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

没有找到会返回空值。

Param conversationId 会话 ID。

Param type 会话类型,详见 EMConversationType

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

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

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

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

Implementation

Future<EMConversation?> getConversation(
  String conversationId, {
  EMConversationType type = EMConversationType.Chat,
  bool createIfNeed = true,
}) async {
  Map req = {
    "convId": conversationId,
    "type": conversationTypeToInt(type),
    "createIfNeed": createIfNeed
  };
  Map result =
      await ChatChannel.invokeMethod(ChatMethodKeys.getConversation, req);
  try {
    EMError.hasErrorFromResult(result);
    EMConversation? ret;
    if (result[ChatMethodKeys.getConversation] != null) {
      ret = EMConversation.fromJson(result[ChatMethodKeys.getConversation]);
    }
    return ret;
  } on EMError catch (e) {
    throw e;
  }
}