loadProfiles method

  1. @override
Future<void> loadProfiles({
  1. bool includeSelf = false,
})
override

Implementation

@override
Future<void> loadProfiles({bool includeSelf = false}) async {
  AppConfig.logger.t("loadProfiles");
  try {
    _profiles.value = await ProfileFirestore().retrieveAllProfiles();

    if(!includeSelf) _profiles.remove(profile.id);

    if((profile.followers?.isNotEmpty ?? false) && _profiles.isNotEmpty) {
      _followerProfiles.value = _profiles.entries
          .where((entry) => profile.followers!.contains(entry.key))
          .fold(<String, AppProfile>{}, (map, entry) {
        map[entry.key] = entry.value;
        return map;
      });
    }

    if((profile.following?.isNotEmpty ?? false) && _profiles.isNotEmpty) {
      _followingProfiles.value = _profiles.entries
          .where((entry) => profile.following!.contains(entry.key))
          .fold(<String, AppProfile>{}, (map, entry) {
        map[entry.key] = entry.value;
        return map;
      });
    }

    if((profile.itemmates?.isNotEmpty ?? false )&& _profiles.isNotEmpty) {
      _mates.value = _profiles.entries
          .where((entry) => profile.following!.contains(entry.key))
          .fold(<String, AppProfile>{}, (map, entry) {
        map[entry.key] = entry.value;
        return map;
      });
    }

  } catch (e) {
    AppConfig.logger.e(e.toString());
  }

  isLoading.value = false;
  AppConfig.logger.d("${_profiles.length} profiles found ");
  update();
}