Can get the number of unread conversations of a user

This commit is contained in:
Pierre 2018-02-21 16:13:15 +01:00
parent 3a3c6d9787
commit 2f37d37a54
2 changed files with 34 additions and 0 deletions

View File

@ -386,6 +386,22 @@ class conversationsController{
}
/**
* Get the number of unread conversations of the user
*
* @url POST conversations/get_number_unread
*/
public function get_number_unread(){
user_login_required();
//Get the number of unread conversations of the user
$number_unread_conversations = components()->conversations->number_user_unread(userID);
//Return result
return array("nb_unread" => $number_unread_conversations);
}
/**
* Delete a conversation
*

View File

@ -766,6 +766,24 @@ class conversations {
return CS::get()->db->deleteEntry($this->conversationsListTable, "ID = ?", array($convID));
}
/**
* Get the number of unread conversations of a user
*
* @param int $userID Target user ID
* @return int The number of unread conversations of the user
*/
public function number_user_unread(int $userID) : int {
//Prepare database request
$tableName = $this->conversationsUsersTable;
$conditions = "WHERE ID_utilisateurs = ? AND saw_last_message = 0";
$values = array($userID);
//Perform request and return result
return CS::get()->db->count($tableName, $conditions, $values);
}
/**
* Get a list of conversation messages based on specified conditions
*