getFriendsInfo method

Future<V2TimValueCallback<List<V2TimFriendInfoResult>>> getFriendsInfo(
  1. Map<String, dynamic> params
)

Implementation

Future<V2TimValueCallback<List<V2TimFriendInfoResult>>> getFriendsInfo(
    Map<String, dynamic> params) async {
  try {
    final res = await wrappedPromiseToFuture(
        timeWeb!.getFriendProfile(FriendInfo.formateGetInfoParams(params)));
    final resultData = jsToMap(res.data);
    final successFriendList = resultData['friendList'] as List;
    final failureFriendList = resultData['failureUserIDList'] as List;
    var formatedFailureFriendList = [];
    if (failureFriendList.isNotEmpty) {
      final failedUserIDList =
          failureFriendList.map((e) => jsToMap(e)["userID"]).toList();
      final userProfileListResult = await wrappedPromiseToFuture(timeWeb!
          .getUserProfile(mapToJSObj({"userIDList": failedUserIDList})));
      formatedFailureFriendList = failureFriendList.map((e) {
        final item = jsToMap(e);
        final userID = item["userID"];
        final userProfileList = userProfileListResult.data as List;
        final result = userProfileList
            .firstWhere((element) => jsToMap(element)["userID"] == userID);
        item['profile'] = result;
        return mapToJSObj(item);
      }).toList();
    }
    final result = await FriendInfo.formateFriendInfoResult(
        successFriendList, formatedFailureFriendList);

    return CommonUtils.returnSuccess<List<V2TimFriendInfoResult>>(result);
  } catch (error) {
    return CommonUtils.returnErrorForValueCb<List<V2TimFriendInfoResult>>(
        error);
  }
}