loadMessagesWithKeyword method

Future<List<EMMessage>> loadMessagesWithKeyword(
  1. String keywords, {
  2. String? sender,
  3. int timestamp = -1,
  4. int count = 20,
  5. EMMessageSearchDirection direction = EMMessageSearchDirection.Up,
})

Implementation

Future<List<EMMessage>> loadMessagesWithKeyword(
  String keywords, {
  String? sender,
  int timestamp = -1,
  int count = 20,
  EMMessageSearchDirection direction = EMMessageSearchDirection.Up,
}) async {
  Map req = this.toJson();
  req["keywords"] = keywords;
  req['count'] = count;
  if (sender != null) {
    req['sender'] = sender;
  }
  req['timestamp'] = timestamp;
  req['direction'] = direction == EMMessageSearchDirection.Up ? "up" : "down";

  Map<String, dynamic> result = await _emConversationChannel.invokeMethod(
      EMSDKMethod.loadMsgWithKeywords, req);

  EMError.hasErrorFromResult(result);

  List<EMMessage> msgList = [];
  result[EMSDKMethod.loadMsgWithKeywords]?.forEach((element) {
    msgList.add(EMMessage.fromJson(element));
  });
  return msgList;
}