Link Search Menu Expand Document

Create

/api/v2/post/create

Post

posts

profiles

groups

notifications

jwt


Purpose

To allow a user to create a post.

Body Content [input]

{
    uid: string,
    content: string,
    visibility: string,
    allow_comments: bool,
    groupID: string,
    shareID: string,
}

Returns if valid [output]

{
    postID: string,
    error: 0
}

What the API does

  • If groupID has been passed, the API ensures that:
    • A group from the groups collection exists by that groupID [404].
    • uid is a value among the members field of that group [403].
    • The record with the uid among themembers field of the found group has a status of accepted [403].
  • If shareID has been passed, the API does the following:
    • Finds the profile corresponding to the uid passed and fetches a list of all values inside of the following and blocked fields.
    • Finds the record from the posts collection having a postID corresponding to the value of the shareID field passed [404].
    • Ensures that the record found does not have a value for its visibility field set to none [403].
    • If the record does not have a visibility of none, followers or public, fetch the members field of the AccessGroup corresponding to the value of the visibility field and ensures that uid is among the values of that members field [403].
    • Ensures that that record’s uid field does not equal to a value among those of the fetched blocked field above [403].
    • Ensures that the profile that has a uid corresponding to that of the current post record does not contain a value corresponding to the uid passed in its blocked field [403].
    • If the record has a value for its groupID field, find the group corresponding to that groupID and check if uid is a value among that group’s members field with a status of accepted [403].
    • Else, if the record does not have a value for its groupID field, and has a value of followers for its visibility field check if uid is among the values of the following field or if it is equal to the uid of the post itself [403].
  • Validates the value of the visibility field passed to make sure that its value is either public, followers, none or one among the accessIDs found in the access_groups field in the record corresponding to that of the uid passed from the profiles collection [400].
  • Generates a unique postID and a timestamp for the current date/time.
  • Adds and saves a document in the posts collection using the uid, content, allow_comments, groupID and visibility fields passed, as well as the generated timestamp for the posted_on and modified_on fields, and uses the generated postID. Empty / DefroomIDault values will be used for the reacts and comments fields.
  • If groupID is not a blank string, loops through each member in the members field of the group that corresponds to groupID from the groups collection that has a status of accepted and a value of false for its has_muted 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 :
    {
      uid: member.uid,
      notificationID: notificationID,
      content: `uid.${uid} posted in the group.${groupID} group`,
      profileID: uid,
      type: "post_new_group",
      created_on: timestamp,
      read: false,
      redirect: `/post/${postID}`
    }