diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index 53abe99..dfd625d 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -96,13 +96,14 @@ public function getUsername() { public function jsonify() { return \wcf\util\JSON::encode(array( 'formattedUsername' => $this->getFormattedUsername(), - 'formattedMessage' => $this->getFormattedMessage(), + 'formattedMessage' => (string) $this, 'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'), 'sender' => $this->sender, 'username' => $this->getUsername(), 'time' => $this->time, 'receiver' => $this->receiver, - 'type' => $this->type + 'type' => $this->type, + 'roomID' => $this->roomID )); } } diff --git a/file/lib/data/chat/message/ChatMessageList.class.php b/file/lib/data/chat/message/ChatMessageList.class.php index 43891d4..10f474f 100644 --- a/file/lib/data/chat/message/ChatMessageList.class.php +++ b/file/lib/data/chat/message/ChatMessageList.class.php @@ -16,12 +16,49 @@ class ChatMessageList extends \wcf\data\DatabaseObjectList { */ public $className = 'wcf\data\chat\message\ChatMessage'; - public static function getNewestMessages(\wcf\data\chat\room\ChatRoom $room, $number) { + /** + * Reads the newest messages for the given room. + * + * @param \wcf\data\chat\room\ChatRoom $room + * @param integer $number + * @return array<\wcf\data\chat\message\ChatMessage> + */ + public static function getNewestMessages(\wcf\data\chat\room\ChatRoom $room, $number = CHAT_LASTMESSAGES) { $messageList = new static(); $messageList->sqlOrderBy = "chat_message.messageID DESC"; $messageList->sqlLimit = $number; - $messageList->getConditionBuilder()->add('chat_message.roomID = ?', array($room->roomID)); + $messageList->getConditionBuilder()->add(' + (( + chat_message.receiver IS NULL + AND chat_message.roomID = ? + ) + OR chat_message.receiver = ? + OR chat_message.sender = ?)', array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)); + $messageList->readObjects(); return array_reverse($messageList->getObjects()); } + + /** + * Reads the messages since the given message-id for the given room. + * + * @param \wcf\data\chat\room\ChatRoom $room + * @param integer $since + * @return array<\wcf\data\chat\message\ChatMessage> + */ + public static function getMessagesSince(\wcf\data\chat\room\ChatRoom $room, $since) { + $messageList = new static(); + $messageList->sqlOrderBy = "chat_message.messageID ASC"; + $messageList->getConditionBuilder()->add('chat_message.messageID > ?', array($since)); + $messageList->getConditionBuilder()->add(' + (( + chat_message.receiver IS NULL + AND chat_message.roomID = ? + ) + OR chat_message.receiver = ? + OR chat_message.sender = ?)', array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)); + + $messageList->readObjects(); + return $messageList->getObjects(); + } } diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index b123c09..db8c11c 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -81,6 +81,9 @@ public function readData() { ) )); $messageAction->executeAction(); + $return = $messageAction->getReturnValues(); + + \wcf\util\ChatUtil::writeUserData(array('lastSeen' => $return['returnValues'] -> messageID)); } $this->readDefaultSmileys();