mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +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
|
//Then we can get the ten last messages of the conversation system
|
||||||
$conversationsMessages["conversation-".$conversationID] = CS::get()->components->conversations->getLastMessages($conversationID, 10);
|
$conversationsMessages["conversation-".$conversationID] = CS::get()->components->conversations->getLastMessages($conversationID, 10);
|
||||||
|
|
||||||
|
//Specify that user has seen last messages
|
||||||
|
CS::get()->components->conversations->markUserAsRead(userID, $conversationID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +336,7 @@ class conversationsController{
|
|||||||
|
|
||||||
//Check if informations where given about the limit of the informations to get
|
//Check if informations where given about the limit of the informations to get
|
||||||
if(!isset($informations["last_message_id"]))
|
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"]);
|
$last_message_id = toInt($informations["last_message_id"]);
|
||||||
|
|
||||||
//Check if the user belongs to the conversation
|
//Check if the user belongs to the conversation
|
||||||
@ -342,6 +345,9 @@ class conversationsController{
|
|||||||
|
|
||||||
//Then we can get informations about the conversation
|
//Then we can get informations about the conversation
|
||||||
$conversationsMessages["conversation-".$conversationID] = CS::get()->components->conversations->getNewMessages($conversationID, $last_message_id);
|
$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;
|
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
|
* Send a new message
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user