determineProfileState method

Future<ProfileState> determineProfileState(
  1. InitialiseProfileEvent event
)

Implementation

Future<ProfileState> determineProfileState(
    InitialiseProfileEvent event) async {
  var accessState = event.accessDetermined;
  var currentMemberModel = accessState.getMember();
  var pageContextInfo =
      eliudrouter.Router.getPageContextInfoWithRoute(event.modalRoute);
  var feedId = event.feedId;
  var app = event.app;
  if (currentMemberModel == null) {
    if (pageContextInfo.parameters != null) {
      var param = pageContextInfo
          .parameters![SwitchMember.switchMemberFeedPageParameter];
      if (param == null) {
        return WatchingPublicProfile(
            feedId: feedId,
            app: app,
            uploadingProfilePhotoProgress: null,
            uploadingBGProgress: null);
      } else {
        var feedPublicInfoModel = await getMemberPublicInfo(param);
        var feedProfileModel = await getMemberProfileModelWithPublicInfo(
            false,
            app,
            feedId,
            feedPublicInfoModel,
            MemberProfileAccessibleByGroup.public,
            null);
        return NotLoggedInWatchingSomeone(
            app: app,
            feedId: feedId,
            feedProfileModel: feedProfileModel,
            feedPublicInfoModel: feedPublicInfoModel,
            uploadingProfilePhotoProgress: null,
            uploadingBGProgress: null);
      }
    } else {
      return WatchingPublicProfile(
          feedId: feedId,
          app: app,
          uploadingProfilePhotoProgress: null,
          uploadingBGProgress: null);
    }
  } else {
    var defaultPostGroup = PostAccessibleByGroup.public;
    var defaultMemberProfileGroup =
        toMemberProfileAccessibleByGroup(defaultPostGroup.index);
    List<String> defaultMembers = [];
    // Determine current member
    String? param;
    if (pageContextInfo.parameters != null) {
      param = pageContextInfo
          .parameters![SwitchMember.switchMemberFeedPageParameter];
    }

    if (param == null) {
      var currentMemberProfileModel =
          await getMemberProfileModelWithCurrentMemberModel(true, app, feedId,
              currentMemberModel, defaultMemberProfileGroup, defaultMembers);
      return LoggedInWatchingMyProfile(
          feedId: feedId,
          app: app,
          currentMemberProfileModel: currentMemberProfileModel,
          currentMember: currentMemberModel,
          postAccessibleByGroup: defaultPostGroup,
          postAccessibleByMembers: defaultMembers,
          onlyMyPosts: false,
          uploadingProfilePhotoProgress: null,
          uploadingBGProgress: null);
    } else {
      var currentMemberProfileModel =
          await getMemberProfileModelWithCurrentMemberModel(
              false,
              app,
              feedId,
              currentMemberModel,
              defaultMemberProfileGroup,
              defaultMembers);
      var following =
          await FollowerHelper.following(currentMemberModel.documentID, app);
      var feedPublicInfoModel = await getMemberPublicInfo(param);
      var feedProfileModel = await getMemberProfileModelWithPublicInfo(
          false,
          app,
          feedId,
          feedPublicInfoModel,
          MemberProfileAccessibleByGroup.public,
          null);
      return LoggedInAndWatchingOtherProfile(
          feedId: feedId,
          app: app,
          currentMemberProfileModel: currentMemberProfileModel,
          currentMember: currentMemberModel,
          postAccessibleByGroup: PostAccessibleByGroup.public,
          feedProfileModel: feedProfileModel,
          feedPublicInfoModel: feedPublicInfoModel,
          iFollowThisPerson: following.contains(
            currentMemberModel.documentID,
          ),
          uploadingProfilePhotoProgress: null,
          uploadingBGProgress: null);
    }
  }
}