searchMsgFromDB method Null safety
- String keywords,
- {int timeStamp = -1,
- int maxCount = 20,
- String from = '',
- EMSearchDirection direction = EMSearchDirection.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 username 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 {@link EMError}.
Implementation
Future<List<EMMessage>> searchMsgFromDB(
String keywords, {
int timeStamp = -1,
int maxCount = 20,
String from = '',
EMSearchDirection direction = EMSearchDirection.Up,
}) async {
Map req = Map();
req['keywords'] = keywords;
req['timeStamp'] = timeStamp;
req['maxCount'] = maxCount;
req['from'] = from;
req['direction'] = direction == EMSearchDirection.Up ? "up" : "down";
Map result = await EMMethodChannel.ChatManager.invokeMethod(
ChatMethodKeys.searchChatMsgFromDB, req);
try {
EMError.hasErrorFromResult(result);
List<EMMessage> list = [];
result[ChatMethodKeys.searchChatMsgFromDB]?.forEach((element) {
list.add(EMMessage.fromJson(element));
});
return list;
} on EMError catch (e) {
throw e;
}
}