loadConversationMessagesWithKeyword method
- String? keyword,
- int timestamp = -1,
- String? sender,
- ChatSearchDirection direction = ChatSearchDirection.Up,
- MessageSearchScope scope = MessageSearchScope.All,
通过关键词从本地数据库中获取消息,返回包含会话 ID 与消息 ID 数组的 Map。 SDK 按时间顺序返回消息。
Param keyword 搜索关键词,nil 表示忽略该参数。
Param timestamp 搜索起始 Unix 时间戳,单位毫秒。
为负数时从最新消息向前获取。
Param sender 消息发送方,nil 表示忽略该参数。
Param direction 消息搜索方向,详见 ChatSearchDirection。
- Up:按时间戳逆序获取。
- Down:按时间戳顺序获取。
Param scope 消息搜索范围,详见 MessageSearchScope。
Return Map,key 为会话 ID,value 为消息 ID 列表。
Throws 异常描述,详见 ChatError。
Implementation
Future<Map<String, List<String>>> loadConversationMessagesWithKeyword({
String? keyword,
int timestamp = -1,
String? sender,
ChatSearchDirection direction = ChatSearchDirection.Up,
MessageSearchScope scope = MessageSearchScope.All,
}) async {
try {
Map req = {};
req.putIfNotNull("keyword", keyword);
req["timestamp"] = timestamp;
req.putIfNotNull("sender", sender);
req["direction"] = direction.index;
req["scope"] = scope.index;
Map result = await platform_interface.Client.instance.chatManager.callNativeMethod(
ChatMethodKeys.loadConversationMessagesWithKeyword, req);
ChatError.hasErrorFromResult(result);
Map<String, List<String>> resultMap = {};
Map? data = result[ChatMethodKeys.loadConversationMessagesWithKeyword];
if (data != null) {
data.forEach((key, value) {
resultMap[key] = List<String>.from(value);
});
}
return resultMap;
} catch (e) {
rethrow;
}
}