forked from La_Bureautique/zeg1jeux
91 lines
1.3 KiB
PHP
91 lines
1.3 KiB
PHP
<?php
|
|
|
|
require_once('Message.class.php');
|
|
|
|
function compareMsgDate ($msg1, $msg2) {
|
|
|
|
return ($msg1->getDate() < $msg2->getDate()) ? -1 : 1;
|
|
}
|
|
|
|
class Conversation {
|
|
|
|
private $messages = [];
|
|
|
|
private $firstMessage;
|
|
|
|
private $lastMessage;
|
|
|
|
private $convTitle;
|
|
|
|
private $penpalPubkey;
|
|
|
|
|
|
|
|
public function __construct () {
|
|
|
|
}
|
|
|
|
public function addMessage ($msg) {
|
|
|
|
$this->messages[] = $msg;
|
|
|
|
if (!isset($this->lastMessage, $this->firstMessage)) {
|
|
|
|
$this->lastMessage = $msg;
|
|
$this->firstMessage = $msg;
|
|
|
|
} else {
|
|
|
|
if ($msg->getDate() > $this->lastMessage->getDate()) {
|
|
|
|
$this->lastMessage = $msg;
|
|
}
|
|
|
|
if ($msg->getDate() < $this->firstMessage->getDate()) {
|
|
|
|
$this->firstMessage = $msg;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function sortMessages () {
|
|
|
|
uasort($this->messages, 'compareMsgDate');
|
|
|
|
}
|
|
|
|
public function getConvTitle () {
|
|
|
|
if (!isset($this->convTitle)) {
|
|
|
|
$this->convTitle = $this->getFirstMessage()->getTitle();
|
|
}
|
|
|
|
return $this->convTitle;
|
|
}
|
|
|
|
public function getPenpalPubkey () {
|
|
|
|
if (!isset($this->penpalPubkey)) {
|
|
|
|
$this->penpalPubkey = $this->getFirstMessage()->getPenpalPubkey();
|
|
}
|
|
|
|
return $this->penpalPubkey;
|
|
}
|
|
|
|
public function getMessages () {
|
|
|
|
return $this->messages;
|
|
}
|
|
|
|
public function getFirstMessage () {
|
|
|
|
return $this->firstMessage;
|
|
}
|
|
|
|
public function getLastMessage () {
|
|
|
|
return $this->lastMessage;
|
|
}
|
|
} |