mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 04:58:59 +00:00
Can update the content of a conversation message
This commit is contained in:
parent
2749dbcb3f
commit
9df1c93a24
@ -480,6 +480,34 @@ class ConversationsController {
|
||||
return array("success" => "The conversation has been deleted");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the content of a conversation message
|
||||
*
|
||||
* @url POST /conversations/updateMessage
|
||||
*/
|
||||
public function updateMessage(){
|
||||
user_login_required();
|
||||
|
||||
$messageID = postInt("messageID");
|
||||
$newContent = postString("content");
|
||||
|
||||
if(!check_string_before_insert($newContent))
|
||||
Rest_fatal_error(401, "Invalid new message content!");
|
||||
|
||||
//Check whether the user own or not conversation message
|
||||
if(!components()->conversations->isOwnerMessage(userID, $messageID))
|
||||
Rest_fatal_error(401, "You do not own this conversation message!");
|
||||
|
||||
//Update the message
|
||||
$message = new ConversationMessage();
|
||||
$message->set_id($messageID);
|
||||
$message->set_message($newContent);
|
||||
if(!components()->conversations->updateMessage($message))
|
||||
Rest_fatal_error(500, "Could not update the content of the message!");
|
||||
|
||||
return array("success" => "The conversation message has been successfully updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a conversation message
|
||||
*
|
||||
|
@ -552,6 +552,24 @@ class Conversations {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a message
|
||||
*
|
||||
* @param ConversationMessage $message Information about the message to update
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function updateMessage(ConversationMessage $message) : bool {
|
||||
|
||||
$modifs = array();
|
||||
|
||||
//Check if the content of message has to be updated
|
||||
if($message->has_message())
|
||||
$modifs["message"] = $message->get_message();
|
||||
|
||||
//Peform update
|
||||
return db()->updateDB(self::MESSAGES_TABLE, "id = ?", $modifs, array($message->get_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last messages of a conversation
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user