Link Search Menu Expand Document

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 or public, and defaults to public.
  • Generates a roomID.
  • Loops through membersID with each value corresponding to memberID and:
    • Fetches the profile for the record with a uid corresponding to the uid passed (src) [404].
    • Fetches the profile for the record with a uid corresponding to memberID (dest) [404].
    • Ensures that neither uid is found in dest’s blocked field nor that memberID is found in src’s blocked field [403].
    • Ensures that uid is found in dest’s followers field [403].
    • Saves a new invite in dest’s chat_invites with the generated roomID and uses pending as value for the state field.
    • 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:
      {
      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}`
      }
      
  • Generates a new object with the passed name, description, privacy, icon and the generated roomID. Empty values will be used for messages and threads. Records will be added to the members field with each one corresponding to the current user’s uid, with a value of false for is_admin and has_muted, and uses a value of pending for the status field. A record will be similarly created for the current user using the uid passed, but with values of true for is_admin, false for has_muted and accepted for status.