searchMsgsByOptions method

Future<List<EMMessage>> searchMsgsByOptions(
  1. MessageSearchOptions options
)

通过类型从数据库获取消息。

Param options 搜索配置项, 详情查看 MessageSearchOptions.

Return 消息列表。

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

Implementation

Future<List<EMMessage>> searchMsgsByOptions(
    MessageSearchOptions options) async {
  Map req = this._toJson();
  req['ts'] = options.ts;
  req['count'] = options.count;
  req['direction'] = options.direction.index;
  req.putIfNotNull("from", options.from);
  req['types'] = options.types.map((e) => e.index).toList();
  Map result = await _emConversationChannel.invokeMethod(
      ChatMethodKeys.conversationSearchMsgsByOptions, req);
  try {
    EMError.hasErrorFromResult(result);
    List<EMMessage> messages = [];
    List list = result[ChatMethodKeys.conversationSearchMsgsByOptions];
    list.forEach((element) {
      messages.add(EMMessage.fromJson(element));
    });
    return messages;
  } on EMError catch (e) {
    throw e;
  }
}