Can get friendship status

This commit is contained in:
Pierre
2017-12-20 18:53:00 +01:00
parent 558f7dc59f
commit 583ef8fc2d
2 changed files with 72 additions and 6 deletions

View File

@ -61,12 +61,12 @@ class friendsController{
*
* @url POST /friends/remove
*/
public function delete(){
user_login_required(); //Login required
public function delete(){
user_login_required(); //Login required
//Check input parametres
if(!isset($_POST['friendID']))
Rest_fatal_error(400, "Please specify the ID of the friend to delete !");
//Check input parametres
if(!isset($_POST['friendID']))
Rest_fatal_error(400, "Please specify the ID of the friend to delete !");
//Delete the friend from the list
$friendID = toInt($_POST['friendID']);
@ -77,6 +77,50 @@ class friendsController{
Rest_fatal_error(500, "Couldn't remove user from the friendlist for an unexcepted reason !");
else
return array("success" => "The friend was removed from the list !");
}
}
/**
* Get the status of a friendship
*
* Check if the users are friends, or this there is a pending request...
*
* @url POST /friends/getStatus
*/
public function getStatus(){
user_login_required(); //Login required
//Check if the a friendID has been specified
if(!isset($_POST['friendID']))
Rest_fatal_error(400, "Please specify a friend ID !");
//Get it
$friendID = toInt($_POST['friendID']);
//Prepare the response
$response = array(
"are_friend" => false,
"sent_request" => false,
"received_request" => false,
);
//Check if the two personns are friend
$response['are_friend'] =
CS::get()->components->friends->are_friend(userID, $friendID);
//Perform next check only if the personns are not already friend
if(!$response['are_friend']){
//Check if the current user has sent a request to the other user
if(CS::get()->components->friends->sent_request(userID, $friendID))
$response["sent_request"] = true;
//Check if the current user has received a friendship request
if(CS::get()->components->friends->sent_request($friendID, userID))
$response["received_request"] = true;
}
//Return the response
return $response;
}
}