1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-22 21:40:08 +00:00

Automatically refresh the room-list

This commit is contained in:
Tim Düsterhus 2011-12-18 16:08:51 +01:00
parent 818d51608c
commit 52445e9cb9
3 changed files with 106 additions and 8 deletions

View File

@ -16,6 +16,8 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {};
messageTemplate: null, messageTemplate: null,
init: function(roomID, messageID) { init: function(roomID, messageID) {
this.bindEvents(); this.bindEvents();
this.refreshRoomList();
new WCF.PeriodicalExecuter(this.refreshRoomList, 10e3);
$('#chatInput').focus(); $('#chatInput').focus();
}, },
@ -36,13 +38,6 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {};
this.toggleSidebarContent($(event.target)); this.toggleSidebarContent($(event.target));
}, this)); }, 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) { $('.chatUser .chatUserLink').click($.proxy(function (event) {
event.preventDefault(); event.preventDefault();
this.toggleUserMenu($(event.target)); this.toggleUserMenu($(event.target));
@ -173,7 +168,28 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {};
}, },
refreshRoomList: function() { refreshRoomList: function() {
$('.chatRoom').unbind('click'); $('.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 = $('<li></li>');
if (data[room].active) li.addClass('activeMenuItem');
$('<a href="'+data[room].link+'">'+data[room].title+'</a>').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) { submit: function (target) {

View File

@ -0,0 +1,82 @@
<?php
namespace wcf\page;
use \wcf\data\chat;
use \wcf\system\cache\CacheHandler;
use \wcf\system\package\PackageDependencyHandler;
use \wcf\system\user\storage\UserStorageHandler;
use \wcf\system\WCF;
/**
* Shows the chat-interface
*
* @author Tim Düsterhus
* @copyright 2010-2011 Tim Düsterhus
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
* @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;
}
}

View File

@ -232,7 +232,7 @@
<nav class="chatSidebarTabs"> <nav class="chatSidebarTabs">
<ul> <ul>
<li id="toggleUsers" class="active"><a href="javascript:;" title="{lang}wcf.chat.users{/lang}">{lang}wcf.chat.users{/lang}</a></li> <li id="toggleUsers" class="active"><a href="javascript:;" title="{lang}wcf.chat.users{/lang}">{lang}wcf.chat.users{/lang}</a></li>
<li id="toggleRooms"><a href="javascript:;" title="{lang}wcf.chat.rooms{/lang}">{lang}wcf.chat.rooms{/lang}</a></li> <li id="toggleRooms"><a href="javascript:;" title="{lang}wcf.chat.rooms{/lang}" data-refresh-url="{link controller="Chat" action="RefreshRoomList"}{/link}">{lang}wcf.chat.rooms{/lang}</a></li>
</ul> </ul>
</nav> </nav>