Comment React
/api/v2/feed/comment/react
Post
posts
profiles
groups
notifications
jwt
Purpose
To allow a user to react to an existing comment on a post.
Body Content [input]
{
uid: string,
postID: string,
commentID: 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]. - If the record has a value for its
groupIDfield, find thegroupcorresponding to thatgroupIDand check ifuidis a value among thatgroup’smembersfield with astatusofaccepted[403]. - Ensures that the 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 record does not contain a value corresponding to theuidpassed in itsblockedfield [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]. - Checks that there is a
commentcorresponding to the value of thecommentIDfield passed inside of thatpost’scommentsfield [404]. - Loops through each of the
commentof thecommentsfield of thatpostif the value of thereply_tofield of the foundcommentis not empty and:- Create a new data structure
illegalCommentsfor thecommentIDs ofcomments that theuseris not allowed to reply to. - Append the value of the
commentIDfield of acommentif:- That
commentif has avisibilityset tonone. uidis not among the values of themembersfield obtained by fetching themembersfield of theAccessGroupcorresponding to the value of thevisibilityfield if thecommentdoes not have avisibilityofnone,followersorpublicand is not equal to theuidof thatcommenteither.- The value of its
uidfield is among those of the fetchedblockedfield above. - The
blockedfield of theprofilethat has auidcorresponding to that of thecommenthas theuidpassed among its values. uidis not among the values of thefollowersfield of theprofilecorresponding to the value of theuidfield of thatcommentif thecommenthas avisibilityoffollowers.
- That
- Create a new data structure
- Checks that the value of the
reply_tofield of the foundcommentis not among those of theillegalCommentsdata structure [403]. - If
reacthas a value oftrue, ensure thatuidis not already a value among thereactsfield of the foundcomment, else, ifreacthas a value offalse, ensure thatuidis a value among thereactsfield of the foundcomment[403]. - Updates and saves the object inside of that
post’scommentsfield corresponding to thecommentIDpassed, and appendsuidto the values of thereactsfield isreactis 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: comments[commentID].uid, notificationID: notificationID, content: `uid.${uid} reacted to your comment`, profileID: uid, type: "comment_react", created_on: timestamp, read: false, redirect: `/posts/${postID}` }