Comment Add
/api/v2/feed/comment/add
Post
posts
profiles
groups
notifications
jwt
Purpose
To allow a user to comment on a post that he/she is allowed to comment on.
Body Content [input]
{
uid: string,
postID: string,
comment: string,
visibility: string,
reply_to: string
}
Returns if valid [output]
{
commentID: 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 the
posthas a value oftruefor itsallow_commentsfield [403]. - Checks that there is a
commentwith a value ofreply_tofor itscommentIDfield inside of thatpost’scommentsfield ifreply_tois not empty [404]. - Loops through each of the
commentof thecommentsfield of thatpostifreply_tois 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,followersorpublic.- 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 avisibilityoffollowersand is not equal to theuidof thatcommenteither.
- That
- Create a new data structure
- Checks that the value of the
reply_tofield passed is not among those of theillegalCommentsdata structure [403]. - Validates the value of the
visibilityfield passed to make sure that its value is eitherpublic,followers,noneor one among theaccessIDs found in theaccess_groupsfield in the record corresponding to that of theuidpassed from theprofilescollection [400]. - Generates a unique
commentIDand atimestampfor the current date/time. - Creates and saves a new object inside of that
post’scommentsfield with the values of theuid,comment,reply_toandvisibilityfields passed, along with the value of the generatedtimestampfor thecreated_onandmodified_onfields, and uses the generatedcommentIDas well as an empty array for thereactsfield. - Generates a new
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data:{ uid: post.uid, notificationID: notificationID, content: `uid.${uid} commented on your post`, profileID: uid, type: "comment_new", created_on: timestamp, read: false, redirect: `/posts/${postID}` } - Generates a new
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data ifreply_tocorresponds to something other than an empty string:{ uid: comments[reply_to].uid, notificationID: notificationID, content: `uid.${uid} replied to your comment`, profileID: uid, type: "comment_reply", created_on: timestamp, read: false, redirect: `/posts/${postID}` }