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
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 there is a
comment
corresponding to the value of thecommentID
field passed inside of thatpost
’scomments
field [404]. - Loops through each of the
comment
of thecomments
field of thatpost
if the value of thereply_to
field of the foundcomment
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
and is not equal to theuid
of thatcomment
either.- 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
.
- That
- Create a new data structure
- Checks that the value of the
reply_to
field of the foundcomment
is not among those of theillegalComments
data structure [403]. - If
react
has a value oftrue
, ensure thatuid
is not already a value among thereacts
field of the foundcomment
, else, ifreact
has a value offalse
, ensure thatuid
is a value among thereacts
field of the foundcomment
[403]. - Updates and saves the object inside of that
post
’scomments
field corresponding to thecommentID
passed, and appendsuid
to the values of thereacts
field isreact
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: 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}` }