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

Cleaning up ChatMessagePage

This commit is contained in:
Tim Düsterhus 2012-01-14 12:50:57 +01:00
parent 5d7ef3c05b
commit bedb5dcea5

View File

@ -22,31 +22,61 @@ class ChatMessagePage extends AbstractPage {
public $useTemplate = false; public $useTemplate = false;
/** /**
* Reads room data. * @see \wcf\page\Page::readData()
*/ */
public function readData() { public function readData() {
parent::readData(); parent::readData();
$this->readRoom();
$this->readMessages();
$this->readUsers();
}
public function readMessages() {
$this->messages = chat\message\ChatMessageList::getMessagesSince($this->room, \wcf\util\ChatUtil::readUserData('lastSeen'));
// update last seen message
$sql = "SELECT
max(messageID) as messageID
FROM
wcf".WCF_N."_chat_message";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute();
$row = $stmt->fetchArray();
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => $row['messageID']));
}
public function readRoom() {
$this->roomID = \wcf\util\ChatUtil::readUserData('roomID'); $this->roomID = \wcf\util\ChatUtil::readUserData('roomID');
$this->room = chat\room\ChatRoom::getCache()->search($this->roomID); $this->room = chat\room\ChatRoom::getCache()->search($this->roomID);
if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); if (!$this->room) throw new \wcf\system\exception\IllegalLinkException();
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
}
$this->messages = chat\message\ChatMessageList::getMessagesSince($this->room, \wcf\util\ChatUtil::readUserData('lastSeen')); public function readUsers() {
$stmt = WCF::getDB()->prepareStatement("SELECT max(messageID) as messageID FROM wcf".WCF_N."_chat_message"); $packageID = \wcf\system\package\PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
$stmt->execute();
$row = $stmt->fetchArray();
\wcf\util\ChatUtil::writeUserData(array('lastSeen' => $row['messageID']));
$sql = "SELECT userID FROM wcf".WCF_N."_user_storage WHERE field = 'roomID' AND packageID = 16 AND fieldValue = ".intval($this->roomID); $sql = "SELECT
userID
FROM
wcf".WCF_N."_user_storage
WHERE
field = 'roomID'
AND packageID = ".intval($packageID)."
AND fieldValue = ".intval($this->roomID);
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(); $stmt->execute();
while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID']; while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID'];
$sql = "SELECT u.* $sql = "SELECT
FROM wcf".WCF_N."_user u *
WHERE userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") FROM
ORDER BY u.username ASC"; wcf".WCF_N."_user
WHERE
userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').")
ORDER BY
username ASC";
$stmt = WCF::getDB()->prepareStatement($sql); $stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute($userIDs); $stmt->execute($userIDs);
$this->users = $stmt->fetchObjects('\wcf\data\user\User'); $this->users = $stmt->fetchObjects('\wcf\data\user\User');
@ -75,6 +105,7 @@ public function show() {
'username' => $user->username 'username' => $user->username
); );
} }
echo \wcf\util\JSON::encode($json); echo \wcf\util\JSON::encode($json);
exit; exit;
} }