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

Refresh dashboard box with nodePush

This commit is contained in:
Tim Düsterhus 2013-05-02 22:43:52 +02:00
parent ad5bf9eb9a
commit ee1114935a
4 changed files with 92 additions and 33 deletions

View File

@ -206,5 +206,34 @@ public function leave() {
// set current room to null // set current room to null
ChatUtil::writeUserData(array('roomID' => null), $this->parameters['user']); ChatUtil::writeUserData(array('roomID' => null), $this->parameters['user']);
\wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join');
}
/**
* Validates permissions.
*/
public function validateGetDashboardRoomList() {
if (!CHAT_ACTIVE) throw new \wcf\system\exception\IllegalLinkException();
}
/**
* Returns dashboard roomlist.
*/
public function getDashboardRoomList() {
$rooms = Room::getCache();
foreach ($rooms as $key => $room) {
if (!$room->canEnter()) unset($rooms[$key]);
}
\wcf\system\WCF::getTPL()->assign(array(
'rooms' => $rooms,
'onlyList' => true
));
return array(
'template' => \wcf\system\WCF::getTPL()->fetch('dashboardBoxOnlineList', 'chat')
);
} }
} }

View File

@ -208,6 +208,7 @@ public function show() {
\wcf\system\user\activity\point\UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.join', $result, WCF::getUser()->userID); \wcf\system\user\activity\point\UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.join', $result, WCF::getUser()->userID);
// break if not using ajax // break if not using ajax
\wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join');
if ($this->useTemplate) exit; if ($this->useTemplate) exit;
@header('Content-type: application/json'); @header('Content-type: application/json');

View File

@ -24,6 +24,7 @@ class OnlineListDashboardBox extends \wcf\system\dashboard\box\AbstractContentDa
public function init(\wcf\data\dashboard\box\DashboardBox $box, \wcf\page\IPage $page) { public function init(\wcf\data\dashboard\box\DashboardBox $box, \wcf\page\IPage $page) {
parent::init($box, $page); parent::init($box, $page);
if (!CHAT_ACTIVE) return;
if (!\wcf\system\WCF::getUser()->userID) return; if (!\wcf\system\WCF::getUser()->userID) return;
$this->rooms = data\room\Room::getCache(); $this->rooms = data\room\Room::getCache();

View File

@ -1,34 +1,62 @@
{hascontent} {capture assign='roomList'}
<header class="boxHeadline boxSubHeadline"> {foreach from=$rooms item='room'}
<h1>{lang}chat.header.menu.chat{/lang}</h1> {assign var='users' value=$room->getUsers()}
</header>
{if $users|count > 0}
<div class="container marginTop"> <li>
<ul class="containerList"> <div>
{content} <div>
{foreach from=$rooms item='room'} <hgroup class="containerHeadline">
{assign var='users' value=$room->getUsers()} <h1><a href="{link controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h1>
<h2>{$room->topic|language}</h2>
{if $users|count > 0} </hgroup>
<li>
<div> <ul class="dataList">
<div> {foreach from=$users item='user'}
<hgroup class="containerHeadline"> <li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
<h1><a href="{link controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h1> {/foreach}
<h2>{$room->topic|language}</h2> </ul>
</hgroup> </div>
</div>
<ul class="dataList"> </li>
{foreach from=$users item='user'} {/if}
<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li> {/foreach}
{/foreach} {/capture}
</ul> {if $onlyList|isset}
</div> {@$roomList}
</div> {else}
</li> <div id="chatDashboardBoxOnlineListContainer" {if !$roomList|trim} style="display: none;"{/if}>
{/if} <header class="boxHeadline boxSubHeadline">
{/foreach} <h1>{lang}chat.header.menu.chat{/lang}</h1>
{/content} </header>
</ul>
<div class="container marginTop">
<ul class="containerList">
{@$roomList}
</ul>
</div>
<script type="text/javascript">
//<![CDATA[
(function($, window, undefined) {
proxy = new WCF.Action.Proxy({
data: {
actionName: 'getDashboardRoomList',
className: 'chat\\data\\room\\RoomAction'
},
showLoadingOverlay: false,
suppressErrors: true,
success: function(data) {
if (data.returnValues.template) $('#chatDashboardBoxOnlineListContainer').show();
else $('#chatDashboardBoxOnlineListContainer').hide();
$('#chatDashboardBoxOnlineListContainer ul').html(data.returnValues.template);
}
});
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.join', $.proxy(proxy.sendRequest, proxy));
be.bastelstu.wcf.nodePush.onMessage('be.bastelstu.chat.leave', $.proxy(proxy.sendRequest, proxy));
})(jQuery, this);
//]]>
</script>
</div> </div>
{/hascontent} {/if}