loadMessages method
- String startMsgId = '',
- int loadCount = 20,
- ChatSearchDirection direction = ChatSearchDirection.Up,
从本地数据库加载消息。
根据传入的参数从本地数据库加载 startMsgId 之前(存储顺序)指定数量的消息。
Param startMsgId
加载这个 ID 之前的 message,如果传入 "" 或者 null,将从最近的消息开始加载。
Param loadCount
加载的条数。
Param direction
消息的加载方向。
Return 消息列表。
Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。
Implementation
Future<List<ChatMessage>> loadMessages({
String startMsgId = '',
int loadCount = 20,
ChatSearchDirection direction = ChatSearchDirection.Up,
}) async {
Map req = this._toJson();
req["startId"] = startMsgId;
req['count'] = loadCount;
req['direction'] = direction.index;
Map<String, dynamic> result = await _emConversationChannel.invokeMethod(
ChatMethodKeys.loadMsgWithStartId, req);
try {
ChatError.hasErrorFromResult(result);
List<ChatMessage> msgList = [];
result[ChatMethodKeys.loadMsgWithStartId]?.forEach((element) {
msgList.add(ChatMessage.fromJson(element));
});
return msgList;
} on ChatError catch (e) {
throw e;
}
}