Accept
/api/v2/room/accept
Post
rooms
profiles
jwt
Purpose
To allow a user to accept or refuse an invitation to join a chat room.
Body Content [input]
{
uid: string,
roomID: string,
action: string
}
Returns if valid [output]
{
message: string,
error: 0
}
What the API does
- Finds the
room
being referenced by theroomID
passed [404]. - Ensures that
uid
corresponds to a record in themembers
field [403]. - Ensures that that record in the
members
field does not have astatus
ofaccepted
orunauthorized
[403]. - Ensures that
action
has a value ofaccept
orreject
[400]. - Loops through the
chat_invites
field of the record corresponding to theuid
passed from theprofiles
collection, finding any instance having the sameroomID
as that being referenced and having a value ofpending
for thestatus
field [403]. - Sets that/those instance(s) to have a
status
ofaccepted
ifaction
is set toaccept
else,status
will have a value ofrejected
. - Updates and saves the
room
with the record in themembers
field referenced by theuid
passed to have a status ofaccepted
ifaction
is set toaccept
else, removes the record. - Generates a
messageID
andtimestamp
corresponding to the current date and time ifaction
is set toaccept
. - 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
ifaction
is set toaccept
.