Fetch
/api/v2/feed/fetch
Post
posts
profiles
groups
users
jwt
pgn
Purpose
To allow a user to fetch all the posts from users that he/she follows that he/she is allowed to see in his/her feed.
Body Content [input]
{
uid: string
}
Returns if valid [output]
{
posts: {
uid: string,
postID: string,
content: string,
posted_on: Date,
modified_on: Date,
reacts: string[],
groupID: string,
shareID: string,
comments: {
uid: string,
commentID: string,
reply_to: string,
posted_on: Date,
modified_on: Date,
reacts: string[],
visibility: string
}[],
visibility: string,
allow_comments: bool,
senderName: string,
senderUsername: string,
groupName: string
}[],
error: 0,
amount: int
}
What the API does
- Finds the
profile
corresponding to theuid
passed and fetches a list of all values inside of thefollowing
andblocked
fields. - Finds all records from the
posts
collection having auid
not corresponding to the one passed. - Loops through each of these
post
records and:- Removes that record if it has a
visibility
set tonone
. - If the record does not have a
visibility
ofnone
,followers
orpublic
, fetch themembers
field of theAccessGroup
corresponding to the value of thevisibility
field and ifuid
is not among the values of thatmembers
field, remove the record. - Remove that record if it has a visibility set to
none
. - Removes that record if the value of its
uid
field is among that of the fetchedblocked
field above. - Finds the
profile
that has auid
corresponding to that of the currentpost
record, and removes that record if theblocked
field contains theuid
passed. - If the record has a value for its
groupID
field, find thegroup
corresponding to thatgroupID
and check ifuid
is a value among thatgroup
’smembers
field with astatus
ofaccepted
. If that is not the case, remove that record. - Else, if the record does not have a value for its
groupID
field and has a value offollowers
for its visibility field, check ifuid
is among the values of thefollowing
field or if it is equal to theuid
of thepost
itself. If that is not the case, remove that record. - Loop through each of the
comment
of thecomments
field of that record and:- Create a new data structure
removedComments
for thecommentID
s of removedcomment
s. - Remove that
comment
if it has avisibility
set tonone
. - If the
comment
does not have avisibility
ofnone
,followers
orpublic
, fetch themembers
field of theAccessGroup
corresponding to the value of thevisibility
field and ifuid
is not among the values of thatmembers
field, remove thecomment
. - Removes that
comment
if the value of itsuid
field is among those of the fetchedblocked
field above. - Finds the
profile
that has auid
corresponding to that of the currentcomment
, and removes thatcomment
if theuid
passed is among the values ofblocked
field. - If the
comment
has avisibility
offollowers
fetch thefollowers
field of theprofile
corresponding to the value of theuid
field of thatcomment
and ifuid
is not among these values or is not equal to the value of theuid
field of thecomment
itself, remove thecomment
. - Append the value of the
commentID
field of all removedcomment
s toremovedComments
. - Loop through all
comment
s again, and remove all those who have a value for theirreply_to
field corresponding to a value inside of theremovedComments
array.
- Create a new data structure
- Removes that record if it has a
- Appends also all the
posts
having a value for theiruid
field corresponding to the one passwd. - Sort all the
posts
by date in descending order of when they were posted based on the value of theirposted_on
field. - Adds a
senderName
andsenderUsername
field to each of theposts
having a value equal to that of thename
andusername
of theuser
who posted it identified by the value of itsuid
field. - Adds a
groupName
field to each of theposts
corresponding to thename
of thegroup
if they have a value for theirgroupID
field.