Link Search Menu Expand Document

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 the roomID passed [404].
  • Ensures that uid corresponds to a record in the members field [403].
  • Ensures that that record in the members field does not have a status of accepted or unauthorized [403].
  • Ensures that action has a value of accept or reject [400].
  • Loops through the chat_invites field of the record corresponding to the uid passed from the profiles collection, finding any instance having the same roomID as that being referenced and having a value of pending for the status field [403].
  • Sets that/those instance(s) to have a status of accepted if action is set to accept else, status will have a value of rejected.
  • Updates and saves the room with the record in the members field referenced by the uid passed to have a status of accepted if action is set to accept else, removes the record.
  • Generates a messageID and timestamp corresponding to the current date and time if action is set to accept.
  • 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 if action is set to accept.