Link Search Menu Expand Document

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 and profileID aren’t the same value [403].
  • Fetches the profile for the record with a uid corresponding to the uid passed (src) [404].
  • Fetches the profile for the record with a uid corresponding to the profileID passed (dest) [404].
  • Ensure that neither uid is found in dest’s blocked field nor that profileID is found in src’s blocked field [403].
  • Ensure that profileID is not in src’s following or sent_follow_requests field if status is true and that profileID is in src’s following or sent_follow_requests field if status is false [403].
  • If dest’s account_type is set to public or status is equal to false, do the following:
    • Append or filter out profileID in src’s following depending on the value of status.
    • Append or filter out uid in dest’s followers depending on the value of status.
  • Else if dest’s account_type is set to private or restricted, do the following:
    • Append or filter out profileID in src’s sent_follow_requests depending on the value of status.
    • Append or filter out uid in dest’s received_follow_requests depending on the value of status.
  • Do the same thing as above if dest’s account_type is set to ghost and has uid as value among its following field.
  • Generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications collection with the following data if status has a value of true:
    {
      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’s account_type is set to public, make the content field of the above object have a value of “${username} is now following you” instead.