diff --git a/file/js/be.bastelstu.WCF.Chat.coffee b/file/js/be.bastelstu.WCF.Chat.coffee index 059970e..dea41c5 100644 --- a/file/js/be.bastelstu.WCF.Chat.coffee +++ b/file/js/be.bastelstu.WCF.Chat.coffee @@ -312,6 +312,13 @@ consoleMock ?= if element[0] console.log '[be.bastelstu.WCF.Chat Moving User: "' + user.username + '"' element = element.detach() + if user.awayStatus? + element.addClass 'timsChatAway' + element.attr 'title', user.awayStatus + else + element.removeClass 'timsChatAway' + element.removeAttr 'title' + element.data 'tooltip', '' $('#timsChatUserList').append element # Insert the user else @@ -319,6 +326,10 @@ consoleMock ?= li = $ '
  • ' li.attr 'id', id li.addClass 'timsChatUser' + li.addClass 'jsTooltip' + if user.awayStatus? + li.addClass 'timsChatAway' + li.attr 'title', user.awayStatus li.data 'username', user.username a = $ ''+user.username+'' a.click $.proxy (event) -> diff --git a/file/lib/data/chat/room/ChatRoom.class.php b/file/lib/data/chat/room/ChatRoom.class.php index 0ad0cbb..578c566 100644 --- a/file/lib/data/chat/room/ChatRoom.class.php +++ b/file/lib/data/chat/room/ChatRoom.class.php @@ -22,7 +22,7 @@ class ChatRoom extends \wcf\data\DatabaseObject implements \wcf\system\request\I * @see \wcf\data\DatabaseObject::$databaseTableIndexName */ protected static $databaseTableIndexName = 'roomID'; - + /** * Caches rooms. * @@ -43,21 +43,18 @@ public function __toString() { * @return integer */ public function countUsers() { - $packageID = \wcf\util\ChatUtil::getPackageID(); - $sql = "SELECT - count(*) as count + COUNT(*) FROM wcf".WCF_N."_user_storage WHERE - field = 'roomID' - AND packageID = ".intval($packageID)." - AND fieldValue = ".intval($this->roomID); + field = ? + AND packageID = ? + AND fieldValue = ?"; $stmt = WCF::getDB()->prepareStatement($sql); - $stmt->execute(); - $row = $stmt->fetchArray(); + $stmt->execute(array('roomID', \wcf\util\ChatUtil::getPackageID(), $this->roomID)); - return $row['count']; + return $stmt->fetchColumn(); } /** @@ -101,32 +98,42 @@ public function getTitle() { */ public function getUsers() { $packageID = \wcf\util\ChatUtil::getPackageID(); - + $sql = "SELECT userID FROM wcf".WCF_N."_user_storage WHERE - field = 'roomID' - AND packageID = ".intval($packageID)." - AND fieldValue = ".intval($this->roomID); + field = ? + AND packageID = ? + AND fieldValue = ?"; $stmt = WCF::getDB()->prepareStatement($sql); - $stmt->execute(); + $stmt->execute(array('roomID', $packageID, $this->roomID)); $userIDs = array(); - while ($row = $stmt->fetchArray()) $userIDs[] = $row['userID']; - - if (!count($userIDs)) return; - + while ($userIDs[] = $stmt->fetchColumn()); + + if (!count($userIDs)) return array(); + $sql = "SELECT - * + u.*, + s.fieldValue AS awayStatus FROM - wcf".WCF_N."_user + wcf".WCF_N."_user u + LEFT JOIN + wcf".WCF_N."_user_storage s + ON ( + u.userID = s.userID + AND s.field = ? + AND s.packageID = ? + ) WHERE - userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") + u.userID IN (".rtrim(str_repeat('?,', count($userIDs)), ',').") ORDER BY - username ASC"; + u.username ASC"; $stmt = WCF::getDB()->prepareStatement($sql); + array_unshift($userIDs, 'away', $packageID); $stmt->execute($userIDs); + return $stmt->fetchObjects('\wcf\data\user\User'); } diff --git a/file/lib/form/ChatForm.class.php b/file/lib/form/ChatForm.class.php index 763241d..325ddef 100644 --- a/file/lib/form/ChatForm.class.php +++ b/file/lib/form/ChatForm.class.php @@ -31,6 +31,7 @@ class ChatForm extends AbstractForm { public function readData() { $this->userData['color'] = \wcf\util\ChatUtil::readUserData('color'); $this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID'); + $this->userData['away'] = \wcf\util\ChatUtil::readUserData('away'); $this->room = chat\room\ChatRoom::getCache()->search($this->userData['roomID']); if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); @@ -70,6 +71,7 @@ public function validate() { public function save() { parent::save(); + \wcf\util\ChatUtil::writeUserData(array('away' => null)); $commandHandler = new \wcf\system\chat\commands\CommandHandler($this->message); if ($commandHandler->isCommand()) { try { @@ -101,6 +103,23 @@ public function save() { $receiver = null; } + // mark user as back + if ($this->userData['away'] !== null) { + $messageAction = new chat\message\ChatMessageAction(array(), 'create', array( + 'data' => array( + 'roomID' => $this->room->roomID, + 'sender' => WCF::getUser()->userID, + 'username' => WCF::getUser()->username, + 'time' => TIME_NOW, + 'type' => chat\message\ChatMessage::TYPE_BACK, + 'message' => '', + 'color1' => $this->userData['color'][1], + 'color2' => $this->userData['color'][2] + ) + )); + $messageAction->executeAction(); + } + $messageAction = new chat\message\ChatMessageAction(array(), 'create', array( 'data' => array( 'roomID' => $this->room->roomID, @@ -124,7 +143,7 @@ public function save() { * @see \wcf\page\IPage::show() */ public function show() { - header("HTTP/1.0 204 No Content"); + //header("HTTP/1.0 204 No Content"); parent::show(); } } diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php index 062f4f3..a74d2c1 100644 --- a/file/lib/page/ChatMessagePage.class.php +++ b/file/lib/page/ChatMessagePage.class.php @@ -79,7 +79,8 @@ public function show() { foreach ($this->users as $user) { $json['users'][] = array( 'userID' => $user->userID, - 'username' => $user->username + 'username' => $user->username, + 'awayStatus' => $user->awayStatus ); } diff --git a/file/lib/system/chat/commands/commands/Away.class.php b/file/lib/system/chat/commands/commands/Away.class.php new file mode 100644 index 0000000..775bc3a --- /dev/null +++ b/file/lib/system/chat/commands/commands/Away.class.php @@ -0,0 +1,43 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands.commands + */ +class Away extends \wcf\system\chat\commands\AbstractCommand { + public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_OFF; + + public function __construct(\wcf\system\chat\commands\CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + \wcf\util\ChatUtil::writeUserData(array('away' => $commandHandler->getParameters())); + } + + /** + * @see \wcf\system\chat\commands\ICommand::getType() + */ + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_AWAY; + } + + /** + * @see \wcf\system\chat\commands\ICommand::getMessage() + */ + public function getMessage() { + return $this->commandHandler->getParameters(); + } + + /** + * @see \wcf\system\chat\commands\ICommand::getReceiver() + */ + public function getReceiver() { + return \wcf\system\WCF::getUser()->userID; + } +}