latestMessage method

Future<EMMessage?> latestMessage()

~english Gets the last message from the conversation.

The operation does not change the unread message count.

The SDK gets the latest message from the local memory first. If no message is found, the SDK loads the message from the local database and then puts it in the memory.

Return The message instance. ~end

~chinese 获取会话的最新一条消息。

不影响未读数统计。

会先从缓存中获取,如果没有则从本地数据库获取后存入缓存。

Return 消息体实例。 ~end

Implementation

Future<EMMessage?> latestMessage() async {
  Map req = this._toJson();
  Map result = await _emConversationChannel.invokeMethod(
      ChatMethodKeys.getLatestMessage, req);
  try {
    EMError.hasErrorFromResult(result);
    if (result.containsKey(ChatMethodKeys.getLatestMessage)) {
      return EMMessage.fromJson(result[ChatMethodKeys.getLatestMessage]);
    } else {
      return null;
    }
  } on EMError catch (e) {
    throw e;
  }
}