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
groupIDhas been passed, the API ensures that:- A group from the
groupscollection exists by thatgroupID[404]. uidis a value among themembersfield of thatgroup[403].- The record with the
uidamong themembersfield of the foundgrouphas a status ofaccepted[403].
- A group from the
- If
shareIDhas been passed, the API does the following:- Finds the
profilecorresponding to theuidpassed and fetches a list of all values inside of thefollowingandblockedfields. - Finds the record from the
postscollection having apostIDcorresponding to the value of theshareIDfield passed [404]. - Ensures that the record found does not have a value for its
visibilityfield set tonone[403]. - If the record does not have a
visibilityofnone,followersorpublic, fetch themembersfield of theAccessGroupcorresponding to the value of thevisibilityfield and ensures thatuidis among the values of thatmembersfield [403]. - Ensures that that record’s
uidfield does not equal to a value among those of the fetchedblockedfield above [403]. - Ensures that the
profilethat has auidcorresponding to that of the currentpostrecord does not contain a value corresponding to theuidpassed in itsblockedfield [403]. - If the record has a value for its
groupIDfield, find thegroupcorresponding to thatgroupIDand check ifuidis a value among thatgroup’smembersfield with astatusofaccepted[403]. - Else, if the record does not have a value for its
groupIDfield, and has a value offollowersfor its visibility field check ifuidis among the values of thefollowingfield or if it is equal to theuidof thepostitself [403].
- Finds the
- Validates the value of the
visibilityfield passed to make sure that its value is eitherpublic,followers,noneor one among theaccessIDs found in theaccess_groupsfield in the record corresponding to that of theuidpassed from theprofilescollection [400]. - Generates a unique
postIDand atimestampfor the current date/time. - Adds and saves a document in the
postscollection using theuid,content,allow_comments,groupIDandvisibilityfields passed, as well as the generatedtimestampfor theposted_onandmodified_onfields, and uses the generatedpostID. Empty / DefroomIDault values will be used for thereactsandcommentsfields. - If
groupIDis not a blank string, loops through eachmemberin themembersfield of thegroupthat corresponds togroupIDfrom thegroupscollection that has a status ofacceptedand a value offalsefor itshas_mutedfield, generates a newnotificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection 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}` }