diff --git a/file/lib/data/chat/room/ChatRoom.class.php b/file/lib/data/chat/room/ChatRoom.class.php index 9882226..bf958ef 100644 --- a/file/lib/data/chat/room/ChatRoom.class.php +++ b/file/lib/data/chat/room/ChatRoom.class.php @@ -43,9 +43,11 @@ public function __toString() { * * @return boolean */ - public function canEnter() { - $ph = \wcf\system\chat\permission\ChatPermissionHandler::getInstance(); - $suspensions = ChatSuspension::getSuspensionsForUser(); + public function canEnter(\wcf\data\user\User $user = null) { + if ($user === null) $user = WCF::getUser(); + + $ph = new \wcf\system\chat\permission\ChatPermissionHandler($user); + $suspensions = ChatSuspension::getSuspensionsForUser($user); $canEnter = $ph->getPermission($this, 'user.canEnter'); // room suspension @@ -70,9 +72,11 @@ public function canEnter() { * * @return boolean */ - public function canWrite() { - $ph = \wcf\system\chat\permission\ChatPermissionHandler::getInstance(); - $suspensions = ChatSuspension::getSuspensionsForUser(); + public function canWrite(\wcf\data\user\User $user = null) { + if ($user === null) $user = WCF::getUser(); + + $ph = new \wcf\system\chat\permission\ChatPermissionHandler($user); + $suspensions = ChatSuspension::getSuspensionsForUser($user); $canWrite = $ph->getPermission($this, 'user.canWrite'); // room suspension @@ -171,8 +175,7 @@ public function getUsers() { $sql = "SELECT u.*, - st.fieldValue AS awayStatus, - su.suspensionID AS suspended + st.fieldValue AS awayStatus FROM wcf".WCF_N."_user u LEFT JOIN @@ -182,20 +185,12 @@ public function getUsers() { AND st.field = ? AND st.packageID = ? ) - LEFT JOIN - wcf".WCF_N."_chat_suspension su - ON ( - u.userID = su.userID - AND ( su.roomID IS NULL - OR su.roomID = ?) - AND time > ? - ) WHERE u.userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") ORDER BY u.username ASC"; $stmt = WCF::getDB()->prepareStatement($sql); - array_unshift($userIDs, 'away', $packageID, $this->roomID, TIME_NOW); + array_unshift($userIDs, 'away', $packageID); $stmt->execute($userIDs); return $stmt->fetchObjects('\wcf\data\user\User'); diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php index e37f34f..7b7948b 100644 --- a/file/lib/page/ChatMessagePage.class.php +++ b/file/lib/page/ChatMessagePage.class.php @@ -115,8 +115,8 @@ public function readMessages() { // update last seen message $sql = "SELECT - max(messageID) as messageID - FROM + MAX(messageID) as messageID + FROM wcf".WCF_N."_chat_message"; $stmt = WCF::getDB()->prepareStatement($sql); $stmt->execute(); @@ -162,7 +162,24 @@ public function show() { 'userID' => $user->userID, 'username' => $user->username, 'awayStatus' => $user->awayStatus, - 'suspended' => $user->suspended + 'suspended' => !$this->room->canWrite($user) + ); + } + + if (ENABLE_BENCHMARK) { + $b = \wcf\system\benchmark\Benchmark::getInstance(); + $items = array(); + if (ENABLE_DEBUG_MODE) { + foreach ($b->getItems() as $item) { + $items[] = array('text' => $item['text'], 'use' => $item['use']); + } + } + + $json['benchmark'] = array( + 'time' => $b->getExecutionTime(), + 'queryTime' => $b->getQueryExecutionTime(), + 'queryPercent' => $b->getQueryExecutionTime() / $b->getExecutionTime(), + 'items' => $items ); } diff --git a/file/lib/system/chat/permission/ChatPermissionHandler.class.php b/file/lib/system/chat/permission/ChatPermissionHandler.class.php index 5f0215e..135534b 100644 --- a/file/lib/system/chat/permission/ChatPermissionHandler.class.php +++ b/file/lib/system/chat/permission/ChatPermissionHandler.class.php @@ -14,39 +14,41 @@ * @package be.bastelstu.wcf.chat * @subpackage system.chat.permissions */ -class ChatPermissionHandler extends \wcf\system\SingletonFactory { +class ChatPermissionHandler { protected $chatPermissions = array(); + protected $user = null, $userProfile = null; - /** - * @see \wcf\system\SingletonFactory::init() - */ - protected function init() { + public function __construct(\wcf\data\user\User $user = null) { + if ($user === null) $user = WCF::getUser(); + $this->user = $user; + $this->userProfile = new \wcf\data\user\UserProfile($this->user); + $packageID = \wcf\util\ChatUtil::getPackageID(); $ush = \wcf\system\user\storage\UserStorageHandler::getInstance(); // get groups permissions - $groups = implode(',', WCF::getUser()->getGroupIDs()); - $groupsFileName = \wcf\util\StringUtil::getHash(implode('-', WCF::getUser()->getGroupIDs())); + $groups = implode(',', $user->getGroupIDs()); + $groupsFileName = \wcf\util\StringUtil::getHash(implode('-', $user->getGroupIDs())); CacheHandler::getInstance()->addResource('chatPermission-'.$groups, WCF_DIR.'cache/cache.chatPermission-'.$groupsFileName.'.php', '\wcf\system\cache\builder\ChatPermissionCacheBuilder'); $this->chatPermissions = CacheHandler::getInstance()->get('chatPermission-'.$groups); // get user permissions - if (WCF::getUser()->userID) { + if ($user->userID) { // get data from storage - $ush->loadStorage(array(WCF::getUser()->userID), $packageID); - + $ush->loadStorage(array($user->userID), $packageID); + // get ids - $data = $ush->getStorage(array(WCF::getUser()->userID), 'chatUserPermissions', $packageID); - + $data = $ush->getStorage(array($user->userID), 'chatUserPermissions', $packageID); + // cache does not exist or is outdated - if ($data[WCF::getUser()->userID] === null) { + if ($data[$user->userID] === null) { $userPermissions = array(); $conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $conditionBuilder->add('acl_option.packageID IN (?)', array(PackageDependencyHandler::getInstance()->getDependencies())); $conditionBuilder->add('acl_option.objectTypeID = ?', array(ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.wcf.chat.room'))); $conditionBuilder->add('option_to_user.optionID = acl_option.optionID'); - $conditionBuilder->add('option_to_user.userID = ?', array(WCF::getUser()->userID)); + $conditionBuilder->add('option_to_user.userID = ?', array($user->userID)); $sql = "SELECT option_to_user.objectID AS roomID, option_to_user.optionValue, acl_option.optionName AS permission FROM wcf".WCF_N."_acl_option acl_option, @@ -59,10 +61,10 @@ protected function init() { } // update cache - $ush->update(WCF::getUser()->userID, 'chatUserPermissions', serialize($userPermissions), $packageID); + $ush->update($user->userID, 'chatUserPermissions', serialize($userPermissions), $packageID); } else { - $userPermissions = unserialize($data[WCF::getUser()->userID]); + $userPermissions = unserialize($data[$user->userID]); } foreach ($userPermissions as $roomID => $permissions) { @@ -83,7 +85,8 @@ protected function init() { public function getPermission(\wcf\data\chat\room\ChatRoom $room, $permission) { if (!isset($this->chatPermissions[$room->roomID][$permission])) { $permission = str_replace(array('user.', 'mod.'), array('user.chat.', 'mod.chat.'), $permission); - return WCF::getSession()->getPermission($permission); + + return $this->userProfile->getPermission($permission); } return (boolean) $this->chatPermissions[$room->roomID][$permission]; }