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
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]. - 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]. - Ensures that the 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 record does not contain a value corresponding to theuid
passed in itsblocked
field [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]. - Checks that the
post
has a value oftrue
for itsallow_comments
field [403]. - Checks that there is a
comment
with a value ofreply_to
for itscommentID
field inside of thatpost
’scomments
field ifreply_to
is not empty [404]. - Loops through each of the
comment
of thecomments
field of thatpost
ifreply_to
is not empty and:- Create a new data structure
illegalComments
for thecommentID
s ofcomment
s that theuser
is not allowed to reply to. - Append the value of the
commentID
field of acomment
if:- That
comment
if has avisibility
set tonone
. uid
is not among the values of themembers
field obtained by fetching themembers
field of theAccessGroup
corresponding to the value of thevisibility
field if thecomment
does not have avisibility
ofnone
,followers
orpublic
.- The value of its
uid
field is among those of the fetchedblocked
field above. - The
blocked
field of theprofile
that has auid
corresponding to that of thecomment
has theuid
passed among its values. uid
is not among the values of thefollowers
field of theprofile
corresponding to the value of theuid
field of thatcomment
if thecomment
has avisibility
offollowers
and is not equal to theuid
of thatcomment
either.
- That
- Create a new data structure
- Checks that the value of the
reply_to
field passed is not among those of theillegalComments
data structure [403]. - Validates the value of the
visibility
field passed to make sure that its value is eitherpublic
,followers
,none
or one among theaccessID
s found in theaccess_groups
field in the record corresponding to that of theuid
passed from theprofiles
collection [400]. - Generates a unique
commentID
and atimestamp
for the current date/time. - Creates and saves a new object inside of that
post
’scomments
field with the values of theuid
,comment
,reply_to
andvisibility
fields passed, along with the value of the generatedtimestamp
for thecreated_on
andmodified_on
fields, and uses the generatedcommentID
as well as an empty array for thereacts
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:{ 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
notificationID
and atimestamp
corresponding to the current date and time, and creates a new object in thenotifications
collection with the following data ifreply_to
corresponds 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}` }