2011-12-04 21:46:50 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\data\chat\message;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a list of chat messages.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2012-01-28 16:50:33 +00:00
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
2011-12-04 21:46:50 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
|
|
|
* @package timwolla.wcf.chat
|
|
|
|
* @subpackage data.chat.room
|
|
|
|
*/
|
|
|
|
class ChatMessageList extends \wcf\data\DatabaseObjectList {
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\DatabaseObjectList::$className
|
2011-12-04 21:46:50 +00:00
|
|
|
*/
|
|
|
|
public $className = 'wcf\data\chat\message\ChatMessage';
|
|
|
|
|
2011-12-26 15:31:37 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
2011-12-04 21:46:50 +00:00
|
|
|
$messageList = new static();
|
|
|
|
$messageList->sqlOrderBy = "chat_message.messageID DESC";
|
|
|
|
$messageList->sqlLimit = $number;
|
2011-12-26 15:31:37 +00:00
|
|
|
$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));
|
|
|
|
|
2011-12-04 21:46:50 +00:00
|
|
|
$messageList->readObjects();
|
|
|
|
return array_reverse($messageList->getObjects());
|
|
|
|
}
|
2011-12-26 15:31:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
2011-12-04 21:46:50 +00:00
|
|
|
}
|