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:
parent
5d7ef3c05b
commit
bedb5dcea5
@ -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();
|
||||
}
|
||||
|
||||
$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']));
|
||||
public function readUsers() {
|
||||
$packageID = \wcf\system\package\PackageDependencyHandler::getPackageID('timwolla.wcf.chat');
|
||||
|
||||
$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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user