searchLocalMessages method

Future searchLocalMessages(
  1. V2TimMessageSearchParam searchParam
)

Implementation

Future<dynamic> searchLocalMessages(V2TimMessageSearchParam searchParam) async {
  try {
    final res = await wrappedPromiseToFuture(
      timeweb!.searchCloudMessages(
        mapToJSObj(
          {
            "keywordList": searchParam.keywordList,
            "keywordListMatchType": searchParam.type == 0 ? "or" : "and",
            "senderUserIDList": searchParam.userIDList,
            "messageTypeList": searchParam.messageTypeList,
            "conversationID": searchParam.conversationID,
            "timePosition": searchParam.searchTimePosition ?? 0,
            "timePeriod": searchParam.searchTimePeriod ?? 0,
            "cursor": searchParam.searchCursor ?? "",
          },
        ),
      ),
    );
    // List<String> translatedtext = List<String>.from( ?? []);
    // var resMap = {};
    // if (translatedtext.isNotEmpty) {
    //   for (var elem in translatedtext) {
    //     resMap[texts[translatedtext.indexOf(elem)]] = elem;
    //   }
    // }
    var map = jsToMap(res.data);
    int totalCount = map["totalCount"] ?? 0;
    String cursor = map["cursor"] ?? "";
    var searchResultList = List.from((jsToMap(map["searchResultList"])) as List).map((e) => jsToMap(e)).toList();

    if (res.code == 0) {
      return CommonUtils.returnSuccess<V2TimMessageSearchResult>({
        "totalCount": totalCount,
        "searchCursor": cursor,
        "messageSearchResultItems": searchResultList,
      });
    } else {
      return CommonUtils.returnSuccess<V2TimMessageSearchResult>({
        "totalCount": 0,
        "searchCursor": "",
        "messageSearchResultItems": [],
      });
    }
  } catch (e) {
    return CommonUtils.returnErrorForValueCb(e.toString());
  }
}