From f777bc1d2e8fe2dc835fc8ba7be19aa9e915b8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 7 Sep 2012 22:37:25 +0200 Subject: [PATCH] Fixing Chat*(Page|Form|Action) --- file/lib/action/ChatLeaveAction.class.php | 5 +++-- file/lib/form/ChatForm.class.php | 6 ++++-- file/lib/page/ChatMessagePage.class.php | 5 +++-- file/lib/page/ChatPage.class.php | 20 +++++++++---------- .../page/ChatRefreshRoomListPage.class.php | 4 ++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/file/lib/action/ChatLeaveAction.class.php b/file/lib/action/ChatLeaveAction.class.php index 0670073..0ee0516 100644 --- a/file/lib/action/ChatLeaveAction.class.php +++ b/file/lib/action/ChatLeaveAction.class.php @@ -67,8 +67,9 @@ public function execute() { $this->userData['roomID'] = \wcf\util\ChatUtil::readUserData('roomID'); - $this->room = chat\room\ChatRoom::getCache()->search($this->userData['roomID']); - if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); + $cache = chat\room\ChatRoom::getCache(); + if (!isset($cache[$this->userData['roomID']])) throw new \wcf\system\exception\IllegalLinkException(); + $this->room = $cache[$this->userData['roomID']]; if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); if (CHAT_DISPLAY_JOIN_LEAVE) { diff --git a/file/lib/form/ChatForm.class.php b/file/lib/form/ChatForm.class.php index 513a126..4b64369 100644 --- a/file/lib/form/ChatForm.class.php +++ b/file/lib/form/ChatForm.class.php @@ -95,8 +95,10 @@ public function readData() { $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(); + $cache = chat\room\ChatRoom::getCache(); + if (!isset($cache[$this->userData['roomID']])) throw new \wcf\system\exception\IllegalLinkException(); + $this->room = $cache[$this->userData['roomID']]; + if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); if (!$this->room->canWrite()) throw new \wcf\system\exception\PermissionDeniedException(); parent::readData(); diff --git a/file/lib/page/ChatMessagePage.class.php b/file/lib/page/ChatMessagePage.class.php index 063d103..e37f34f 100644 --- a/file/lib/page/ChatMessagePage.class.php +++ b/file/lib/page/ChatMessagePage.class.php @@ -133,9 +133,10 @@ public function readMessages() { */ public function readRoom() { $roomID = \wcf\util\ChatUtil::readUserData('roomID'); + $cache = chat\room\ChatRoom::getCache(); + if (!isset($cache[$roomID])) throw new \wcf\system\exception\IllegalLinkException(); - $this->room = chat\room\ChatRoom::getCache()->search($roomID); - if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); + $this->room = $cache[$roomID]; if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); } diff --git a/file/lib/page/ChatPage.class.php b/file/lib/page/ChatPage.class.php index 59b197c..ccf42d4 100644 --- a/file/lib/page/ChatPage.class.php +++ b/file/lib/page/ChatPage.class.php @@ -213,22 +213,20 @@ public function readRoom() { if ($this->roomID === 0) { // no room given - try { - // redirect to first chat-room - $this->rooms->seek(0); - \wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array( - 'object' => $this->rooms->current() - ))); - exit; - } - catch (\OutOfBoundsException $e) { + $room = reset($this->rooms); + if ($room === null) { // no valid room found throw new \wcf\system\exception\IllegalLinkException(); } + // redirect to first chat-room + \wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array( + 'object' => $room + ))); + exit; } - $this->room = $this->rooms->search($this->roomID); - if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); + if (!isset($this->rooms[$this->roomID])) throw new \wcf\system\exception\IllegalLinkException(); + $this->room = $this->rooms[$this->roomID]; if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException(); } diff --git a/file/lib/page/ChatRefreshRoomListPage.class.php b/file/lib/page/ChatRefreshRoomListPage.class.php index 6c5d13b..d4c8298 100644 --- a/file/lib/page/ChatRefreshRoomListPage.class.php +++ b/file/lib/page/ChatRefreshRoomListPage.class.php @@ -62,8 +62,8 @@ public function readData() { $this->rooms = chat\room\ChatRoom::getCache(); $roomID = \wcf\util\ChatUtil::readUserData('roomID'); - $this->room = $this->rooms->search($roomID); - if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); + if (!isset($this->rooms[$roomID])) throw new \wcf\system\exception\IllegalLinkException(); + $this->room = $this->rooms[$roomID]; } /**