diff --git a/file/js/TimWolla.WCF.Chat.js b/file/js/TimWolla.WCF.Chat.js index 62f2b35..e3f1a7a 100644 --- a/file/js/TimWolla.WCF.Chat.js +++ b/file/js/TimWolla.WCF.Chat.js @@ -16,6 +16,8 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {}; messageTemplate: null, init: function(roomID, messageID) { this.bindEvents(); + this.refreshRoomList(); + new WCF.PeriodicalExecuter(this.refreshRoomList, 10e3); $('#chatInput').focus(); }, @@ -36,13 +38,6 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {}; this.toggleSidebarContent($(event.target)); }, this)); - $('.chatRoom').click($.proxy(function (event) { - if (typeof window.history.replaceState != 'undefined') { - event.preventDefault(); - this.changeRoom($(event.target)); - } - }, this)); - $('.chatUser .chatUserLink').click($.proxy(function (event) { event.preventDefault(); this.toggleUserMenu($(event.target)); @@ -173,7 +168,28 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {}; }, refreshRoomList: function() { $('.chatRoom').unbind('click'); + $('#toggleRooms a').addClass('ajaxLoad'); + $.ajax($('#toggleRooms a').data('refreshUrl'), { + dataType: 'json', + type: 'POST', + success: $.proxy(function (data, textStatus, jqXHR) { + $('#chatRoomList li').remove(); + $('#toggleRooms a').removeClass('ajaxLoad'); + for (var room in data) { + var li = $('
  • '); + if (data[room].active) li.addClass('activeMenuItem'); + $(''+data[room].title+'').addClass('chatRoom').appendTo(li); + $('#chatRoomList ul').append(li); + } + $('.chatRoom').click($.proxy(function (event) { + if (typeof window.history.replaceState != 'undefined') { + event.preventDefault(); + this.changeRoom($(event.target)); + } + }, this)); + }, this) + }); }, submit: function (target) { diff --git a/file/lib/page/ChatRefreshRoomListPage.class.php b/file/lib/page/ChatRefreshRoomListPage.class.php new file mode 100644 index 0000000..25e080f --- /dev/null +++ b/file/lib/page/ChatRefreshRoomListPage.class.php @@ -0,0 +1,82 @@ + + * @package timwolla.wcf.chat + * @subpackage page + */ +class ChatRefreshRoomListPage extends AbstractPage { + public $neededModules = array('CHAT_ACTIVE'); + //public $neededPermissions = array('user.chat.canEnter'); + public $room = null; + public $roomID = 0; + public $rooms = array(); + public $useTemplate = false; + + /** + * Reads room data. + */ + public function readData() { + parent::readData(); + $this->readUserData(); + $this->rooms = chat\room\ChatRoom::getCache(); + + $this->room = $this->rooms->search($this->roomID); + if (!$this->room) throw new \wcf\system\exception\IllegalLinkException(); + } + + /** + * Reads user data. + */ + public function readUserData() { + // TODO: Move this into ChatUtil + $ush = UserStorageHandler::getInstance(); + $packageID = PackageDependencyHandler::getPackageID('timwolla.wcf.chat'); + + // load storage + $ush->loadStorage(array(WCF::getUser()->userID), $packageID); + $data = $ush->getStorage(array(WCF::getUser()->userID), 'roomID', $packageID); + + if ($data[WCF::getUser()->userID] === null) { + throw new \wcf\system\exception\IllegalLinkException(); + } + + $this->roomID = $data[WCF::getUser()->userID]; + } + + /** + * @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'); + $json = array(); + foreach ($this->rooms as $room) { + $json[] = array( + 'title' => WCF::getLanguage()->get($room->title), + 'link' => \wcf\system\request\LinkHandler::getInstance()->getLink('Chat', array( + 'object' => $room + )), + 'active' => $room->roomID == $this->room->roomID + ); + } + echo \wcf\util\JSON::encode($json); + exit; + } +} diff --git a/template/chat.tpl b/template/chat.tpl index 2729438..1528c1f 100644 --- a/template/chat.tpl +++ b/template/chat.tpl @@ -232,7 +232,7 @@