loadConversationMessagesWithKeyword function

Future<Map<String, List<String>>> loadConversationMessagesWithKeyword({
  1. String? keyword,
  2. int timestamp = -1,
  3. String? sender,
  4. ChatSearchDirection direction = ChatSearchDirection.Up,
  5. MessageSearchScope scope = MessageSearchScope.All,
})

Loads messages with the specified keyword from the local database, returning a map containing conversation IDs and message ID arrays.

Param keyword The search keyword, nil means ignore. Param timestamp The starting Unix timestamp in milliseconds. Negative means fetch from the latest message. Param sender The message sender, nil means ignore. Param direction Message search direction, see ChatSearchDirection. - Up: Reverse order by timestamp. - Down: Chronological order by timestamp. Param scope Message search scope, see MessageSearchScope.

Returns A map where key is conversation ID, value is message ID list.

Throws Exception description, see 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;
  }
}