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
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);
// break if not using ajax
\wcf\system\nodePush\NodePushHandler::getInstance()->sendMessage('be.bastelstu.chat.join');
if ($this->useTemplate) exit;
@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) {
parent::init($box, $page);
if (!CHAT_ACTIVE) return;
if (!\wcf\system\WCF::getUser()->userID) return;
$this->rooms = data\room\Room::getCache();

View File

@ -1,34 +1,62 @@
{hascontent}
<header class="boxHeadline boxSubHeadline">
<h1>{lang}chat.header.menu.chat{/lang}</h1>
</header>
{capture assign='roomList'}
{foreach from=$rooms item='room'}
{assign var='users' value=$room->getUsers()}
<div class="container marginTop">
<ul class="containerList">
{content}
{foreach from=$rooms item='room'}
{assign var='users' value=$room->getUsers()}
{if $users|count > 0}
<li>
<div>
<div>
<hgroup class="containerHeadline">
<h1><a href="{link controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h1>
<h2>{$room->topic|language}</h2>
</hgroup>
{if $users|count > 0}
<li>
<div>
<div>
<hgroup class="containerHeadline">
<h1><a href="{link controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h1>
<h2>{$room->topic|language}</h2>
</hgroup>
<ul class="dataList">
{foreach from=$users item='user'}
<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
{/foreach}
</ul>
</div>
</div>
</li>
{/if}
{/foreach}
{/capture}
{if $onlyList|isset}
{@$roomList}
{else}
<div id="chatDashboardBoxOnlineListContainer" {if !$roomList|trim} style="display: none;"{/if}>
<header class="boxHeadline boxSubHeadline">
<h1>{lang}chat.header.menu.chat{/lang}</h1>
</header>
<ul class="dataList">
{foreach from=$users item='user'}
<li><a href="{link controller='User' object=$user}{/link}" class="userLink" data-user-id="{$user->userID}">{$user}</a></li>
{/foreach}
</ul>
</div>
</div>
</li>
{/if}
{/foreach}
{/content}
</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>
{/hascontent}
{/if}