mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-23 21:50:09 +00:00
c2fe53fdb0
The „global“ room can be activated on a user group basis. This allows for bots processing messages from all rooms and responding to them.
101 lines
3.1 KiB
PHP
101 lines
3.1 KiB
PHP
<?php
|
|
namespace chat\data\message;
|
|
|
|
/**
|
|
* Represents a list of chat messages.
|
|
*
|
|
* @author Tim Düsterhus
|
|
* @copyright 2010-2014 Tim Düsterhus
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
|
* @package be.bastelstu.chat
|
|
* @subpackage chat.room
|
|
*/
|
|
class MessageList extends \wcf\data\DatabaseObjectList {
|
|
/**
|
|
* @see \wcf\data\DatabaseObjectList::$className
|
|
*/
|
|
public $className = 'chat\data\message\Message';
|
|
|
|
/**
|
|
* Reads the newest messages for the given room.
|
|
*
|
|
* @param \chat\data\room\Room $room
|
|
* @param integer $number
|
|
* @return array<\chat\data\message\Message>
|
|
*/
|
|
public static function getNewestMessages(\chat\data\room\Room $room, $number = CHAT_LASTMESSAGES) {
|
|
if ($number === 0) return array();
|
|
|
|
$messageList = new static();
|
|
$messageList->sqlOrderBy = "message.messageID DESC";
|
|
$messageList->sqlLimit = $number;
|
|
$messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
|
|
|
|
if ($room->roomID !== \chat\data\room\Room::GLOBAL_ROOM) {
|
|
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
|
|
}
|
|
|
|
$messageList->readObjects();
|
|
return array_reverse($messageList->getObjects());
|
|
}
|
|
|
|
/**
|
|
* Reads the messages since the given message-id for the given room.
|
|
*
|
|
* @param \chat\data\room\Room $room
|
|
* @param integer $since
|
|
* @return array<\chat\data\message\Message>
|
|
*/
|
|
public static function getMessagesSince(\chat\data\room\Room $room, $since) {
|
|
$messageList = new static();
|
|
$messageList->sqlOrderBy = "message.messageID ASC";
|
|
$messageList->getConditionBuilder()->add('message.messageID > ?', array($since));
|
|
|
|
if ($room->roomID !== \chat\data\room\Room::GLOBAL_ROOM) {
|
|
$messageList->getConditionBuilder()->add('
|
|
((
|
|
message.receiver IS NULL
|
|
AND message.roomID = ?
|
|
)
|
|
OR message.receiver = ?
|
|
OR message.sender = ?)',
|
|
array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
|
|
);
|
|
}
|
|
else {
|
|
$messageList->getConditionBuilder()->add('
|
|
(message.receiver IS NULL
|
|
OR message.receiver = ?
|
|
OR message.sender = ?)',
|
|
array(\wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
|
|
);
|
|
}
|
|
|
|
$messageList->readObjects();
|
|
return $messageList->getObjects();
|
|
}
|
|
|
|
/**
|
|
* Reads the message between the given timestamps for the given room.
|
|
*
|
|
* @param \chat\data\room\Room $room
|
|
* @param integer $start
|
|
* @param integer $end
|
|
* @return array<\chat\data\message\Message>
|
|
*/
|
|
public static function getMessagesBetween(\chat\data\room\Room $room, $start, $end) {
|
|
$messageList = new static();
|
|
$messageList->sqlOrderBy = "message.messageID ASC";
|
|
$messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
|
|
|
|
if ($room->roomID !== \chat\data\room\Room::GLOBAL_ROOM) {
|
|
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
|
|
}
|
|
|
|
$messageList->getConditionBuilder()->add('message.time BETWEEN ? AND ?', array($start, $end));
|
|
|
|
$messageList->readObjects();
|
|
return $messageList->getObjects();
|
|
}
|
|
}
|