Fetch Save
/api/v2/feed/fetch/save
Post
posts
profiles
groups
users
jwt
pgn
Purpose
To allow a user to fetch all of his/her saved posts.
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. - 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 and if thegroup
has a value ofprivate
for itsprivacy
field, 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
- Generates an array of
savedPosts
by concatenating the values of theposts
field of everycollection
found in thecollections
field of the user’sprofile
. - Filters out the
posts
, keeping only those having a value for theirpostID
field that is among the values in thesavedPosts
list. - 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.