loadMessagesFromTime method
~english Loads messages from the local database according the following parameters: start timestamp, end timestamp, count.
Note Pay attention to the memory usage when the maxCount is large.
Param startTime
The starting Unix timestamp for search.
Param endTime
The ending Unix timestamp for search.
Param count
The maximum number of message to retrieve.
Returns The list of searched messages.
Throws A description of the exception. See ChatError. ~end
~chinese 加载一个时间段内的消息,不超过最大数量。
注意:当 maxCount 非常大时,需要考虑内存消耗。
Param startTime
搜索的起始时间。
Param endTime
搜索的结束时间。
Param count
搜索结果的最大条数。
Return 消息列表。
Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。 ~end
Implementation
Future<List<ChatMessage>> loadMessagesFromTime({
required int startTime,
required int endTime,
int count = 20,
}) async {
Map req = this._toJson();
req["startTime"] = startTime;
req['endTime'] = endTime;
req['count'] = count;
Map<String, dynamic> result = await _emConversationChannel.invokeMethod(
ChatMethodKeys.loadMsgWithTime, req);
try {
ChatError.hasErrorFromResult(result);
List<ChatMessage> msgList = [];
result[ChatMethodKeys.loadMsgWithTime]?.forEach((element) {
msgList.add(ChatMessage.fromJson(element));
});
return msgList;
} on ChatError catch (e) {
throw e;
}
}