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
profilecorresponding to theuidpassed and fetches a list of all values inside of thefollowingandblockedfields. - Finds the record from the
postscollection having apostIDcorresponding to the one passed [404]. - Ensures that the record found does not have a value for its
visibilityfield set tonone[403]. - If the record does not have a
visibilityofnone,followersorpublic, fetch themembersfield of theAccessGroupcorresponding to the value of thevisibilityfield and ensures thatuidis among the values of thatmembersfield [403]. - Ensures that that record’s
uidfield does not equal to a value among those of the fetchedblockedfield above [403]. - Ensures that the
profilethat has auidcorresponding to that of the currentpostrecord does not contain a value corresponding to theuidpassed in itsblockedfield [403]. - If the record has a value for its
groupIDfield, find thegroupcorresponding to thatgroupIDand check ifuidis a value among thatgroup’smembersfield with astatusofaccepted[403]. - Else, if the record does not have a value for its
groupIDfield, and has a value offollowersfor its visibility field check ifuidis among the values of thefollowingfield or if it is equal to theuidof thepostitself [403]. - If
reacthas a value oftrue, ensure thatuidis not already a value among thereactsfield of thatpost, else, ifreacthas a value offalse, ensure thatuidis a value among thereactsfield of thatpost[403]. - Appends and saves
uidto thereactsfield of thatpostifreactis set totrue, else removesuidfrom the values of that field. - Generates a new
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data ifreactis 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}` }