mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Follow state of a conversation can be updated
This commit is contained in:
parent
b1e340e0c1
commit
952779f527
@ -12,7 +12,7 @@ class conversationsController{
|
||||
*
|
||||
* @url POST /conversations/getList
|
||||
*/
|
||||
public function getConversationsList(){
|
||||
public function getList(){
|
||||
user_login_required();
|
||||
|
||||
//Try to get the list
|
||||
@ -31,7 +31,7 @@ class conversationsController{
|
||||
*
|
||||
* @url POST /conversations/getInfosOne
|
||||
*/
|
||||
public function getOneConversationInformations(){
|
||||
public function getOneInformations(){
|
||||
user_login_required();
|
||||
|
||||
//First, check the parametres
|
||||
@ -62,7 +62,7 @@ class conversationsController{
|
||||
*
|
||||
* @url POST /conversations/create
|
||||
*/
|
||||
public function createConversation(){
|
||||
public function create(){
|
||||
user_login_required();
|
||||
|
||||
//Check for parametres
|
||||
@ -96,4 +96,34 @@ class conversationsController{
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a conversation settings
|
||||
*
|
||||
* @url POST /conversations/updateSettings
|
||||
*/
|
||||
public function updateSettings(){
|
||||
user_login_required();
|
||||
|
||||
//Check conversation ID was specified
|
||||
if(!isset($_POST["conversationID"]))
|
||||
Rest_fatal_error("501", "Please specify a conversation ID !");
|
||||
$conversationID = toInt($_POST["conversationID"]);
|
||||
|
||||
//Check if the user is a conversation moderator or not
|
||||
if(!CS::get()->components->conversations->userBelongsTo(userID, $conversationID))
|
||||
Rest_fatal_error("401", "Specified user doesn't belongs to the conversation !");
|
||||
|
||||
//Check if user want to update its follow state
|
||||
if(isset($_POST['following'])){
|
||||
$follow = $_POST["following"] === "true" ? true : false;
|
||||
|
||||
//Try to update follow state
|
||||
if(!CS::get()->components->conversations->changeFollowState(userID, $conversationID, $follow))
|
||||
Rest_fatal_error(500, "Couldn't update user follow state !");
|
||||
}
|
||||
|
||||
|
||||
//Success
|
||||
return array("success" => "User informations were successfully updated !");
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ class friendsController{
|
||||
Rest_fatal_error(501, "Please check your parametres !");
|
||||
|
||||
//Extract informations and process request
|
||||
$friendID = $_POST['friendID']*1;
|
||||
$friendID = toInt($_POST['friendID']);
|
||||
$acceptRequest = $_POST['accept'] == "true";
|
||||
|
||||
//Try to perform request
|
||||
|
@ -21,7 +21,7 @@ class searchController
|
||||
Rest_fatal_error(400, "Please specify search terms");
|
||||
|
||||
//Check for search limit
|
||||
$searchLimit = (isset($_POST['searchLimit']) ? $_POST['searchLimit']*1 : 5);
|
||||
$searchLimit = (isset($_POST['searchLimit']) ? toInt($_POST['searchLimit']) : 5);
|
||||
|
||||
//Check the limit
|
||||
if($searchLimit < 1 || $searchLimit > 25)
|
||||
|
@ -72,18 +72,14 @@ class userController
|
||||
|
||||
//Determine userID
|
||||
if(isset($_POST['userID'])){
|
||||
$usersID = array($_POST['userID']*1);
|
||||
$usersID = array(toInt($_POST['userID']));
|
||||
}
|
||||
elseif(isset($_POST['usersID'])){
|
||||
//Generate users ID list
|
||||
$usersID = array();
|
||||
foreach(explode(",", $_POST['usersID']) as $userID){
|
||||
if($userID*1 > 0)
|
||||
$usersID[$userID*1] = $userID*1;
|
||||
}
|
||||
$usersID = users_list_to_array($_POST['usersID']);
|
||||
|
||||
//Check for errors
|
||||
if(count($userID) == 0)
|
||||
if(count($usersID) == 0)
|
||||
Rest_fatal_error(400, "No user ID were specified!");
|
||||
}
|
||||
else
|
||||
|
@ -207,6 +207,45 @@ class conversations {
|
||||
return $result != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the follow state of a user on conversation
|
||||
*
|
||||
* @param Integer $userID The ID to update
|
||||
* @param Integer $conversationID The ID of the conversation
|
||||
* @param Boolean $follow Specify if the conversation is followed or not
|
||||
* @return Boolean True for a success
|
||||
*/
|
||||
public function changeFollowState($userID, $conversationID, $follow){
|
||||
|
||||
//Prepare the request on the database
|
||||
$tableName = $this->conversationsUsersTable;
|
||||
$conditions = "ID_".$this->conversationsListTable." = ? AND ID_utilisateurs = ?";
|
||||
$condVals = array(
|
||||
$conversationID,
|
||||
$userID
|
||||
);
|
||||
|
||||
//Defines modifications
|
||||
$modifs = array(
|
||||
"following" => $follow ? 1 : 0,
|
||||
);
|
||||
|
||||
//Update the table
|
||||
if(!CS::get()->db->updateDB($tableName, $conditions, $modifs, $condVals))
|
||||
return false; //An error occured
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a user is a conversation moderator or not
|
||||
*
|
||||
* @param Integer $userID The ID of the user to check
|
||||
* @param Integer $conversationID The ID of the conversation to check
|
||||
* @return Boolean True if the user is a conversation moderator or not
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
//Register component
|
||||
|
@ -45,7 +45,8 @@ function users_list_to_array($list) : array{
|
||||
|
||||
//Check the entry is valid
|
||||
if(toInt($process) < 1)
|
||||
return array();
|
||||
//return array();
|
||||
continue; //Ignore entry
|
||||
|
||||
//Add the entry to the list
|
||||
$usersList[toInt($process)] = toInt($process);
|
||||
|
@ -24,8 +24,11 @@ require PROJECT_PATH."3rdparty/RestServer/RestServer.php";
|
||||
if(!isset($_GET["format"]))
|
||||
$_GET['format'] = "json";
|
||||
|
||||
//Specify we are on Comunic API Server
|
||||
header("Technology: Official Comunic API Server");
|
||||
|
||||
//Set debug clients tokens
|
||||
if($cs->config->get("site_mode") == "debug"){ //DEBUG ONLY
|
||||
if($cs->config->get("site_mode") === "debug"){ //DEBUG ONLY
|
||||
$_POST['serviceName'] = "testService";
|
||||
$_POST['serviceToken'] = "testPasswd";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user