fromEntityPlus static method

Future<MemberProfileModel?> fromEntityPlus(
  1. String documentID,
  2. MemberProfileEntity? entity, {
  3. String? appId,
})

Implementation

static Future<MemberProfileModel?> fromEntityPlus(
    String documentID, MemberProfileEntity? entity,
    {String? appId}) async {
  if (entity == null) return null;

  MemberMediumModel? profileBackgroundHolder;
  if (entity.profileBackgroundId != null) {
    try {
      profileBackgroundHolder = await memberMediumRepository(appId: appId)!
          .get(entity.profileBackgroundId);
    } on Exception catch (e) {
      print('Error whilst trying to initialise profileBackground');
      print(
          'Error whilst retrieving memberMedium with id ${entity.profileBackgroundId}');
      print('Exception: $e');
    }
  }

  var counter = 0;
  return MemberProfileModel(
    documentID: documentID,
    appId: entity.appId ?? '',
    feedId: entity.feedId,
    authorId: entity.authorId,
    profile: entity.profile,
    profileBackground: profileBackgroundHolder,
    profileOverride: entity.profileOverride,
    nameOverride: entity.nameOverride,
    accessibleByGroup:
        toMemberProfileAccessibleByGroup(entity.accessibleByGroup),
    accessibleByMembers: entity.accessibleByMembers,
    readAccess: entity.readAccess,
    memberMedia: entity.memberMedia == null
        ? null
        : List<MemberMediumContainerModel>.from(
            await Future.wait(entity.memberMedia!.map((item) {
            counter++;
            return MemberMediumContainerModel.fromEntityPlus(
                counter.toString(), item,
                appId: appId);
          }).toList())),
  );
}