mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-23 20:18:57 +00:00
Users are marked as "read" when their browser download last messages
This commit is contained in:
parent
46985a77f9
commit
a82b65f18d
@ -306,6 +306,9 @@ class conversationsController{
|
||||
|
||||
//Then we can get the ten last messages of the conversation system
|
||||
$conversationsMessages["conversation-".$conversationID] = CS::get()->components->conversations->getLastMessages($conversationID, 10);
|
||||
|
||||
//Specify that user has seen last messages
|
||||
CS::get()->components->conversations->markUserAsRead(userID, $conversationID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,11 +332,11 @@ class conversationsController{
|
||||
|
||||
//Check if conversation number is valid
|
||||
if($conversationID < 1)
|
||||
Rest_fatal_error(401, "An error occured while trying to extract given conversation ID to refresh :".$conversationID);
|
||||
Rest_fatal_error(401, "An error occured while trying to extract given conversation ID to refresh: ".$conversationID);
|
||||
|
||||
//Check if informations where given about the limit of the informations to get
|
||||
if(!isset($informations["last_message_id"]))
|
||||
Rest_fatal_error(401, "Conversation ".$conversationID." couldn't be refreshed: not enough informations");
|
||||
Rest_fatal_error(401, "Conversation ".$conversationID." couldn't be refreshed: not enough informations !");
|
||||
$last_message_id = toInt($informations["last_message_id"]);
|
||||
|
||||
//Check if the user belongs to the conversation
|
||||
@ -342,6 +345,9 @@ class conversationsController{
|
||||
|
||||
//Then we can get informations about the conversation
|
||||
$conversationsMessages["conversation-".$conversationID] = CS::get()->components->conversations->getNewMessages($conversationID, $last_message_id);
|
||||
|
||||
//Specify that user has seen last messages
|
||||
CS::get()->components->conversations->markUserAsRead(userID, $conversationID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -509,6 +509,36 @@ class conversations {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the user of a conversation as "read" for a conversation
|
||||
*
|
||||
* @param Integer $userID The ID of the user to update
|
||||
* @param Integer $conversationID The ID of a conversation to update
|
||||
* @return Boolean True for a success
|
||||
*/
|
||||
public function markUserAsRead($userID, $conversationID) : bool {
|
||||
|
||||
//Prepare database request
|
||||
$tableName = $this->conversationsUsersTable;
|
||||
$conditions = "ID_".$this->conversationsListTable." = ? AND ID_utilisateurs = ?";
|
||||
$condVals = array(
|
||||
$conversationID,
|
||||
$userID
|
||||
);
|
||||
|
||||
//Define new values
|
||||
$newValues = array(
|
||||
"saw_last_message" => 1
|
||||
);
|
||||
|
||||
//Try to perform a request on the database
|
||||
if(!CS::get()->db->updateDB($tableName, $conditions, $newValues, $condVals))
|
||||
return false; //An error occured
|
||||
|
||||
//Success
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new message
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user