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,11 +1,4 @@
{hascontent} {capture assign='roomList'}
<header class="boxHeadline boxSubHeadline">
<h1>{lang}chat.header.menu.chat{/lang}</h1>
</header>
<div class="container marginTop">
<ul class="containerList">
{content}
{foreach from=$rooms item='room'} {foreach from=$rooms item='room'}
{assign var='users' value=$room->getUsers()} {assign var='users' value=$room->getUsers()}
@ -28,7 +21,42 @@
</li> </li>
{/if} {/if}
{/foreach} {/foreach}
{/content} {/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>
<div class="container marginTop">
<ul class="containerList">
{@$roomList}
</ul> </ul>
</div> </div>
{/hascontent} <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>
{/if}