Post React
/api/v2/feed/post/react
Post
posts
profiles
groups
notifications
jwt
Purpose
To allow a user to react on a post that he/she is allowed to react on.
Body Content [input]
{
uid: string,
postID: string,
react: bool
}
Returns if valid [output]
{
message: string,
error: 0
}
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 record from the
posts
collection having apostID
corresponding to the one passed [404]. - Ensures that the record found does not have a value for its
visibility
field set tonone
[403]. - If the record does not have a
visibility
ofnone
,followers
orpublic
, fetch themembers
field of theAccessGroup
corresponding to the value of thevisibility
field and ensures thatuid
is among the values of thatmembers
field [403]. - Ensures that that record’s
uid
field does not equal to a value among those of the fetchedblocked
field above [403]. - Ensures that the
profile
that has auid
corresponding to that of the currentpost
record does not contain a value corresponding to theuid
passed in itsblocked
field [403]. - 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
[403]. - 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 [403]. - If
react
has a value oftrue
, ensure thatuid
is not already a value among thereacts
field of thatpost
, else, ifreact
has a value offalse
, ensure thatuid
is a value among thereacts
field of thatpost
[403]. - Appends and saves
uid
to thereacts
field of thatpost
ifreact
is set totrue
, else removesuid
from the values of that field. - Generates a new
notificationID
and atimestamp
corresponding to the current date and time, and creates a new object in thenotifications
collection with the following data ifreact
is set totrue
:{ uid: post.uid, notificationID: notificationID, content: `uid.${uid} reacted to your post`, profileID: uid, type: "post_react", created_on: timestamp, read: false, redirect: `/posts/${postID}` }