Link Search Menu Expand Document

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 the roomID passed [404].
  • Ensures that uid corresponds to a record in the members field with a status of accepted and which has a value of true for the is_admin field [403].
  • Loops through each value named profileID in the membersID field and does the following.
  • Checks that uid and profileID are not the same value [400].
  • Ensures that operation has a value of either add, remove, promote or block [400].
  • Ensures that profileID does not already correspond to a record in the members field if operation is set to add [403].
  • Ensures that profileID corresponds to a record in the members field if operation is set to remove, promote or block [403].
  • Ensures that profileID does not correspond to a record in the members field with a value of true for the is_admin field if operation is set to remove, promote or block [403].
  • Generates a messageID and timestamp corresponding to the current date and time if operation is set to anything other than promote.
  • Saves a new invite in the chat_invites field of the record corresponding to the profileID passed, from the profiles collection with roomID and uses pending as value for the state field if operation is set to add.
  • Updates and saves the room with a new record for the members field with the profileID passed, and uses a value of pending for the status field, and uses false as value for the is_admin and has_muted fields if operation is set to add.
  • Generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications collection with the following data if operation is set to add:
    {
      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 the profileID passed from the room and saves if operation is set to remove.
  • Generates and saves a new object in the messages field of the room using messageID, “uid.${uid} was kicked from the chat” as message, timestamp as created_on and modified_on, “_system” as senderID, false for is_deleted and an empty array for views if operation is set to remove.
  • Loops through the chat_invites field of the record corresponding to the profileID passed from the profiles collection, finding any instance having the same roomID as that being referenced with a status of pending, and setting that instance to have a status of rejected if operation is set to block or remove.
  • Updates and saves the room with the record of the members field corresponding to profileID to use a value of unauthorized for the status field if operation is set to block.
  • Generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications collection with the following data if operation is set to remove or block:
    {
      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 the room using messageID, “uid.${uid} has been banned from the chat” as message, timestamp as created_on and modified_on, “_system” as senderID, false for is_deleted and an empty array for views if operation is set to block.
  • Updates and saves the room with the record for the members field corresponding to profileID having a value of true for the is_admin field if operation is set to promote.
  • Generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications collection with the following data if operation is set to promote:
    {
      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}`
    }