postQuery static method
Implementation
static EliudQuery postQuery(ProfileInitialised state) {
// We could limit the posts retrieve by making adding the condition: 'authorId' whereIn FollowerHelper.following(me, state.app.documentID)
// However, combining this query with arrayContainsAny in 1 query is not possible currently in the app.
// For now we lay the responsibility with the one posting the post, i.e. that the readAccess includes the person.
// More comments, see firestore.rules > match /post/{id} > allow create
// When we post, we indicate we post to public, followers or just me. The readAccess field is determined with that indicator with the following entries
// - public: readAccess becomes "PUBLIC", + the list of followers + me
// - followers: readAccess becomes the list of followers + me
// - me: readAccess becomes me
if (state is LoggedInWatchingMyProfile) {
if (!state.onlyMyPosts) {
// query where I'm in the readAccess, which means I see my posts and everybody's
// posts where I was included as follower, be it indicated as publc of as follower:
// We're not interested in ALL people's posts, we're only interested in the posts of ourselves or
// or the people I follow
return EliudQuery()
.withCondition(EliudQueryCondition('archived',
isEqualTo: PostArchiveStatus.active.index))
.withCondition(
EliudQueryCondition('feedId', isEqualTo: state.feedId))
.withCondition(EliudQueryCondition('readAccess',
arrayContainsAny: [state.currentMember.documentID, 'PUBLIC']));
} else {
// query where I'm the author. We could include that we're part of the readAccess but that's obsolete
return EliudQuery()
.withCondition(EliudQueryCondition('archived',
isEqualTo: PostArchiveStatus.active.index))
.withCondition(EliudQueryCondition('authorId',
isEqualTo: state.currentMember.documentID))
.withCondition(
EliudQueryCondition('feedId', isEqualTo: state.feedId));
}
} else if (state is LoggedInAndWatchingOtherProfile) {
if (state.iFollowThisPerson) {
// query where that person is the author and I'm in the readAccess
return EliudQuery()
.withCondition(EliudQueryCondition('archived',
isEqualTo: PostArchiveStatus.active.index))
.withCondition(EliudQueryCondition('authorId',
isEqualTo: state.feedPublicInfoModel.documentID))
.withCondition(
EliudQueryCondition('feedId', isEqualTo: state.feedId))
.withCondition(EliudQueryCondition('readAccess',
arrayContainsAny: [state.currentMember.documentID]));
} else {
// query where that person is the author and PUBLIC in the readAccess
return publicQueryForAuthor(
state.feedPublicInfoModel.documentID, state.feedId);
}
} else if (state is NotLoggedInWatchingSomeone) {
return publicQueryForAuthor(
state.feedPublicInfoModel.documentID, state.feedId);
} else if (state is WatchingPublicProfile) {
return publicQuery(state.feedId);
} else {
throw Exception('Post query case not expected');
}
}