searchMsgFromDB method

Future<List<ChatMessage>> searchMsgFromDB(
  1. String keywords,
  2. {int timestamp = -1,
  3. int maxCount = 20,
  4. String from = '',
  5. ChatSearchDirection direction = ChatSearchDirection.Up}
)

Retrieves messages from the database according to the parameters.

Note Pay attention to the memory usage when the maxCount is large. Currently, a maximum of 400 historical messages can be retrieved each time.

Param keywords The keywords in message.

Param timestamp The Unix timestamp for search, in milliseconds.

Param maxCount The maximum number of messages to retrieve each time.

Param from A user ID or group ID at which the retrieval is targeted. Usually, it is the conversation ID.

Return The list of messages.

Throws A description of the exception. See ChatError.

Implementation

Future<List<ChatMessage>> searchMsgFromDB(
  String keywords, {
  int timestamp = -1,
  int maxCount = 20,
  String from = '',
  ChatSearchDirection direction = ChatSearchDirection.Up,
}) async {
  Map req = Map();
  req['keywords'] = keywords;
  req['timestamp'] = timestamp;
  req['maxCount'] = maxCount;
  req['from'] = from;
  req['direction'] = direction == ChatSearchDirection.Up ? "up" : "down";

  Map result =
      await ChatChannel.invokeMethod(ChatMethodKeys.searchChatMsgFromDB, req);
  try {
    ChatError.hasErrorFromResult(result);
    List<ChatMessage> list = [];
    result[ChatMethodKeys.searchChatMsgFromDB]?.forEach((element) {
      list.add(ChatMessage.fromJson(element));
    });
    return list;
  } on ChatError catch (e) {
    throw e;
  }
}