mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
A user can delete his membership from a conversation
This commit is contained in:
parent
9044501f8b
commit
e95f6cfb98
@ -34,12 +34,8 @@ class conversationsController{
|
|||||||
public function getOneInformations(){
|
public function getOneInformations(){
|
||||||
user_login_required();
|
user_login_required();
|
||||||
|
|
||||||
//First, check the parametres
|
//Get conversation ID
|
||||||
if(!isset($_POST['conversationID']))
|
$conversationID = getPostConversationID("conversationID");
|
||||||
Rest_fatal_error(501, "No conversation ID specified with the request");
|
|
||||||
|
|
||||||
//Extract data
|
|
||||||
$conversationID = toInt($_POST['conversationID']);
|
|
||||||
|
|
||||||
//Try to get informations about the conversation
|
//Try to get informations about the conversation
|
||||||
$conversationsList = CS::get()->components->conversations->getList(userID, $conversationID);
|
$conversationsList = CS::get()->components->conversations->getList(userID, $conversationID);
|
||||||
@ -412,7 +408,9 @@ class conversationsController{
|
|||||||
Rest_fatal_error(500, "Couldn't delete the conversation from the server !");
|
Rest_fatal_error(500, "Couldn't delete the conversation from the server !");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Rest_fatal_error(500, "Not implemented yet !!");
|
//Delete the membership to the conversation
|
||||||
|
if(!CS::get()->components->conversations->delete_member($conversationID, userID))
|
||||||
|
Rest_fatal_error(500, "Couldn't delete conversation membership !");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -635,6 +635,8 @@ class conversations {
|
|||||||
/**
|
/**
|
||||||
* Delete a conversation
|
* Delete a conversation
|
||||||
*
|
*
|
||||||
|
* Delete all the messages, membership and informations about a conversation
|
||||||
|
*
|
||||||
* @param int $conID The conversation to delete
|
* @param int $conID The conversation to delete
|
||||||
* @return bool True in case of success / False else
|
* @return bool True in case of success / False else
|
||||||
*/
|
*/
|
||||||
@ -661,6 +663,39 @@ class conversations {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a conversation membership
|
||||||
|
*
|
||||||
|
* This function is just removing a user from a conversation by
|
||||||
|
* deleting all the messages the user has posted and removing its
|
||||||
|
* membership
|
||||||
|
*
|
||||||
|
* @param int $convID The target conversation
|
||||||
|
* @param int $memberID The ID of the member to delete from the conversation
|
||||||
|
* @return bool True in case of success / false else
|
||||||
|
*/
|
||||||
|
public function delete_member(int $convID, int $memberID) : bool {
|
||||||
|
|
||||||
|
//Get all the messages of member the conversation
|
||||||
|
$messages = $this->getMessages(
|
||||||
|
"WHERE ID_".$this->conversationsListTable." = ? AND ID_utilisateurs = ?",
|
||||||
|
array($convID, $memberID));
|
||||||
|
|
||||||
|
//Delete each message
|
||||||
|
foreach($messages as $message){
|
||||||
|
if(!$this->delete_message($message['ID'], $convID))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Delete user membership
|
||||||
|
if(!$this->removeMember($convID, $memberID))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//Success
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a single message of a conversation
|
* Delete a single message of a conversation
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user