1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Improved Message-DBOs + Save last seen message in user_storage

This commit is contained in:
Tim Düsterhus 2011-12-26 16:31:37 +01:00
parent c83336c9fb
commit bdb7ec3b0d
3 changed files with 45 additions and 4 deletions

View File

@ -96,13 +96,14 @@ public function getUsername() {
public function jsonify() { public function jsonify() {
return \wcf\util\JSON::encode(array( return \wcf\util\JSON::encode(array(
'formattedUsername' => $this->getFormattedUsername(), 'formattedUsername' => $this->getFormattedUsername(),
'formattedMessage' => $this->getFormattedMessage(), 'formattedMessage' => (string) $this,
'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'), 'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'),
'sender' => $this->sender, 'sender' => $this->sender,
'username' => $this->getUsername(), 'username' => $this->getUsername(),
'time' => $this->time, 'time' => $this->time,
'receiver' => $this->receiver, 'receiver' => $this->receiver,
'type' => $this->type 'type' => $this->type,
'roomID' => $this->roomID
)); ));
} }
} }

View File

@ -16,12 +16,49 @@ class ChatMessageList extends \wcf\data\DatabaseObjectList {
*/ */
public $className = 'wcf\data\chat\message\ChatMessage'; 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 = new static();
$messageList->sqlOrderBy = "chat_message.messageID DESC"; $messageList->sqlOrderBy = "chat_message.messageID DESC";
$messageList->sqlLimit = $number; $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(); $messageList->readObjects();
return array_reverse($messageList->getObjects()); 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();
}
} }

View File

@ -81,6 +81,9 @@ public function readData() {
) )
)); ));
$messageAction->executeAction(); $messageAction->executeAction();
$return = $messageAction->getReturnValues();
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => $return['returnValues'] -> messageID));
} }
$this->readDefaultSmileys(); $this->readDefaultSmileys();