diff --git a/file/js/TimWolla.WCF.Chat.coffee b/file/js/TimWolla.WCF.Chat.coffee index 4d4d74f..5f35bd0 100644 --- a/file/js/TimWolla.WCF.Chat.coffee +++ b/file/js/TimWolla.WCF.Chat.coffee @@ -132,6 +132,12 @@ TimWolla.WCF ?= {} # Loads new messages. ### getMessages: () -> + $.ajax 'index.php/Chat/Message/', + dataType: 'json' + type: 'POST' + success: $.proxy((data, textStatus, jqXHR) -> + @handleMessages(data) + , this) ### # Inserts the new messages. # diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php new file mode 100644 index 0000000..3bdaf6c --- /dev/null +++ b/file/lib/page/ChatMessagePage.class.php @@ -0,0 +1,56 @@ + + * @package timwolla.wcf.chat + * @subpackage page + */ +class ChatMessagePage extends AbstractPage { + public $messages = array(); + public $neededModules = array('CHAT_ACTIVE'); + //public $neededPermissions = array('user.chat.canEnter'); + public $room = null; + public $roomID = 0; + public $useTemplate = false; + + /** + * Reads room data. + */ + public function readData() { + parent::readData(); + $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')); + } + + /** + * @see \wcf\page\IPage::show() + */ + public function show() { + // guests are not supported + if (!WCF::getUser()->userID) { + throw new \wcf\system\exception\PermissionDeniedException(); + } + + parent::show(); + + @header('Content-type: application/json'); + $result = '['; + foreach ($this->messages as $message) { + $result .= $message->jsonify().','; + } + echo rtrim($result, ',').']'; + exit; + } +} diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index db8c11c..53d2a5e 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -106,7 +106,11 @@ public function readDefaultSmileys() { public function readParameters() { parent::readParameters(); - if ($this->action == 'Log') { + if ($this->action == 'Message') { + new ChatMessagePage(); + exit; + } + else if ($this->action == 'Log') { //TODO: Initialise LogPage exit; } diff --git a/file/lib/system/event/listener/ChatRouteListener.class.php b/file/lib/system/event/listener/ChatRouteListener.class.php index f23c609..1c64d13 100644 --- a/file/lib/system/event/listener/ChatRouteListener.class.php +++ b/file/lib/system/event/listener/ChatRouteListener.class.php @@ -18,7 +18,7 @@ public function execute($eventObj, $className, $eventName) { $route = new \wcf\system\request\Route('chatAction'); $route->setSchema('/{controller}/{action}'); $route->setParameterOption('controller', null, 'Chat'); - $route->setParameterOption('action', null, '(Log|Send|RefreshRoomList)'); + $route->setParameterOption('action', null, '(Message|Log|Send|RefreshRoomList)'); $eventObj->addRoute($route); } }