Can update the content of a conversation message

This commit is contained in:
Pierre HUBERT 2018-08-29 13:36:27 +02:00
parent 2749dbcb3f
commit 9df1c93a24
2 changed files with 46 additions and 0 deletions

View File

@ -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
*

View File

@ -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
*