Follow
/api/v2/profile/follow
Post
profiles
notifications
jwt
Purpose
To allow a user to follow another user.
Body Content [input]
{
uid: string,
profileID: string,
status: bool
}
Returns if valid [output]
{
message: string,
error: 0
}
What the API does
- Checks that
uid
andprofileID
aren’t the same value [403]. - Fetches the profile for the record with a
uid
corresponding to theuid
passed (src
) [404]. - Fetches the profile for the record with a
uid
corresponding to theprofileID
passed (dest
) [404]. - Ensure that neither
uid
is found indest
’sblocked
field nor thatprofileID
is found insrc
’sblocked
field [403]. - Ensure that
profileID
is not insrc
’sfollowing
orsent_follow_requests
field ifstatus
istrue
and thatprofileID
is insrc
’sfollowing
orsent_follow_requests
field ifstatus
isfalse
[403]. - If
dest
’saccount_type
is set topublic
orstatus
is equal tofalse
, do the following:- Append or filter out
profileID
insrc
’sfollowing
depending on the value ofstatus
. - Append or filter out
uid
indest
’sfollowers
depending on the value ofstatus
.
- Append or filter out
- Else if
dest
’saccount_type
is set toprivate
orrestricted
, do the following:- Append or filter out
profileID
insrc
’ssent_follow_requests
depending on the value ofstatus
. - Append or filter out
uid
indest
’sreceived_follow_requests
depending on the value ofstatus
.
- Append or filter out
- Do the same thing as above if
dest
’saccount_type
is set toghost
and hasuid
as value among itsfollowing
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 ifstatus
has a value oftrue
:{ uid: profileID, notificationID: notificationID, content: `uid.${uid} has sent you a follow request`, profileID: uid, type: "follow_send", created_on: timestamp, read: false, redirect: `/profile/${uid}` }
If
dest
’saccount_type
is set topublic
, make thecontent
field of the above object have a value of “${username} is now following you” instead.