getConversation method Null safety

Future<EMConversation?> getConversation(
  1. String conversationId,
  2. [EMConversationType type = EMConversationType.Chat,
  3. bool createIfNeed = true]
)

Gets the conversation by conversation ID and conversation type.

Param conversationId The conversation ID.

Param type The conversation type: {@link 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 {@link EMError}.

Implementation

Future<EMConversation?> getConversation(
  String conversationId, [
  EMConversationType type = EMConversationType.Chat,
  bool createIfNeed = true,
]) async {
  Map req = {
    "con_id": conversationId,
    "type": conversationTypeToInt(type),
    "createIfNeed": createIfNeed
  };
  Map result =
      await _channel.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;
  }
}