From a2638046eb698b725c71387a5fbd5ddce965b58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 13:58:28 +0100 Subject: [PATCH 01/18] Adding Basic command system. To be improved! --- .../data/chat/message/ChatMessage.class.php | 1 + .../chat/commands/AbstractCommand.class.php | 22 ++++++++ .../AbstractRestrictedCommand.class.php | 24 +++++++++ .../commands/ChatCommandHandler.class.php | 26 ---------- .../chat/commands/CommandHandler.class.php | 52 +++++++++++++++++++ .../system/chat/commands/ICommand.class.php | 20 +++++++ .../commands/IRestrictedCommand.class.php | 15 ++++++ .../chat/commands/NotFoundException.class.php | 13 +++++ .../chat/commands/commands/Free.class.php | 23 ++++++++ 9 files changed, 170 insertions(+), 26 deletions(-) create mode 100644 file/lib/system/chat/commands/AbstractCommand.class.php create mode 100644 file/lib/system/chat/commands/AbstractRestrictedCommand.class.php delete mode 100644 file/lib/system/chat/commands/ChatCommandHandler.class.php create mode 100644 file/lib/system/chat/commands/CommandHandler.class.php create mode 100644 file/lib/system/chat/commands/ICommand.class.php create mode 100644 file/lib/system/chat/commands/IRestrictedCommand.class.php create mode 100644 file/lib/system/chat/commands/NotFoundException.class.php create mode 100644 file/lib/system/chat/commands/commands/Free.class.php diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index 9de2527..544a5f0 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -34,6 +34,7 @@ class ChatMessage extends \wcf\data\DatabaseObject { const TYPE_CLEAR = 9; const TYPE_TEAM = 10; const TYPE_GLOBALMESSAGE = 11; + const TYPE_ERROR = 12; /** * @see \wcf\data\chat\message\ChatMessage::getFormattedMessage() diff --git a/file/lib/system/chat/commands/AbstractCommand.class.php b/file/lib/system/chat/commands/AbstractCommand.class.php new file mode 100644 index 0000000..5fd3494 --- /dev/null +++ b/file/lib/system/chat/commands/AbstractCommand.class.php @@ -0,0 +1,22 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +abstract class AbstractCommand implements ICommand { + public $commandHandler = null; + + public function __construct(CommandHandler $commandHandler) { + EventHandler::getInstance()->fireAction($this, 'shouldInit'); + $this->commandHandler = $commandHandler; + EventHandler::getInstance()->fireAction($this, 'didInit'); + } +} diff --git a/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php b/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php new file mode 100644 index 0000000..1619dff --- /dev/null +++ b/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php @@ -0,0 +1,24 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +abstract class AbstractRestrictedCommand extends AbstractCommand implements IRestrictedCommand { + public function __construct(CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + $this->checkPermission(); + } + + public function checkPermission() { + EventHandler::getInstance()->fireAction($this, 'checkPermission'); + } +} diff --git a/file/lib/system/chat/commands/ChatCommandHandler.class.php b/file/lib/system/chat/commands/ChatCommandHandler.class.php deleted file mode 100644 index 6e24a6a..0000000 --- a/file/lib/system/chat/commands/ChatCommandHandler.class.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @package timwolla.wcf.chat - * @subpackage system.chat.commands - */ -class ChatCommandHandler { - const COMMAND_CHAR = '/'; - - /** - * Checks whether the given text is a command. - * - * @param string $text - * @return boolean - */ - public function isCommand($text) { - return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; - } -} diff --git a/file/lib/system/chat/commands/CommandHandler.class.php b/file/lib/system/chat/commands/CommandHandler.class.php new file mode 100644 index 0000000..56271d5 --- /dev/null +++ b/file/lib/system/chat/commands/CommandHandler.class.php @@ -0,0 +1,52 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +class CommandHandler { + const COMMAND_CHAR = '/'; + public $text = ''; + + /** + * Initialises the CommandHandler + * + * @param string $text + */ + public function __construct($text) { + $this->text = $text; + } + + /** + * Checks whether the given text is a command. + */ + public function isCommand($text = null) { + if ($text === null) $text = $this->text; + return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; + } + + /** + * Loads the command. + */ + public function loadCommand() { + $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); + + if ($this->isCommand($parts[0])) { + return new \wcf\system\chat\commands\PlainCommand(); + } + + $class = '\wcf\system\chat\commands\commands\\'.ucfirst($parts[0]); + if (!class_exists($class)) { + throw new NotFoundException(); + } + + return new $class($this); + } +} diff --git a/file/lib/system/chat/commands/ICommand.class.php b/file/lib/system/chat/commands/ICommand.class.php new file mode 100644 index 0000000..8cb458d --- /dev/null +++ b/file/lib/system/chat/commands/ICommand.class.php @@ -0,0 +1,20 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +interface ICommand { + const SMILEY_OFF = 0; + const SMILEY_ON = 1; + const SMILEY_USER = 2; + + public function getType(); + public function getMessage(); +} diff --git a/file/lib/system/chat/commands/IRestrictedCommand.class.php b/file/lib/system/chat/commands/IRestrictedCommand.class.php new file mode 100644 index 0000000..285d22d --- /dev/null +++ b/file/lib/system/chat/commands/IRestrictedCommand.class.php @@ -0,0 +1,15 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +interface IRestrictedCommand { + protected function checkPermission(); +} diff --git a/file/lib/system/chat/commands/NotFoundException.class.php b/file/lib/system/chat/commands/NotFoundException.class.php new file mode 100644 index 0000000..f62e63e --- /dev/null +++ b/file/lib/system/chat/commands/NotFoundException.class.php @@ -0,0 +1,13 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands + */ +class NotFoundException extends \Exception { } \ No newline at end of file diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php new file mode 100644 index 0000000..a6bfdfe --- /dev/null +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -0,0 +1,23 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands.commands + */ +class Free extends \wcf\system\chat\commands\AbstractCommand { + const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_USER; + + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_ME; + } + + public function getMessage() { + return 'freed the fish'; + } +} From bb50e76463ca166a9e78800903d1e1f56d5d036d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:09:29 +0100 Subject: [PATCH 02/18] Change username on error-type as well --- file/lib/data/chat/message/ChatMessage.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index 544a5f0..1af64a8 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -72,7 +72,7 @@ public function getFormattedMessage() { public function getFormattedUsername() { $username = $this->getUsername(); - if ($this->type != self::TYPE_INFORMATION) $username = \wcf\util\ChatUtil::gradient($username, $this->color1, $this->color2); + if ($this->type != self::TYPE_INFORMATION && $this->type != self::TYPE_ERROR) $username = \wcf\util\ChatUtil::gradient($username, $this->color1, $this->color2); return ''.$username.''; } @@ -84,6 +84,8 @@ public function getFormattedUsername() { */ public function getUsername() { if ($this->type == self::TYPE_INFORMATION) return WCF::getLanguage()->get('wcf.chat.information'); + if ($this->type == self::ERROR) return WCF::getLanguage()->get('wcf.chat.error'); + return $this->username; } From 0dcb2823c3f71c1dbbfbb2f1bdfc1f10ef5f29a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:10:40 +0100 Subject: [PATCH 03/18] ME and WHISPER are parsed like normal messages --- file/lib/data/chat/message/ChatMessage.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index 1af64a8..a94bdce 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -57,9 +57,12 @@ public function getFormattedMessage() { $message = WCF::getLanguage()->get('wcf.chat.message.'.$this->type); break; case self::TYPE_NORMAL: + case self::TYPE_ME: + case self::TYPE_WHISPER: if (!$this->enableHTML) { $message = \wcf\system\bbcode\SimpleMessageParser::getInstance()->parse($message, true, $this->enableSmilies); } + break; } return $message; } @@ -84,7 +87,7 @@ public function getFormattedUsername() { */ public function getUsername() { if ($this->type == self::TYPE_INFORMATION) return WCF::getLanguage()->get('wcf.chat.information'); - if ($this->type == self::ERROR) return WCF::getLanguage()->get('wcf.chat.error'); + if ($this->type == self::TYPE_ERROR) return WCF::getLanguage()->get('wcf.chat.error'); return $this->username; } From 83713fc56eb72d5c4bc177d26a8741eeb4049616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:17:13 +0100 Subject: [PATCH 04/18] Use language-items --- file/lib/form/ChatForm.class.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/file/lib/form/ChatForm.class.php b/file/lib/form/ChatForm.class.php index 04503da..283fe38 100644 --- a/file/lib/form/ChatForm.class.php +++ b/file/lib/form/ChatForm.class.php @@ -62,15 +62,35 @@ public function validate() { public function save() { parent::save(); - $commandHandler = new \wcf\system\chat\commands\ChatCommandHandler(); - var_dump($commandHandler->isCommand($this->message)); + $commandHandler = new \wcf\system\chat\commands\CommandHandler($this->message); + if ($commandHandler->isCommand()) { + try { + $command = $commandHandler->loadCommand(); + + if ($command::ENABLE_SMILIES != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command::ENABLE_SMILIES; + $type = $command->getType(); + $this->message = $command->getMessage(); + } + catch (\wcf\system\chat\commands\NotFoundException $e) { + $this->message = WCF::getLanguage()->get('wcf.chat.command.error.notFound'); + $type = chat\message\ChatMessage::TYPE_ERROR; + } + catch (\wcf\system\exception\PermissionDeniedException $e) { + $this->message = WCF::getLanguage()->get('wcf.chat.command.error.permissionDenied'); + $type = chat\message\ChatMessage::TYPE_ERROR; + } + } + else { + $type = chat\message\ChatMessage::TYPE_NORMAL; + } + $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_NORMAL, + 'type' => $type, 'message' => $this->message, 'enableSmilies' => $this->enableSmilies, 'color1' => $this->userData['color'][1], From cfa7ce79a90a3809ca0088496a13b3afe048dc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:21:06 +0100 Subject: [PATCH 05/18] Adding separator --- file/lib/data/chat/message/ChatMessage.class.php | 1 + template/chatMessage.tpl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index a94bdce..ac50043 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -103,6 +103,7 @@ public function jsonify($raw = false) { 'formattedUsername' => $this->getFormattedUsername(), 'formattedMessage' => (string) $this, 'formattedTime' => \wcf\util\DateUtil::format(\wcf\util\DateUtil::getDateTimeByTimestamp($this->time), 'H:i:s'), + 'separator' => ($this->type == self::TYPE_NORMAL) ? ': ' : ' ', 'sender' => $this->sender, 'username' => $this->getUsername(), 'time' => $this->time, diff --git a/template/chatMessage.tpl b/template/chatMessage.tpl index 466534a..b3566fb 100644 --- a/template/chatMessage.tpl +++ b/template/chatMessage.tpl @@ -1 +1 @@ -{literal}
{@$formattedUsername}
{@$formattedMessage}
{/literal} +{literal}
{@$formattedUsername}{$separator}
{@$formattedMessage}
{/literal} From 6046e40cc2240400fde320a52ef36e2c7a3023c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:32:28 +0100 Subject: [PATCH 06/18] Adding /me --- .../chat/commands/CommandHandler.class.php | 11 +++++++ .../chat/commands/commands/Free.class.php | 13 ++++---- .../chat/commands/commands/Me.class.php | 30 +++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 file/lib/system/chat/commands/commands/Me.class.php diff --git a/file/lib/system/chat/commands/CommandHandler.class.php b/file/lib/system/chat/commands/CommandHandler.class.php index 56271d5..a0b5406 100644 --- a/file/lib/system/chat/commands/CommandHandler.class.php +++ b/file/lib/system/chat/commands/CommandHandler.class.php @@ -32,6 +32,17 @@ public function isCommand($text = null) { return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; } + /** + * Returns the parameter-string. + * + * @return string + */ + public function getParameters() { + $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); + + return $parts[1]; + } + /** * Loads the command. */ diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php index a6bfdfe..4ed581c 100644 --- a/file/lib/system/chat/commands/commands/Free.class.php +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -10,14 +10,13 @@ * @package timwolla.wcf.chat * @subpackage system.chat.commands.commands */ -class Free extends \wcf\system\chat\commands\AbstractCommand { - const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_USER; - - public function getType() { - return \wcf\data\chat\message\ChatMessage::TYPE_ME; - } +class Free extends Me { + const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_OFF; + /** + * @see \wcf\system\chat\commands\ICommand::getMessage() + */ public function getMessage() { - return 'freed the fish'; + return 'freed the fish. OH A NOEZ'; } } diff --git a/file/lib/system/chat/commands/commands/Me.class.php b/file/lib/system/chat/commands/commands/Me.class.php new file mode 100644 index 0000000..c0e79c8 --- /dev/null +++ b/file/lib/system/chat/commands/commands/Me.class.php @@ -0,0 +1,30 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands.commands + */ +class Me extends \wcf\system\chat\commands\AbstractCommand { + const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_USER; + + /** + * @see \wcf\system\chat\commands\ICommand::getType() + */ + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_ME; + } + + /** + * @see \wcf\system\chat\commands\ICommand::getMessage() + */ + public function getMessage() { + return$this->commandHandler->getParameters(); + } +} From fd6739bd2d1a8087961a98ab2c809eb9059c828e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:34:42 +0100 Subject: [PATCH 07/18] Commands return the receiver now as well --- file/lib/form/ChatForm.class.php | 5 +++++ file/lib/system/chat/commands/AbstractCommand.class.php | 4 ++++ file/lib/system/chat/commands/ICommand.class.php | 1 + 3 files changed, 10 insertions(+) diff --git a/file/lib/form/ChatForm.class.php b/file/lib/form/ChatForm.class.php index 283fe38..25b29af 100644 --- a/file/lib/form/ChatForm.class.php +++ b/file/lib/form/ChatForm.class.php @@ -70,18 +70,22 @@ public function save() { if ($command::ENABLE_SMILIES != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command::ENABLE_SMILIES; $type = $command->getType(); $this->message = $command->getMessage(); + $receiver = $command->getReceiver(); } catch (\wcf\system\chat\commands\NotFoundException $e) { $this->message = WCF::getLanguage()->get('wcf.chat.command.error.notFound'); $type = chat\message\ChatMessage::TYPE_ERROR; + $receiver = WCF::getUser()->userID; } catch (\wcf\system\exception\PermissionDeniedException $e) { $this->message = WCF::getLanguage()->get('wcf.chat.command.error.permissionDenied'); $type = chat\message\ChatMessage::TYPE_ERROR; + $receiver = WCF::getUser()->userID; } } else { $type = chat\message\ChatMessage::TYPE_NORMAL; + $receiver = null; } $messageAction = new chat\message\ChatMessageAction(array(), 'create', array( @@ -89,6 +93,7 @@ public function save() { 'roomID' => $this->room->roomID, 'sender' => WCF::getUser()->userID, 'username' => WCF::getUser()->username, + 'receiver' => $receiver, 'time' => TIME_NOW, 'type' => $type, 'message' => $this->message, diff --git a/file/lib/system/chat/commands/AbstractCommand.class.php b/file/lib/system/chat/commands/AbstractCommand.class.php index 5fd3494..3539b9d 100644 --- a/file/lib/system/chat/commands/AbstractCommand.class.php +++ b/file/lib/system/chat/commands/AbstractCommand.class.php @@ -19,4 +19,8 @@ public function __construct(CommandHandler $commandHandler) { $this->commandHandler = $commandHandler; EventHandler::getInstance()->fireAction($this, 'didInit'); } + + public function getReceiver() { + return null; + } } diff --git a/file/lib/system/chat/commands/ICommand.class.php b/file/lib/system/chat/commands/ICommand.class.php index 8cb458d..a94ca4c 100644 --- a/file/lib/system/chat/commands/ICommand.class.php +++ b/file/lib/system/chat/commands/ICommand.class.php @@ -17,4 +17,5 @@ interface ICommand { public function getType(); public function getMessage(); + public function getReceiver(); } From f020c8a20f55a2ab95390fc5be4e8cb080d49f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 27 Dec 2011 14:39:42 +0100 Subject: [PATCH 08/18] Adding missing space --- file/lib/system/chat/commands/commands/Me.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file/lib/system/chat/commands/commands/Me.class.php b/file/lib/system/chat/commands/commands/Me.class.php index c0e79c8..a7864d7 100644 --- a/file/lib/system/chat/commands/commands/Me.class.php +++ b/file/lib/system/chat/commands/commands/Me.class.php @@ -25,6 +25,6 @@ public function getType() { * @see \wcf\system\chat\commands\ICommand::getMessage() */ public function getMessage() { - return$this->commandHandler->getParameters(); + return $this->commandHandler->getParameters(); } } From 06c77bafdea4f45c5134dec1328bfb22dbd1eb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 22 Jan 2012 14:48:11 +0100 Subject: [PATCH 09/18] Removing some inconsistencies --- file/js/TimWolla.WCF.Chat.coffee | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/file/js/TimWolla.WCF.Chat.coffee b/file/js/TimWolla.WCF.Chat.coffee index b8257bf..771550f 100644 --- a/file/js/TimWolla.WCF.Chat.coffee +++ b/file/js/TimWolla.WCF.Chat.coffee @@ -19,7 +19,7 @@ TimWolla.WCF ?= {} newMessage: $.Callbacks() userMenu: $.Callbacks() init: () -> - console.log('[TimWolla.WCF.Chat] Initializing'); + console.log '[TimWolla.WCF.Chat] Initializing' @bindEvents() @events.newMessage.add $.proxy @notify, @ @@ -35,7 +35,8 @@ TimWolla.WCF ?= {} bindEvents: () -> @isActive = true $(window).focus $.proxy () -> - document.title = @titleTemplate.fetch({ title: $('#chatRoomList .activeMenuItem a').text() }) + document.title = @titleTemplate.fetch + title: $('#chatRoomList .activeMenuItem a').text() @newMessageCount = 0 @isActive = true , @ @@ -109,7 +110,7 @@ TimWolla.WCF ?= {} $('#topic').text data.topic $('#topic').wcfBlindIn() if $('#topic').text().trim() isnt '' and $('#topic').is(':hidden') - $('title').text @titleTemplate.fetch(data) + $('title').text @titleTemplate.fetch data @getMessages() , @) error: () -> @@ -250,11 +251,15 @@ TimWolla.WCF ?= {} return if (@isActive or $('#chatNotify').data('status') is 0) @newMessageCount++ - document.title = '(' + @newMessageCount + ') ' + @titleTemplate.fetch({ title: $('#chatRoomList .activeMenuItem a').text() }) + document.title = '(' + @newMessageCount + ') ' + @titleTemplate.fetch + title: $('#chatRoomList .activeMenuItem a').text() if typeof window.webkitNotifications isnt 'undefined' if window.webkitNotifications.checkPermission() is 0 - notification = window.webkitNotifications.createNotification WCF.Icon.get('timwolla.wcf.chat.chat'), WCF.Language.get('wcf.chat.newMessages'), message.username + ' ' + message.message + title = WCF.Language.get('wcf.chat.newMessages') + icon = WCF.Icon.get('timwolla.wcf.chat.chat') + content = message.username + message.separator + ' ' + message.message + notification = window.webkitNotifications.createNotification icon, title, content notification.show() setTimeout(() -> notification.cancel() From 5e177e614fd98de5fe0c67f03a862e0b31a43af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 22 Jan 2012 15:40:25 +0100 Subject: [PATCH 10/18] Adding Color-Command --- .../chat/commands/commands/Color.class.php | 76 +++++++++++++++++++ .../chat/commands/commands/Free.class.php | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 file/lib/system/chat/commands/commands/Color.class.php diff --git a/file/lib/system/chat/commands/commands/Color.class.php b/file/lib/system/chat/commands/commands/Color.class.php new file mode 100644 index 0000000..13790dd --- /dev/null +++ b/file/lib/system/chat/commands/commands/Color.class.php @@ -0,0 +1,76 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands.commands + */ +class Color extends \wcf\system\chat\commands\AbstractCommand { + const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_OFF; + public static $colors = array( + 'red' => 0xFF0000, + 'blue' => 0x0000FF, + 'green' => 0x00FF00, + 'yellow' => 0xFFFF00, + 'black' => 0x000000, + 'white' => 0xFFFFFF, + 'orange' => 0xFFA500, + 'purple' => 0xA020F0, + 'weed' => 0xF5DEB3, + 'pink' => 0xFFC0CB, + 'grey' => 0xBEBEBE, + 'khaki' => 0xF0E68C, + 'lavender' => 0xE6E6FA, + 'maroon' => 0xB03060, + 'gold' => 0xFFD700, + 'navyblue' => 0x000080, + 'royalblue' => 0x4169E1, + 'aquamarine' => 0x7FFFD4, + 'cyan' => 0x00FFFF, + 'magenta' => 0x00FFFF + ); + + public function __construct(\wcf\system\chat\commands\CommandHandler $commandHandler) { + parent::__construct($commandHandler); + list($color1, $color2) = explode(' ', $commandHandler->getParameters()); + if (isset(self::$colors[$color1])) $color1 = self::$colors[$color1]; + else { + if (strlen($color1) == 3) $color1 = $color1[0].$color1[0].$color1[1].$color1[1].$color1[2].$color1[2]; + $color1 = hexdec($color1); + } + if (isset(self::$colors[$color2])) $color2 = self::$colors[$color2]; + else { + if (strlen($color2) == 3) $color2 = $color2[0].$color2[0].$color2[1].$color2[1].$color2[2].$color2[2]; + $color2 = hexdec($color2); + } + + \wcf\util\ChatUtil::writeUserData(array('color' => array(1 => $color1, 2 => $color2))); + } + + /** + * @see \wcf\system\chat\commands\ICommand::getType() + */ + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_INFORMATION; + } + + /** + * @see \wcf\system\chat\commands\ICommand::getMessage() + */ + public function getMessage() { + return 'color changed'; + } + + /** + * @see \wcf\system\chat\commands\ICommand::getReceiver() + */ + public function getReceiver() { + return \wcf\system\WCF::getUser()->userID; + } +} diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php index 4ed581c..941091d 100644 --- a/file/lib/system/chat/commands/commands/Free.class.php +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -2,7 +2,7 @@ namespace wcf\system\chat\commands\commands; /** - * Free-Command + * Informs everyone that the fish was freed. OH A NOEZ. * * @author Tim Düsterhus * @copyright 2010-2011 Tim Düsterhus From 7c8a72e89cbd4672b498aef6c3f567794bd9bdb3 Mon Sep 17 00:00:00 2001 From: max-m Date: Sat, 28 Jan 2012 15:23:33 +0100 Subject: [PATCH 11/18] Check if the executed command actually is "free the fish". --- file/lib/system/chat/commands/commands/Free.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php index 941091d..25b19df 100644 --- a/file/lib/system/chat/commands/commands/Free.class.php +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -17,6 +17,9 @@ class Free extends Me { * @see \wcf\system\chat\commands\ICommand::getMessage() */ public function getMessage() { - return 'freed the fish. OH A NOEZ'; + if (\wcf\util\StringUtil::toLowerCase($this->commandHandler->getParameters()) == 'the fish') + return 'freed the fish. OH A NOEZ'; + else + throw new \wcf\system\chat\commands\NotFoundException(); } } From 5eb9aea5037e8e02583bbcae8a2761ebe33de691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 30 Jan 2012 17:48:13 +0100 Subject: [PATCH 12/18] 2011 -> 2012 --- file/lib/system/chat/commands/AbstractCommand.class.php | 2 +- .../system/chat/commands/AbstractRestrictedCommand.class.php | 2 +- file/lib/system/chat/commands/CommandHandler.class.php | 2 +- file/lib/system/chat/commands/ICommand.class.php | 2 +- file/lib/system/chat/commands/IRestrictedCommand.class.php | 2 +- file/lib/system/chat/commands/NotFoundException.class.php | 2 +- file/lib/system/chat/commands/commands/Color.class.php | 2 +- file/lib/system/chat/commands/commands/Free.class.php | 2 +- file/lib/system/chat/commands/commands/Me.class.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/file/lib/system/chat/commands/AbstractCommand.class.php b/file/lib/system/chat/commands/AbstractCommand.class.php index 3539b9d..8c994ad 100644 --- a/file/lib/system/chat/commands/AbstractCommand.class.php +++ b/file/lib/system/chat/commands/AbstractCommand.class.php @@ -6,7 +6,7 @@ * Default implementation for commands. * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands diff --git a/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php b/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php index 1619dff..6d743a0 100644 --- a/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php +++ b/file/lib/system/chat/commands/AbstractRestrictedCommand.class.php @@ -6,7 +6,7 @@ * Default implementation for restricted commands * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands diff --git a/file/lib/system/chat/commands/CommandHandler.class.php b/file/lib/system/chat/commands/CommandHandler.class.php index a0b5406..558f6b5 100644 --- a/file/lib/system/chat/commands/CommandHandler.class.php +++ b/file/lib/system/chat/commands/CommandHandler.class.php @@ -6,7 +6,7 @@ * Handles commands * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands diff --git a/file/lib/system/chat/commands/ICommand.class.php b/file/lib/system/chat/commands/ICommand.class.php index a94ca4c..72e0ae4 100644 --- a/file/lib/system/chat/commands/ICommand.class.php +++ b/file/lib/system/chat/commands/ICommand.class.php @@ -5,7 +5,7 @@ * Interface for chat-commands. * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands diff --git a/file/lib/system/chat/commands/IRestrictedCommand.class.php b/file/lib/system/chat/commands/IRestrictedCommand.class.php index 285d22d..abdb3c2 100644 --- a/file/lib/system/chat/commands/IRestrictedCommand.class.php +++ b/file/lib/system/chat/commands/IRestrictedCommand.class.php @@ -5,7 +5,7 @@ * Interface for Restricted commands. * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands diff --git a/file/lib/system/chat/commands/NotFoundException.class.php b/file/lib/system/chat/commands/NotFoundException.class.php index f62e63e..fe786ec 100644 --- a/file/lib/system/chat/commands/NotFoundException.class.php +++ b/file/lib/system/chat/commands/NotFoundException.class.php @@ -5,7 +5,7 @@ * Thrown when a command is not found. * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands diff --git a/file/lib/system/chat/commands/commands/Color.class.php b/file/lib/system/chat/commands/commands/Color.class.php index 13790dd..6f8f322 100644 --- a/file/lib/system/chat/commands/commands/Color.class.php +++ b/file/lib/system/chat/commands/commands/Color.class.php @@ -6,7 +6,7 @@ * Changes the color of the username * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands.commands diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php index 25b19df..b5a77e7 100644 --- a/file/lib/system/chat/commands/commands/Free.class.php +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -5,7 +5,7 @@ * Informs everyone that the fish was freed. OH A NOEZ. * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands.commands diff --git a/file/lib/system/chat/commands/commands/Me.class.php b/file/lib/system/chat/commands/commands/Me.class.php index a7864d7..d08f36d 100644 --- a/file/lib/system/chat/commands/commands/Me.class.php +++ b/file/lib/system/chat/commands/commands/Me.class.php @@ -6,7 +6,7 @@ * Indicates an action. The message is shown without the colon. * * @author Tim Düsterhus - * @copyright 2010-2011 Tim Düsterhus + * @copyright 2010-2012 Tim Düsterhus * @license Creative Commons Attribution-NonCommercial-ShareAlike * @package timwolla.wcf.chat * @subpackage system.chat.commands.commands From d2f6e3c88ab61c3e2c53fa15361edd8dea76d6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 30 Jan 2012 18:13:16 +0100 Subject: [PATCH 13/18] Fixing Color-Command --- .../chat/commands/commands/Color.class.php | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/file/lib/system/chat/commands/commands/Color.class.php b/file/lib/system/chat/commands/commands/Color.class.php index 6f8f322..8142a7c 100644 --- a/file/lib/system/chat/commands/commands/Color.class.php +++ b/file/lib/system/chat/commands/commands/Color.class.php @@ -38,19 +38,25 @@ class Color extends \wcf\system\chat\commands\AbstractCommand { public function __construct(\wcf\system\chat\commands\CommandHandler $commandHandler) { parent::__construct($commandHandler); - list($color1, $color2) = explode(' ', $commandHandler->getParameters()); - if (isset(self::$colors[$color1])) $color1 = self::$colors[$color1]; - else { - if (strlen($color1) == 3) $color1 = $color1[0].$color1[0].$color1[1].$color1[1].$color1[2].$color1[2]; - $color1 = hexdec($color1); + try { + list($color[1], $color[2]) = explode(' ', $commandHandler->getParameters()); } - if (isset(self::$colors[$color2])) $color2 = self::$colors[$color2]; - else { - if (strlen($color2) == 3) $color2 = $color2[0].$color2[0].$color2[1].$color2[1].$color2[2].$color2[2]; - $color2 = hexdec($color2); + catch (\wcf\system\exception\SystemException $e) { + $color[1] = $color[2] = $commandHandler->getParameters(); } - \wcf\util\ChatUtil::writeUserData(array('color' => array(1 => $color1, 2 => $color2))); + $regex = new \wcf\system\Regex('^#?([a-f0-9]{3}|[a-f0-9]{6})$', \wcf\system\Regex::CASE_INSENSITIVE); + foreach ($color as $key => $val) { + if (isset(self::$colors[$val])) $color[$key] = self::$colors[$val]; + else { + if (!$regex->match($val)) throw new \wcf\system\chat\commands\NotFoundException(); + $matches = $regex->getMatches(); + $val = $matches[1]; + if (strlen($val) == 3) $val = $val[0].$val[0].$val[1].$val[1].$val[2].$val[2]; + $color[$key] = hexdec($val); + } + } + \wcf\util\ChatUtil::writeUserData(array('color' => $color)); } /** From 1ffd7c78284d4b9ed00405716060192b2314b6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 30 Jan 2012 18:16:15 +0100 Subject: [PATCH 14/18] Adding predefined oxford color --- .../chat/commands/commands/Color.class.php | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/file/lib/system/chat/commands/commands/Color.class.php b/file/lib/system/chat/commands/commands/Color.class.php index 8142a7c..db67a55 100644 --- a/file/lib/system/chat/commands/commands/Color.class.php +++ b/file/lib/system/chat/commands/commands/Color.class.php @@ -14,26 +14,27 @@ class Color extends \wcf\system\chat\commands\AbstractCommand { const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_OFF; public static $colors = array( - 'red' => 0xFF0000, - 'blue' => 0x0000FF, - 'green' => 0x00FF00, - 'yellow' => 0xFFFF00, - 'black' => 0x000000, - 'white' => 0xFFFFFF, - 'orange' => 0xFFA500, - 'purple' => 0xA020F0, - 'weed' => 0xF5DEB3, - 'pink' => 0xFFC0CB, - 'grey' => 0xBEBEBE, - 'khaki' => 0xF0E68C, - 'lavender' => 0xE6E6FA, - 'maroon' => 0xB03060, - 'gold' => 0xFFD700, - 'navyblue' => 0x000080, - 'royalblue' => 0x4169E1, - 'aquamarine' => 0x7FFFD4, - 'cyan' => 0x00FFFF, - 'magenta' => 0x00FFFF + 'red' => 0xFF0000, + 'blue' => 0x0000FF, + 'green' => 0x00FF00, + 'yellow' => 0xFFFF00, + 'black' => 0x000000, + 'white' => 0xFFFFFF, + 'orange' => 0xFFA500, + 'purple' => 0xA020F0, + 'weed' => 0xF5DEB3, + 'pink' => 0xFFC0CB, + 'grey' => 0xBEBEBE, + 'khaki' => 0xF0E68C, + 'lavender' => 0xE6E6FA, + 'maroon' => 0xB03060, + 'gold' => 0xFFD700, + 'navyblue' => 0x000080, + 'royalblue' => 0x4169E1, + 'aquamarine' => 0x7FFFD4, + 'cyan' => 0x00FFFF, + 'magenta' => 0x00FFFF, + 'oxford' => 0xF02D // looks like green ); public function __construct(\wcf\system\chat\commands\CommandHandler $commandHandler) { From 64fb4bec06a3f0c7248c8c8543faa5845113672a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 4 Feb 2012 12:25:09 +0100 Subject: [PATCH 15/18] Use classmember instead of constant for smiley activation --- file/lib/form/ChatForm.class.php | 3 ++- file/lib/system/chat/commands/CommandHandler.class.php | 2 +- file/lib/system/chat/commands/commands/Color.class.php | 2 +- file/lib/system/chat/commands/commands/Free.class.php | 2 +- file/lib/system/chat/commands/commands/Me.class.php | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/file/lib/form/ChatForm.class.php b/file/lib/form/ChatForm.class.php index 1d12d46..32e9d54 100644 --- a/file/lib/form/ChatForm.class.php +++ b/file/lib/form/ChatForm.class.php @@ -51,6 +51,7 @@ public function readFormParameters() { */ public function validate() { parent::validate(); + if ($this->message === '') { throw new UserInputException('text'); } @@ -67,7 +68,7 @@ public function save() { try { $command = $commandHandler->loadCommand(); - if ($command::ENABLE_SMILIES != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command::ENABLE_SMILIES; + if ($command->enableSmilies != \wcf\system\chat\commands\ICommand::SMILEY_USER) $this->enableSmilies = $command->enableSmilies; $type = $command->getType(); $this->message = $command->getMessage(); $receiver = $command->getReceiver(); diff --git a/file/lib/system/chat/commands/CommandHandler.class.php b/file/lib/system/chat/commands/CommandHandler.class.php index 558f6b5..2121fc2 100644 --- a/file/lib/system/chat/commands/CommandHandler.class.php +++ b/file/lib/system/chat/commands/CommandHandler.class.php @@ -50,7 +50,7 @@ public function loadCommand() { $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); if ($this->isCommand($parts[0])) { - return new \wcf\system\chat\commands\PlainCommand(); + return new commands\commands\PlainCommand($this); } $class = '\wcf\system\chat\commands\commands\\'.ucfirst($parts[0]); diff --git a/file/lib/system/chat/commands/commands/Color.class.php b/file/lib/system/chat/commands/commands/Color.class.php index db67a55..b79ce01 100644 --- a/file/lib/system/chat/commands/commands/Color.class.php +++ b/file/lib/system/chat/commands/commands/Color.class.php @@ -12,7 +12,7 @@ * @subpackage system.chat.commands.commands */ class Color extends \wcf\system\chat\commands\AbstractCommand { - const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_OFF; + public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_OFF; public static $colors = array( 'red' => 0xFF0000, 'blue' => 0x0000FF, diff --git a/file/lib/system/chat/commands/commands/Free.class.php b/file/lib/system/chat/commands/commands/Free.class.php index b5a77e7..2ffdfd8 100644 --- a/file/lib/system/chat/commands/commands/Free.class.php +++ b/file/lib/system/chat/commands/commands/Free.class.php @@ -11,7 +11,7 @@ * @subpackage system.chat.commands.commands */ class Free extends Me { - const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_OFF; + public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_OFF; /** * @see \wcf\system\chat\commands\ICommand::getMessage() diff --git a/file/lib/system/chat/commands/commands/Me.class.php b/file/lib/system/chat/commands/commands/Me.class.php index d08f36d..dbe734e 100644 --- a/file/lib/system/chat/commands/commands/Me.class.php +++ b/file/lib/system/chat/commands/commands/Me.class.php @@ -12,7 +12,7 @@ * @subpackage system.chat.commands.commands */ class Me extends \wcf\system\chat\commands\AbstractCommand { - const ENABLE_SMILIES = \wcf\system\chat\commands\ICommand::SMILEY_USER; + public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_USER; /** * @see \wcf\system\chat\commands\ICommand::getType() From 08a27db4ede4424dcc7dbf864b63c24ca5f12038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 4 Feb 2012 12:32:56 +0100 Subject: [PATCH 16/18] Adding PlainCommand --- .../chat/commands/CommandHandler.class.php | 16 +++++++-- .../chat/commands/commands/Plain.class.php | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 file/lib/system/chat/commands/commands/Plain.class.php diff --git a/file/lib/system/chat/commands/CommandHandler.class.php b/file/lib/system/chat/commands/CommandHandler.class.php index 2121fc2..23335fa 100644 --- a/file/lib/system/chat/commands/CommandHandler.class.php +++ b/file/lib/system/chat/commands/CommandHandler.class.php @@ -11,9 +11,9 @@ * @package timwolla.wcf.chat * @subpackage system.chat.commands */ -class CommandHandler { +final class CommandHandler { const COMMAND_CHAR = '/'; - public $text = ''; + private $text = ''; /** * Initialises the CommandHandler @@ -32,6 +32,15 @@ public function isCommand($text = null) { return StringUtil::substring($text, 0, StringUtil::length(static::COMMAND_CHAR)) == static::COMMAND_CHAR; } + /** + * Returns the whole message. + * + * @return string + */ + public function getText() { + return $this->text; + } + /** * Returns the parameter-string. * @@ -40,6 +49,7 @@ public function isCommand($text = null) { public function getParameters() { $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); + if (!isset($parts[1])) return ''; return $parts[1]; } @@ -50,7 +60,7 @@ public function loadCommand() { $parts = explode(' ', StringUtil::substring($this->text, StringUtil::length(static::COMMAND_CHAR)), 2); if ($this->isCommand($parts[0])) { - return new commands\commands\PlainCommand($this); + return new commands\Plain($this); } $class = '\wcf\system\chat\commands\commands\\'.ucfirst($parts[0]); diff --git a/file/lib/system/chat/commands/commands/Plain.class.php b/file/lib/system/chat/commands/commands/Plain.class.php new file mode 100644 index 0000000..e0d9e53 --- /dev/null +++ b/file/lib/system/chat/commands/commands/Plain.class.php @@ -0,0 +1,36 @@ + + * @package timwolla.wcf.chat + * @subpackage system.chat.commands.commands + */ +class Plain extends \wcf\system\chat\commands\AbstractCommand { + public $enableSmilies = \wcf\system\chat\commands\ICommand::SMILEY_USER; + + /** + * @see \wcf\system\chat\commands\ICommand::getType() + */ + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_NORMAL; + } + + /** + * @see \wcf\system\chat\commands\ICommand::getMessage() + */ + public function getMessage() { + return \wcf\util\StringUtil::substring($this->commandHandler->getText(), 1); + } + + /** + * @see \wcf\system\chat\commands\ICommand::getReceiver() + */ + public function getReceiver() { + return null; + } +} From f58b51896378a48337d1ad710e393b056f804462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 22 Mar 2012 17:38:33 +0100 Subject: [PATCH 17/18] Handle arbitrary Exceptions --- file/lib/form/ChatForm.class.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/file/lib/form/ChatForm.class.php b/file/lib/form/ChatForm.class.php index 64a2db5..763241d 100644 --- a/file/lib/form/ChatForm.class.php +++ b/file/lib/form/ChatForm.class.php @@ -90,6 +90,11 @@ public function save() { $type = chat\message\ChatMessage::TYPE_ERROR; $receiver = WCF::getUser()->userID; } + catch (\Exception $e) { + $this->message = WCF::getLanguage()->get('wcf.chat.command.error.exception'); + $type = chat\message\ChatMessage::TYPE_ERROR; + $receiver = WCF::getUser()->userID; + } } else { $type = chat\message\ChatMessage::TYPE_NORMAL; From e7598d14f7f59325f2d698af0de85b422491e8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 22 Mar 2012 18:45:36 +0100 Subject: [PATCH 18/18] Adding away-command --- file/js/be.bastelstu.WCF.Chat.coffee | 11 ++++ file/lib/data/chat/room/ChatRoom.class.php | 53 +++++++++++-------- file/lib/form/ChatForm.class.php | 21 +++++++- file/lib/page/ChatMessagePage.class.php | 3 +- .../chat/commands/commands/Away.class.php | 43 +++++++++++++++ 5 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 file/lib/system/chat/commands/commands/Away.class.php 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; + } +}