Admin
/api/v2/room/admin
Post
rooms
profiles
jwt
Purpose
To allow a user that is the administrator of a chat room to remove, add or promote (to being an admin) other users, or to block one from being able to join.
Body Content [input]
{
uid: string,
roomID: string,
membersID: string[],
operation: 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 with astatus
ofaccepted
and which has a value oftrue
for theis_admin
field [403]. - Loops through each value named
profileID
in themembersID
field and does the following. - Checks that
uid
andprofileID
are not the same value [400]. - Ensures that
operation
has a value of eitheradd
,remove
,promote
orblock
[400]. - Ensures that
profileID
does not already correspond to a record in themembers
field ifoperation
is set toadd
[403]. - Ensures that
profileID
corresponds to a record in themembers
field ifoperation
is set toremove
,promote
orblock
[403]. - Ensures that
profileID
does not correspond to a record in themembers
field with a value oftrue
for theis_admin
field ifoperation
is set toremove
,promote
orblock
[403]. - Generates a
messageID
andtimestamp
corresponding to the current date and time ifoperation
is set to anything other thanpromote
. - Saves a new
invite
in thechat_invites
field of the record corresponding to theprofileID
passed, from theprofiles
collection withroomID
and usespending
as value for thestate
field if operation is set toadd
. - Updates and saves the
room
with a new record for themembers
field with theprofileID
passed, and uses a value ofpending
for thestatus
field, and usesfalse
as value for theis_admin
andhas_muted
fields ifoperation
is set toadd
. - 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 ifoperation
is set toadd
:{ uid: profileID, 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}` }
- Removes the record in the
members
field referenced by theprofileID
passed from theroom
and saves ifoperation
is set toremove
. - Generates and saves a new object in the
messages
field of theroom
usingmessageID
, “uid.${uid
} was kicked from the chat” asmessage
,timestamp
ascreated_on
andmodified_on
, “_system” assenderID
,false
foris_deleted
and an empty array forviews
ifoperation
is set toremove
. - Loops through the
chat_invites
field of the record corresponding to theprofileID
passed from theprofiles
collection, finding any instance having the sameroomID
as that being referenced with astatus
ofpending
, and setting that instance to have astatus
ofrejected
ifoperation
is set toblock
orremove
. - Updates and saves the
room
with the record of themembers
field corresponding toprofileID
to use a value ofunauthorized
for thestatus
field ifoperation
is set toblock
. - 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 ifoperation
is set toremove
orblock
:{ uid: profileID, notificationID: notificationID, content: `You were removed from the room.${roomID} chat room`, profileID: uid, type: "room_kick", created_on: timestamp, read: false, redirect: `/chat/${roomID}` }
- Generates and saves a new object in the
messages
field of theroom
usingmessageID
, “uid.${uid
} has been banned from the chat” asmessage
,timestamp
ascreated_on
andmodified_on
, “_system” assenderID
,false
foris_deleted
and an empty array forviews
ifoperation
is set toblock
. - Updates and saves the
room
with the record for themembers
field corresponding toprofileID
having a value oftrue
for theis_admin
field ifoperation
is set topromote
. - 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 ifoperation
is set topromote
:{ uid: profileID, notificationID: notificationID, content: `You were promoted to an admin in the room.${roomID} chat room`, profileID: uid, type: "room_promote", created_on: timestamp, read: false, redirect: `/chat/${roomID}` }