diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php index f05c03e..d7f2fbf 100644 --- a/file/lib/page/ChatMessagePage.class.php +++ b/file/lib/page/ChatMessagePage.class.php @@ -22,31 +22,61 @@ class ChatMessagePage extends AbstractPage { public $useTemplate = false; /** - * Reads room data. + * @see \wcf\page\Page::readData() */ public function 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->room = chat\room\ChatRoom::getCache()->search($this->roomID); if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); + } + + public function readUsers() { + $packageID = \wcf\system\package\PackageDependencyHandler::getPackageID('timwolla.wcf.chat'); - $this->messages = chat\message\ChatMessageList::getMessagesSince($this->room, \wcf\util\ChatUtil::readUserData('lastSeen')); - $stmt = WCF::getDB()->prepareStatement("SELECT max(messageID) as messageID FROM wcf".WCF_N."_chat_message"); - $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->execute(); while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID']; - $sql = "SELECT u.* - FROM wcf".WCF_N."_user u - WHERE userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") - ORDER BY u.username ASC"; + $sql = "SELECT + * + FROM + wcf".WCF_N."_user + WHERE + userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") + ORDER BY + username ASC"; $stmt = WCF::getDB()->prepareStatement($sql); $stmt->execute($userIDs); $this->users = $stmt->fetchObjects('\wcf\data\user\User'); @@ -75,6 +105,7 @@ public function show() { 'username' => $user->username ); } + echo \wcf\util\JSON::encode($json); exit; }