getMemberProfileModel static method

Future<MemberProfileModel> getMemberProfileModel(
  1. bool create,
  2. AppModel app,
  3. String feedId,
  4. String memberId,
  5. String? photoURL,
  6. String name,
  7. MemberProfileAccessibleByGroup accessibleByGroup,
  8. List<String>? accessibleByMembers,
)

Implementation

static Future<MemberProfileModel> getMemberProfileModel(
    bool create,
    AppModel app,
    String feedId,
    String memberId,
    String? photoURL,
    String name,
    MemberProfileAccessibleByGroup accessibleByGroup,
    List<String>? accessibleByMembers) async {
  var key = "$memberId-$feedId";
  var memberProfileModel =
      await memberProfileRepository(appId: app.documentID)!
          .get(key, onError: (exception) {});
  if (memberProfileModel == null) {
    // create default profile
    memberProfileModel = MemberProfileModel(
      documentID: key,
      appId: app.documentID,
      feedId: feedId,
      authorId: memberId,
      accessibleByGroup: accessibleByGroup,
      accessibleByMembers: accessibleByMembers,
      profileOverride: photoURL,
      nameOverride: name,
      readAccess: [
        memberId
      ], // default readAccess to the owner. The function will expand this based on accessibleByGroup/Members
    );
    if (create) {
      await memberProfileRepository(appId: app.documentID)!
          .add(memberProfileModel);
    }
  }
  return memberProfileModel;
}