Create
/api/v2/room/create
Post
rooms
profiles
notifications
jwt
Purpose
To allow a user to create a chat room.
Body Content [input]
{
uid: string,
membersID: string[],
name: string,
description: string,
icon: string,
privacy: string
}
Returns if valid [output]
{
roomID: string,
error: 0
}
What the API does
- Ensures that privacy is either set to
private
orpublic
, and defaults topublic
. - Generates a
roomID
. - Loops through
membersID
with each value corresponding tomemberID
and:- 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 tomemberID
(dest
) [404]. - Ensures that neither
uid
is found indest
’sblocked
field nor thatmemberID
is found insrc
’sblocked
field [403]. - Ensures that
uid
is found indest
’sfollowers
field [403]. - Saves a new
invite
indest
’schat_invites
with the generatedroomID
and usespending
as value for thestate
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:{ uid: memberID, notificationID: notificationID, content: `uid.${uid} invited you to the room.${roomID} chat room`, profileID: uid, type: "room_invite", created_on: timestamp, read: false, redirect: `/chat/${roomID}` }
- Fetches the profile for the record with a
- Generates a new object with the passed
name
,description
,privacy
,icon
and the generatedroomID
. Empty values will be used formessages
andthreads
. Records will be added to themembers
field with each one corresponding to the current user’suid
, with a value offalse
foris_admin
andhas_muted
, and uses a value ofpending
for thestatus
field. A record will be similarly created for the current user using theuid
passed, but with values oftrue
foris_admin
,false
forhas_muted
andaccepted
forstatus
.