mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Can delete a conversation message
This commit is contained in:
parent
9a4048af4b
commit
382f816ad8
@ -480,6 +480,27 @@ class ConversationsController {
|
|||||||
return array("success" => "The conversation has been deleted");
|
return array("success" => "The conversation has been deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a conversation message
|
||||||
|
*
|
||||||
|
* @url POST /conversations/deleteMessage
|
||||||
|
*/
|
||||||
|
public function deleteMessage(){
|
||||||
|
|
||||||
|
user_login_required();
|
||||||
|
|
||||||
|
$messageID = postInt("messageID");
|
||||||
|
|
||||||
|
//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!");
|
||||||
|
|
||||||
|
if(!components()->conversations->deleteConversationMessage($messageID))
|
||||||
|
Rest_fatal_error(500, "Could not delete conversation message!");
|
||||||
|
|
||||||
|
return array("success" => "Conversation message has been successfully deleted!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get and return safely a conversation ID specified in a $_POST Request
|
* Get and return safely a conversation ID specified in a $_POST Request
|
||||||
*
|
*
|
||||||
|
@ -359,6 +359,23 @@ class Conversations {
|
|||||||
return $results[0]["ID_utilisateurs"] == $userID;
|
return $results[0]["ID_utilisateurs"] == $userID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a user is the owner of a conversation message or not
|
||||||
|
*
|
||||||
|
* @param int $userID Target user ID
|
||||||
|
* @param int $messageID Target message
|
||||||
|
* @return bool TRUE if the user is the owner of the conversation / FALSE else
|
||||||
|
*/
|
||||||
|
public function isOwnerMessage(int $userID, int $messageID) : bool {
|
||||||
|
|
||||||
|
return db()->count(
|
||||||
|
$this->conversationsMessagesTable,
|
||||||
|
"WHERE ID = ? AND ID_utilisateurs = ?",
|
||||||
|
array($messageID, $userID)
|
||||||
|
) > 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for a private conversation between two users
|
* Search for a private conversation between two users
|
||||||
*
|
*
|
||||||
@ -750,6 +767,22 @@ class Conversations {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a single conversation message
|
||||||
|
*
|
||||||
|
* @param int $messageID The ID of the message to delete
|
||||||
|
* @return bool TRUE for a success / FALSE else
|
||||||
|
*/
|
||||||
|
public function deleteConversationMessage(int $messageID) : bool {
|
||||||
|
|
||||||
|
//Get information about the message
|
||||||
|
$messages = $this->getMessages("WHERE ID = ?", array($messageID));
|
||||||
|
|
||||||
|
if(count($messages) < 1)
|
||||||
|
return FALSE; //Message not found
|
||||||
|
|
||||||
|
return $this->delete_message($messages[0]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a single message of a conversation
|
* Delete a single message of a conversation
|
||||||
|
Loading…
Reference in New Issue
Block a user