Link Search Menu Expand Document

Edit

/api/v2/message/edit

Post

rooms

jwt


Purpose

To allow a user to edit a sent message in a chat room that he/she is a member of.

Body Content [input]

{
    uid: string,
    roomID: string,
    messageID: string,
    message: string,
    is_thread: bool
}

Returns if valid [output]

{
    message: string,
    error: 0
}

What the API does

  • Finds the record from the rooms collection corresponding to the roomID passed [404].
  • Ensures that uid corresponds to a record in the members field of that record with a status of accepted [403].
  • If is_thread has a value of false, find the message being referenced in the messages field having the same value of messageID as that passed, else if is_thread has a value of true find that being referenced from the threads field [404].
  • Checks that the senderID field of the found message has the same value as that of the uid passed [403].
  • Generates a timestamp for the current date and time.
  • If is_thread has a value of false, updates the object in the messages field of the room corresponding to messageID, with the updated value for message and uses the value of the generated timestamp for the value of the modified_on field.
  • Else if is_thread has a value of true, updates the object in the threads field of the room corresponding to messageID, with the updated value for message and uses the value of the generated timestamp for the value of the modified_on field.