searchMsgsByOptions method

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

Loads messages with the specified keyword from the local database.

Param options search options, see MessageSearchOptions.

Returns The list of retrieved messages.

Throws A description of the exception. See ChatError.

Implementation

Future<List<ChatMessage>> searchMsgsByOptions(
    MessageSearchOptions options) async {
  try {
    Map req = {};
    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 platform_interface.Client.instance.chatManager
        .callNativeMethod(ChatMethodKeys.searchMsgsByOptions, req);
    ChatError.hasErrorFromResult(result);
    List<ChatMessage> messages = [];
    List list = result[ChatMethodKeys.searchMsgsByOptions];
    for (var element in list) {
      messages.add(ChatMessage.fromJson(element));
    }
    return messages;
  } catch (e) {
    rethrow;
  }
}