diff --git a/RestControllers/conversationsController.php b/RestControllers/conversationsController.php index 888d708..e65f95a 100644 --- a/RestControllers/conversationsController.php +++ b/RestControllers/conversationsController.php @@ -402,6 +402,22 @@ class conversationsController{ return array("nb_unread" => $number_unread_conversations); } + /** + * Get the list of unread notifications + * + * @url POST /conversations/get_list_unread + */ + public function get_list_unread(){ + + user_login_required(); + + //Get the list of unread conversations of the user + $list_unread_conversations = components()->conversations->get_list_unread(userID); + + //Return result + return $list_unread_conversations; + } + /** * Delete a conversation * diff --git a/classes/components/conversations.php b/classes/components/conversations.php index c922b00..86f2cb7 100644 --- a/classes/components/conversations.php +++ b/classes/components/conversations.php @@ -784,6 +784,42 @@ class conversations { } + /** + * Get the list of unread conversations of a user + * + * @param int $userID Target user ID + * @return array The list of unread conversations of the user + */ + public function get_list_unread(int $userID) : array { + + //Perform the request on the server + $tablesName = $this->conversationsUsersTable." as users, ".$this->conversationsListTable." as list, ".$this->conversationsMessagesTable." as messages"; + $conditions = "WHERE users.ID_utilisateurs = ? AND users.following = 1 AND users.saw_last_message = 0 AND users.ID_comunic_conversations_list = list.ID + AND list.ID = messages.ID_comunic_conversations_list AND list.last_active = messages.time_insert"; + $values = array($userID); + + //Perform the request + $results = CS::get()->db->select($tablesName, $conditions, $values); + + //Process the list of results + $list = array(); + foreach($results as $result){ + + //Generate the entry + $entry = array( + "id" => $result['ID_comunic_conversations_list'], + "conv_name" => $result["name"], + "last_active" => $result['last_active'], + "userID" => $result["ID_utilisateurs"], + "message" => $result["message"] + ); + + $list[] = $entry; + } + + return $list; + } + /** * Get a list of conversation messages based on specified conditions *