loadMessagesWithKeyword method
- String keywords, {
- String? sender,
- int timestamp = -1,
- int count = 20,
- MessageSearchScope searchScope = MessageSearchScope.All,
- ChatSearchDirection direction = ChatSearchDirection.Up,
Loads messages from the local database by the following parameters: keywords, timestamp, the number of messages to retrieve, message sender, search scope, and search direction.
Note Pay attention to the memory usage when you retrieve a great number of messages.
Param keywords The keywords in message.
Param sender The user ID of the message sender. If you do not set this parameter, the SDK ignores this parameter when retrieving messages.
Param timestamp The starting message timestamp for search.
Param count The number of messages to retrieve.
Param searchScope The message search scope. See MessageSearchScope.
Param direction The direction in which the message is loaded: ChatSearchDirection.
ChatSearchDirection.Up: Gets the messages loaded before the timestamp of the specified message ID.
ChatSearchDirection.Down: Gets the messages loaded after the timestamp of the specified message ID.
Returns The list of retrieved messages.
Throws A description of the exception. See ChatError.
Implementation
Future<List<ChatMessage>> loadMessagesWithKeyword(
String keywords, {
String? sender,
int timestamp = -1,
int count = 20,
MessageSearchScope searchScope = MessageSearchScope.All,
ChatSearchDirection direction = ChatSearchDirection.Up,
}) async {
try {
Map req = {};
req["keywords"] = keywords;
req['count'] = count;
req['timestamp'] = timestamp;
req['searchScope'] = MessageSearchScope.values.indexOf(searchScope);
req['direction'] = direction.index;
req.putIfNotNull("from", sender);
Map result = await platform_interface.Client.instance.chatManager
.callNativeMethod(ChatMethodKeys.searchChatMsgFromDB, req);
ChatError.hasErrorFromResult(result);
List<ChatMessage> list = [];
result[ChatMethodKeys.searchChatMsgFromDB]?.forEach((element) {
list.add(ChatMessage.fromJson(element));
});
return list;
} catch (e) {
rethrow;
}
}