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:
parent
c83336c9fb
commit
bdb7ec3b0d
@ -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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,9 @@ public function readData() {
|
||||
)
|
||||
));
|
||||
$messageAction->executeAction();
|
||||
$return = $messageAction->getReturnValues();
|
||||
|
||||
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => $return['returnValues'] -> messageID));
|
||||
}
|
||||
|
||||
$this->readDefaultSmileys();
|
||||
|
Loading…
Reference in New Issue
Block a user