Join
/api/v2/room/join
Post
rooms
profiles
jwt
Purpose
To allow a user to join an existing chat room.
Body Content [input]
{
uid: string,
roomID: string
}
Returns if valid [output]
{
message: string,
error: 0
}
What the API does
- Finds the
room
being referenced by theroomID
passed [404]. - Checks if the
room
has aprivacy
set topublic
[401]. - Ensures that
uid
does not already correspond to a record in themembers
field with astatus
ofaccepted
orunauthorized
[403]. - Loops through the
chat_invites
field of the record corresponding to theuid
passed from theprofiles
collection, setting any instance having the sameroomID
as that being referenced with astatus
ofpending
to have a value ofaccepted
instead. - Updates and saves the
room
with a new record (if it does not already exist) for themembers
field with theuid
passed, a value ofaccepted
for thestatus
field and usesfalse
as value for theis_admin
andhas_muted
fields. - Generates a
messageID
andtimestamp
corresponding to the current date and time. - Generates and saves a new object in the
messages
field of theroom
usingmessageID
, “uid.${uid
} has joined the chat” asmessage
,timestamp
ascreated_on
andmodified_on
, “_system” assenderID
,false
foris_deleted
and an empty array forviews
.