loadMessagesWithMsgType method
- required MessageType type,
- int timestamp = -1,
- int count = 20,
- String? sender,
- ChatSearchDirection direction = ChatSearchDirection.Up,
根据消息类型、搜索消息的时间点、搜索结果的最大条数、搜索来源和搜索方向从 SDK 本地数据库中搜索指定数量的消息。
Note 当 maxCount 非常大时,需要考虑内存消耗。
Param type
消息类型,文本、图片、语音等等。
Param timestamp
搜索时间。
Param count
搜索结果的最大条数。
Param sender
搜索来自某人的消息,也可用于搜索群组或聊天室里的消息。
Param direction
消息加载的方向。
Return 消息列表。
Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。
Implementation
Future<List<ChatMessage>> loadMessagesWithMsgType({
required MessageType type,
int timestamp = -1,
int count = 20,
String? sender,
ChatSearchDirection direction = ChatSearchDirection.Up,
}) async {
Map req = this._toJson();
req['msgType'] = type.index;
req['timestamp'] = timestamp;
req['count'] = count;
req['direction'] = direction.index;
req.putIfNotNull("sender", sender);
Map result = await _emConversationChannel.invokeMethod(
ChatMethodKeys.loadMsgWithMsgType, req);
try {
ChatError.hasErrorFromResult(result);
List<ChatMessage> list = [];
result[ChatMethodKeys.loadMsgWithMsgType]?.forEach((element) {
list.add(ChatMessage.fromJson(element));
});
return list;
} on ChatError catch (e) {
throw e;
}
}