Link Search Menu Expand Document

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 the roomID passed [404].
  • Checks if the room has a privacy set to public [401].
  • Ensures that uid does not already correspond to a record in the members field with a status of accepted or unauthorized [403].
  • Loops through the chat_invites field of the record corresponding to the uid passed from the profiles collection, setting any instance having the same roomID as that being referenced with a status of pending to have a value of accepted instead.
  • Updates and saves the room with a new record (if it does not already exist) for the members field with the uid passed, a value of accepted for the status field and uses false as value for the is_admin and has_muted fields.
  • Generates a messageID and timestamp corresponding to the current date and time.
  • Generates and saves a new object in the messages field of the room using messageID, “uid.${uid} has joined the chat” as message, timestamp as created_on and modified_on, “_system” as senderID, false for is_deleted and an empty array for views.