loadMessagesWithKeyword method Null safety
- String keywords,
- {String? sender,
- int timestamp = -1,
- int count = 20,
- EMSearchDirection direction = EMSearchDirection.Up}
Loads messages from the local database by the following parameters: keywords, timestamp, max count, sender, search direction.
Note Pay attention to the memory usage when the maxCount is large.
Param keywords
The keywords in message.
Param sender
The message sender. The param can also be used to search in group chat.
Param timestamp
The timestamp for search.
Param count
The maximum number of messages to search.
Param direction
The direction in which the message is loaded: EMSearchDirection.
EMSearchDirection.Up
: Gets the messages loaded before the timestamp of the specified message ID.
EMSearchDirection.Down
: Gets the messages loaded after the timestamp of the specified message ID.
Returns The list of retrieved messages.
Throws A description of the exception. See {@link EMError}.
Implementation
Future<List<EMMessage>> loadMessagesWithKeyword(
String keywords, {
String? sender,
int timestamp = -1,
int count = 20,
EMSearchDirection direction = EMSearchDirection.Up,
}) async {
Map req = this._toJson();
req["keywords"] = keywords;
req['count'] = count;
req['timestamp'] = timestamp;
req['direction'] = direction == EMSearchDirection.Up ? "up" : "down";
req.setValueWithOutNull("sender", sender);
Map<String, dynamic> result = await _emConversationChannel.invokeMethod(
ChatMethodKeys.loadMsgWithKeywords, req);
try {
EMError.hasErrorFromResult(result);
List<EMMessage> msgList = [];
result[ChatMethodKeys.loadMsgWithKeywords]?.forEach((element) {
msgList.add(EMMessage.fromJson(element));
});
return msgList;
} on EMError catch (e) {
throw e;
}
}