Fetch Group
/api/v2/feed/fetch/group
Post
posts
profiles
groups
users
jwt
pgn
Purpose
To allow a user to fetch all the posts found in one specific group.
Body Content [input]
{
uid: string,
groupID: 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 the
group
being referenced using the value of thegroupID
field passed [404]. - Checks if the found
group
has a value for itsprivacy
field that is set topublic
or if there is a record in itsmembers
field with auid
corresponding to the one passed and with astatus
ofaccepted
[403]. - Finds all records from the
posts
collection having a value for theirgroupID
field 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. - 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
- 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.