getFollowersAndFollowees method

Future<LCFollowersAndFollowees> getFollowersAndFollowees(
  1. {bool includeFollower = false,
  2. bool includeFollowee = false,
  3. bool returnCount = false}
)

Queries followers and followees at the same time.

returnCount indicates whether to return followers/followees count.

Implementation

Future<LCFollowersAndFollowees> getFollowersAndFollowees(
    {bool includeFollower = false,
    bool includeFollowee = false,
    bool returnCount = false}) async {
  Map<String, dynamic> queryParams = {};
  if (returnCount) {
    queryParams['count'] = 1;
  }
  if (includeFollower || includeFollowee) {
    List<String> includes = <String>[];
    if (includeFollower) {
      includes.add('follower');
    }
    if (includeFollowee) {
      includes.add('followee');
    }
    queryParams['include'] = includes.join(',');
  }
  Map response = await LeanCloud._httpClient
      .get('users/$objectId/followersAndFollowees', queryParams: queryParams);
  LCFollowersAndFollowees result = new LCFollowersAndFollowees();
  if (response.containsKey('followers')) {
    result.followers = <LCObject>[];
    for (dynamic item in response['followers']) {
      _LCObjectData objectData = _LCObjectData.decode(item);
      LCObject follower = new LCObject('_Follower');
      follower._merge(objectData);
      result.followers?.add(follower);
    }
  }
  if (response.containsKey('followees')) {
    result.followees = <LCObject>[];
    for (dynamic item in response['followees']) {
      _LCObjectData objectData = _LCObjectData.decode(item);
      LCObject followee = new LCObject('_Followee');
      followee._merge(objectData);
      result.followees?.add(followee);
    }
  }
  if (response.containsKey('followers_count')) {
    result.followersCount = response['followers_count'];
  }
  if (response.containsKey('followees_count')) {
    result.followeesCount = response['followees_count'];
  }
  return result;
}