From 8e2154c9944362189cdc7244f9249348c1e052ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 7 Sep 2012 22:58:13 +0200 Subject: [PATCH] Adding WhisperCommand --- .../data/chat/message/ChatMessage.class.php | 8 ++- .../command/commands/WhisperCommand.class.php | 55 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 file/lib/system/chat/command/commands/WhisperCommand.class.php diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php index d067b0b..b7287ac 100755 --- a/file/lib/data/chat/message/ChatMessage.class.php +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -58,9 +58,11 @@ public function getFormattedMessage($outputType = 'text/html') { WCF::getTPL()->assign(@unserialize($message)); $message = WCF::getLanguage()->getDynamicVariable('wcf.chat.message.'.$this->type); break; + case self::TYPE_WHISPER: + $message = @unserialize($message); + $message = $message['message']; case self::TYPE_NORMAL: case self::TYPE_ME: - case self::TYPE_WHISPER: if (!$this->enableHTML && $outputType == 'text/html') { $message = \wcf\system\bbcode\SimpleMessageParser::getInstance()->parse($message, true, $this->enableSmilies); } @@ -78,6 +80,10 @@ public function getFormattedUsername() { $username = $this->getUsername(); if ($this->type != self::TYPE_INFORMATION && $this->type != self::TYPE_ERROR) $username = \wcf\util\ChatUtil::gradient($username, $this->color1, $this->color2); + if ($this->type == self::TYPE_WHISPER) { + $message = @unserialize($this->message); + $username .= ' -> '.$message['username']; + } return ''.$username.''; } diff --git a/file/lib/system/chat/command/commands/WhisperCommand.class.php b/file/lib/system/chat/command/commands/WhisperCommand.class.php new file mode 100644 index 0000000..0da5283 --- /dev/null +++ b/file/lib/system/chat/command/commands/WhisperCommand.class.php @@ -0,0 +1,55 @@ + + * @package be.bastelstu.wcf.chat + * @subpackage system.chat.command.commands + */ +class WhisperCommand extends \wcf\system\chat\command\AbstractCommand { + public $enableSmilies = \wcf\system\chat\command\ICommand::SMILEY_USER; + public $user = null, $message = ''; + + public function __construct(\wcf\system\chat\command\CommandHandler $commandHandler) { + parent::__construct($commandHandler); + + $parameters = $commandHandler->getParameters(); + + if (($comma = strpos($parameters, ',')) !== false) { + $username = substr($parameters, 0, $comma); + $this->message = substr($parameters, $comma + 1); + } + else throw new \wcf\system\chat\command\NotFoundException(); + + $this->user = User::getUserByUsername($username); + if (!$this->user->userID) throw new \wcf\system\chat\command\UserNotFoundException($username); + + $this->didInit(); + } + + /** + * @see \wcf\system\chat\command\ICommand::getType() + */ + public function getType() { + return \wcf\data\chat\message\ChatMessage::TYPE_WHISPER; + } + + /** + * @see \wcf\system\chat\command\ICommand::getMessage() + */ + public function getMessage() { + return serialize(array('message' => $this->message, 'username' => $this->user->username)); + } + + /** + * @see \wcf\system\chat\command\ICommand::getReceiver() + */ + public function getReceiver() { + return $this->user->userID; + } +}