Accept conversation messages with images

This commit is contained in:
Pierre
2017-06-24 14:30:16 +02:00
parent 898cbc2e41
commit 612050a1bc
3 changed files with 195 additions and 5 deletions

View File

@ -423,9 +423,10 @@ class conversations {
* @param Integer $userID The ID of the user inserting the message
* @param Integer $conversationID The ID of the target conversation
* @param String $message The message to insert
* @param Mixed $image_path Optionnal, the path to an image associated with the message
* @return Boolean True for a success
*/
private function insertMessage($userID, $conversationID, $message){
private function insertMessage($userID, $conversationID, $message, $image_path = false){
//Prepare values
$tableName = $this->conversationMessagesTable;
@ -436,6 +437,10 @@ class conversations {
"message" => $message
);
//Add image path (if required)
if($image_path)
$values['image_path'] = $image_path;
//Try to insert new value in database
if(!CS::get()->db->addLine($tableName, $values))
return false; //An error occured
@ -510,15 +515,16 @@ class conversations {
* @param Integer $userID The ID of the user sending the message
* @param Integer $conversationID The ID of the target conversation
* @param String $message The message
* @param Mixed $image_path Optionna, define the path to an image associated with the message
* @return Boolean True for a success
*/
public function sendMessage($userID, $conversationID, $message){
public function sendMessage($userID, $conversationID, $message, $image_path = false){
//GUIDE LINE : this method act like a "controller" : it doesn't perform any database operation
//But it manage all operations (insert message; save image; inform other users; ...)
//First, try to insert the message
if(!$this->insertMessage($userID, $conversationID, $message))
if(!$this->insertMessage($userID, $conversationID, $message, $image_path))
return false; //An error occured
//Then, update the last activity of the conversation