mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Upgraded conversations creation
This commit is contained in:
parent
4ca3314236
commit
2a24d63a5c
@ -71,20 +71,26 @@ class conversationsController{
|
|||||||
Rest_fatal_error(400, "Please check parametres passed with the request !");
|
Rest_fatal_error(400, "Please check parametres passed with the request !");
|
||||||
|
|
||||||
//Extract parametres
|
//Extract parametres
|
||||||
$conversationName = ($_POST["name"] == "false" ? false : $_POST['name']);
|
$conv = new ConversationInfo();
|
||||||
$followConversation = ($_POST['follow'] == "true" ? true : false);
|
$conv->set_id_owner(userID);
|
||||||
$usersList = numbers_list_to_array($_POST['users']);
|
$conv->set_name($_POST["name"] == "false" ? false : removeHTMLnodes($_POST['name']));
|
||||||
|
$conv->set_following($_POST['follow'] == "true" ? true : false);
|
||||||
|
|
||||||
|
//Process the list of users
|
||||||
|
$membersList = numbers_list_to_array($_POST['users']);
|
||||||
|
|
||||||
//Add current user (if not present)
|
//Add current user (if not present)
|
||||||
if(!isset($usersList[userID]))
|
if(!isset($membersList[userID]))
|
||||||
$usersList[userID] = userID;
|
$membersList[userID] = userID;
|
||||||
|
|
||||||
//Check users
|
//Check users
|
||||||
if(count($usersList) < 1)
|
if(count($membersList) < 1)
|
||||||
Rest_fatal_error(501, "Please select at least one user !");
|
Rest_fatal_error(501, "Please select at least one user !");
|
||||||
|
|
||||||
|
$conv->set_members($membersList);
|
||||||
|
|
||||||
//Try to create the conversation
|
//Try to create the conversation
|
||||||
$conversationID = CS::get()->components->conversations->create(userID, $followConversation, $usersList, $conversationName);
|
$conversationID = CS::get()->components->conversations->create($conv);
|
||||||
|
|
||||||
//Check for errors
|
//Check for errors
|
||||||
if($conversationID == 0)
|
if($conversationID == 0)
|
||||||
|
@ -125,17 +125,14 @@ class conversations {
|
|||||||
/**
|
/**
|
||||||
* Create a new conversation
|
* Create a new conversation
|
||||||
*
|
*
|
||||||
* @param int $userID The ID of the user creating the conversation
|
* @param ConversationInfo $conv Information about the conversation to create
|
||||||
* @param bool $follow Defines if the user creating the conversation will follow it
|
|
||||||
* @param array $usersList The list of users following the conversation
|
|
||||||
* @param Mixed $name Optionnal, the name of the conversation
|
|
||||||
* @return int 0 for a fail else the ID of the newly created conversation
|
* @return int 0 for a fail else the ID of the newly created conversation
|
||||||
*/
|
*/
|
||||||
public function create(int $userID, bool $follow, array $usersList, $name = "") : int{
|
public function create(ConversationInfo $conv) : int{
|
||||||
|
|
||||||
$mainInformations = array(
|
$mainInformations = array(
|
||||||
"ID_utilisateurs" => $userID*1,
|
"ID_utilisateurs" => $conv->get_id_owner(),
|
||||||
"name" => ($name ? $name : ""),
|
"name" => ($conv->has_name() ? $conv->get_name() : ""),
|
||||||
"last_active" => time(),
|
"last_active" => time(),
|
||||||
"creation_time" => time()
|
"creation_time" => time()
|
||||||
);
|
);
|
||||||
@ -152,12 +149,12 @@ class conversations {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
//Insert users registrattions
|
//Insert users registrattions
|
||||||
foreach($usersList as $processUser){
|
foreach($conv->get_members() as $processUser){
|
||||||
|
|
||||||
//Make user follow the conversation if required
|
//Make user follow the conversation if required
|
||||||
$processUserFollowing = false;
|
$processUserFollowing = true;
|
||||||
if($userID == $processUser)
|
if($conv->get_id_owner() == $processUser)
|
||||||
$processUserFollowing = $follow;
|
$processUserFollowing = $conv->is_following();
|
||||||
|
|
||||||
//Try to insert user in conversation
|
//Try to insert user in conversation
|
||||||
if(!$this->addMember($conversationID, $processUser, $processUserFollowing))
|
if(!$this->addMember($conversationID, $processUser, $processUserFollowing))
|
||||||
|
Loading…
Reference in New Issue
Block a user