Implement ConversationInfo object parsing

This commit is contained in:
Pierre
2018-04-23 18:59:07 +02:00
parent 3dd0d3792a
commit 4ca3314236
2 changed files with 54 additions and 14 deletions

View File

@ -83,18 +83,8 @@ class conversations {
//Process results
$conversationsList = array();
foreach($results as $processConversation){
$conversationsList[] = array(
"ID" => $processConversation["ID"],
"ID_owner" => $processConversation["ID_owner"],
"last_active" => $processConversation["last_active"],
"name" => ($processConversation["name"] == "" ? false : $processConversation["name"]),
"following" => $processConversation["following"],
"saw_last_message" => $processConversation["saw_last_message"],
//Get and add conversation members
"members" => $this->getConversationMembers($processConversation["ID"]),
);
foreach($results as $entry){
$conversationsList[] = $this->dbToConvInfo($entry);
}
//Return results
@ -861,6 +851,29 @@ class conversations {
return $messages;
}
/**
* Turn a conversation database entry into a ConversationInfo object
*
* @param array $entry Conversation entry in the database
* @return ConversationInfo Generated conversation information object
*/
private function dbToConvInfo(array $entry) : ConversationInfo {
$conv = new ConversationInfo();
$conv->set_id($entry["ID"]);
$conv->set_id_owner($entry["ID_owner"]);
$conv->set_last_active($entry["last_active"]);
if($entry["name"] != null)
$conv->set_name($entry["name"]);
$conv->set_following($entry["following"] == 1);
$conv->set_saw_last_message($entry["saw_last_message"] == 1);
$conv->set_members($this->getConversationMembers($entry["ID"]));
return $conv;
}
}
//Register component