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 thatgroupID
[404]. uid
is a value among themembers
field of thatgroup
[403].- The record with the
uid
among themembers
field of the foundgroup
has a status ofaccepted
[403].
- A group from the
- If
shareID
has been passed, the API does the following:- 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 value of theshareID
field 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]. - Ensures that that 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 currentpost
record does not contain a value corresponding to theuid
passed in itsblocked
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]. - 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].
- Finds the
- Validates the value of the
visibility
field passed to make sure that its value is eitherpublic
,followers
,none
or one among theaccessID
s found in theaccess_groups
field in the record corresponding to that of theuid
passed from theprofiles
collection [400]. - Generates a unique
postID
and atimestamp
for the current date/time. - Adds and saves a document in the
posts
collection using theuid
,content
,allow_comments
,groupID
andvisibility
fields passed, as well as the generatedtimestamp
for theposted_on
andmodified_on
fields, and uses the generatedpostID
. Empty / DefroomIDault values will be used for thereacts
andcomments
fields. - If
groupID
is not a blank string, loops through eachmember
in themembers
field of thegroup
that corresponds togroupID
from thegroups
collection that has a status ofaccepted
and a value offalse
for itshas_muted
field, generates a newnotificationID
and atimestamp
corresponding to the current date and time, and creates a new object in thenotifications
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}` }