searchLocalMessages static method

Future<V2TimValueCallback<V2TimMessageSearchResult>> searchLocalMessages({
  1. required V2TimMessageSearchParam searchParam,
})

Implementation

static Future<V2TimValueCallback<V2TimMessageSearchResult>> searchLocalMessages({
  required V2TimMessageSearchParam searchParam,
}) async {
  String? cid = searchParam.conversationID == null ? null : Tools.nativecidtoCcid(searchParam.conversationID!);
  int? ctype = searchParam.conversationID == null ? null : Tools.convertid2convType(searchParam.conversationID!);
  String param = json.encode({
    "msg_search_param_keyword_array": searchParam.keywordList,
    "msg_search_param_message_type_array": searchParam.messageTypeList,
    "msg_search_param_conv_id": cid,
    "msg_search_param_conv_type": ctype,
    "msg_search_param_keyword_list_match_type": searchParam.type,
    "msg_search_param_search_time_position": searchParam.searchTimePosition,
    "msg_search_param_search_time_period": searchParam.searchTimePeriod,
    "msg_search_param_page_index": searchParam.pageIndex,
    "msg_search_param_page_size": searchParam.pageSize,
    "msg_search_param_send_identifier_array": searchParam.userIDList,
  });
  String userData = Tools.generateUserData();
  Pointer<Uint8> user_data = Tools.string2PointerInt8(userData);
  Pointer<Uint8> json_search_message_param = Tools.string2PointerInt8(param);
  int res = desktopSDK.D_TIMMsgSearchLocalMessages(json_search_message_param, user_data);
  if (res != TIMResult.TIM_SUCC) {
    return V2TimValueCallback<V2TimMessageSearchResult>.fromJson({
      "code": res,
      "desc": "",
    });
  } else {
    Map<String, dynamic> data = await getAsyncData(apiKey: userData);
    Map<String, dynamic> nativeJson = Map<String, dynamic>.from(json.decode(data["json_param"].isEmpty ? json.encode({}) : data["json_param"]));
    List<Map<String, dynamic>> nativeList = List.from(nativeJson["msg_search_result_item_array"] ?? []);
    List<Map<String, dynamic>> dartList = List<Map<String, dynamic>>.empty(growable: true);
    for (var element in nativeList) {
      List<Map<String, dynamic>> messageList = List.from(element["msg_search_result_item_message_array"] ?? []);
      List<Map<String, dynamic>> dartMessageList = List<Map<String, dynamic>>.empty(growable: true);
      for (var msg in messageList) {
        dartMessageList.add((await Tools.convertMessage2Dart(msg)).toJson());
      }

      dartList.add({
        "conversationID": Tools.ccidtoNativecid(element["msg_search_result_item_conv_id"], element["msg_search_result_item_conv_type"]),
        "messageCount": element["msg_search_result_item_total_message_count"],
        "messageList": dartMessageList
      });
    }
    Map<String, dynamic> dartJson = Map<String, dynamic>.from({
      "totalCount": nativeJson["msg_search_result_total_count"],
      "messageSearchResultItems": dartList,
    });

    return V2TimValueCallback<V2TimMessageSearchResult>.fromJson({"code": data["code"], "desc": data["desc"], "data": dartJson});
  }
}