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

Merge branch 'RoomUserLimit'

This commit is contained in:
Maximilian Mader 2015-01-10 01:42:33 +01:00
commit e2372ca799
10 changed files with 77 additions and 13 deletions

View File

@ -71,6 +71,22 @@
{include file='multipleLanguageInputJavascript' elementIdentifier='topic' forceSelection=false}
<dl{if $errorField == 'maxUsers'} class="formError"{/if}>
<dt><label for="maxUsers">{lang}chat.acp.room.maxUsers{/lang}</label></dt>
<dd>
<input id="maxUsers" class="tiny" type="number" min="0" value="{$maxUsers}" name="maxUsers" />
{if $errorField == 'topic'}
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
{else}
{lang}chat.acp.room.topic.error.{@$errorType}{/lang}
{/if}
</small>
{/if}
</dd>
</dl>
<dl id="groupPermissions">
<dt>{lang}wcf.acl.permissions{/lang}</dt>
<dd></dd>

View File

@ -962,7 +962,7 @@ Fetch the roomlist from the server and update it in the GUI.
roomList =
active: {}
available: {}
do $('.timsChatRoom').remove
$('#toggleRooms .badge').text data.returnValues.length
@ -970,15 +970,21 @@ Fetch the roomlist from the server and update it in the GUI.
roomList.available[room.roomID] = room
roomList.active = room if room.active
li = $ '<li></li>'
li = $ '<li />'
li.addClass 'timsChatRoom'
li.addClass 'active' if room.active
a = $("""<a href="#{room.link}">#{WCF.String.escapeHTML(room.title)}</a>""")
a.data 'roomID', room.roomID
a.appendTo li
$("""<span class="badge">#{WCF.String.formatNumeric room.userCount}</span>""").appendTo li
span = $ '<span />'
span.addClass 'badge'
span.text WCF.String.formatNumeric room.userCount
span.append " / #{WCF.String.formatNumeric room.maxUsers}" if room.maxUsers > 0
span.appendTo li
$('#timsChatRoomList ul').append li
if window.history?.replaceState?
$('.timsChatRoom a').click (event) ->
do event.preventDefault
@ -991,7 +997,7 @@ Fetch the roomlist from the server and update it in the GUI.
join target.data 'roomID'
$('#timsChatRoomList .active').removeClass 'active'
target.parent().addClass 'active'
console.log "Found #{data.returnValues.length} rooms"
Shows an unrecoverable error with the given text.
@ -1036,6 +1042,7 @@ Joins a room.
className: 'chat\\data\\room\\RoomAction'
parameters:
roomID: roomID
suppressErrors: true
success: (data) ->
loading = false
roomList.active = data.returnValues
@ -1056,7 +1063,19 @@ Joins a room.
do $('#timsChatInput').enable().focus
failure: (data) ->
showError WCF.Language.get 'chat.error.join', data
if data?.returnValues?.fieldName is 'room'
isJoining = no
loading = false
window.history.replaceState {}, '', roomList.active.link if window.history?.replaceState?
$('<div>').attr('id', 'timsChatJoinErrorDialog').append("<p>#{data.returnValues.errorType}</p>").wcfDialog
title: WCF.Language.get 'wcf.global.error.title'
do $('#timsChatInput').enable().focus
do refreshRoomList
else
showError WCF.Language.get 'chat.error.join', data
after: ->
isJoining = no

View File

@ -38,6 +38,13 @@ class RoomAddForm extends \wcf\form\AbstractForm {
*/
public $topic = '';
/**
* Maximum number of users
*
* @var integer
*/
public $maxUsers = 0;
/**
* @see \wcf\page\AbstractPage::__construct()
*/
@ -67,6 +74,7 @@ public function readFormParameters() {
if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title');
if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic');
if (isset($_POST['maxUsers']) $this->maxUsers = intval($_POST['maxUsers']);
}
/**
@ -90,7 +98,8 @@ public function save() {
// save room
$this->objectAction = new \chat\data\room\RoomAction(array(), 'create', array('data' => array_merge($this->additionalFields, array(
'title' => $this->title,
'topic' => $this->topic
'topic' => $this->topic,
'maxUsers' => $this->maxUsers
))));
$this->objectAction->executeAction();
$returnValues = $this->objectAction->getReturnValues();
@ -116,7 +125,7 @@ public function save() {
}
\wcf\system\acl\ACLHandler::getInstance()->save($roomID, $this->objectTypeID);
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
\chat\system\permission\PermissionHandler::clearCache();
$this->saved();
@ -144,6 +153,7 @@ public function assignVariables() {
'action' => 'add',
'title' => $this->title,
'topic' => $this->topic,
'maxUsers' => $this->maxUsers,
'objectTypeID' => $this->objectTypeID
));
}

View File

@ -83,13 +83,14 @@ public function save() {
}
\wcf\system\acl\ACLHandler::getInstance()->save($this->roomID, $this->objectTypeID);
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
\chat\system\permission\PermissionHandler::clearCache();
// update room
$this->objectAction = new \chat\data\room\RoomAction(array($this->roomID), 'update', array('data' => array_merge($this->additionalFields, array(
'title' => $this->title,
'topic' => $this->topic
'topic' => $this->topic,
'maxUsers' => $this->maxUsers
))));
$this->objectAction->executeAction();
@ -113,6 +114,7 @@ public function readData() {
$this->title = $this->roomObj->title;
$this->topic = $this->roomObj->topic;
$this->maxUsers = $this->roomObj->maxUsers;
}
}

View File

@ -147,6 +147,7 @@ public function getRoomList() {
'roomID' => (int) $room->roomID,
'active' => $this->parameters['room'] && $room->roomID == $this->parameters['room']->roomID,
'userCount' => count($room->getUsers()),
'maxUsers' => (int) $room->maxUsers,
'permissions' => array(
'canBan' => (boolean) $room->canBan(),
'canMute' => (boolean) $room->canMute()
@ -169,6 +170,12 @@ public function validateJoin() {
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new exception\UserInputException('roomID');
if (!$room->canEnter()) throw new exception\PermissionDeniedException();
if ($room->maxUsers && count($room->getUsers()) >= $room->maxUsers) {
$errorMessage = WCF::getLanguage()->getDynamicVariable('chat.global.error.join.full', array('room' => $room));
throw new exception\UserInputException('room', $errorMessage);
}
}
/**
@ -260,6 +267,7 @@ public function join() {
)),
'roomID' => (int) $room->roomID,
'userCount' => count($room->getUsers()),
'maxUsers' => (int) $room->maxUsers,
'permissions' => array(
'canBan' => (boolean) $room->canBan(),
'canMute' => (boolean) $room->canMute()

View File

@ -38,6 +38,7 @@ CREATE TABLE chat1_room (
showOrder INT(10) NOT NULL DEFAULT 0,
permanent TINYINT(1) NOT NULL DEFAULT 1,
owner INT(10) DEFAULT NULL,
maxUsers INT(10) NOT NULL DEFAULT 0
KEY (showOrder),
KEY (owner)

View File

@ -161,6 +161,8 @@ Probieren Sie, den Chat neu zu laden<!-- , bei Risiken und Nebenwirkungen fragen
<item name="chat.global.rooms"><![CDATA[Chaträume]]></item>
<item name="chat.global.users"><![CDATA[Nutzer]]></item>
<item name="chat.global.error.join.full"><![CDATA[Der Raum „{$room}“ hat die maximale Anzahl an Mitgliedern erreicht. Bitte versuchen Sie es später erneut.]]></item>
<item name="chat.global.copyright"><![CDATA[<a href="http://tims.bastelstu.be"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}><strong>Tims Chat{if SHOW_VERSION_NUMBER} {PACKAGE_VERSION}{/if}</strong>, entwickelt in <strong>Tims Bastelstu.be</strong></a>]]></item>
<item name="chat.global.copyright.leader"><![CDATA[Projektleiter]]></item>
<item name="chat.global.copyright.developer"><![CDATA[Entwickler]]></item>

View File

@ -161,6 +161,8 @@ Please try to reload the chat.]]></item>
<item name="chat.global.rooms"><![CDATA[Chatrooms]]></item>
<item name="chat.global.users"><![CDATA[Users]]></item>
<item name="chat.global.error.join.full"><![CDATA[The room “{$room}” has reached the maximum amount of concurrent chatters. Please try again later.]]></item>
<item name="chat.global.copyright"><![CDATA[<a href="http://tims.bastelstu.be"{if EXTERNAL_LINK_TARGET_BLANK} target="_blank"{/if}><strong>Tims Chat{if SHOW_VERSION_NUMBER} {PACKAGE_VERSION}{/if}</strong>, developed in <strong>Tims Bastelstu.be</strong></a>]]></item>
<item name="chat.global.copyright.leader"><![CDATA[Project Lead]]></item>
<item name="chat.global.copyright.developer"><![CDATA[Developers]]></item>

View File

@ -6,7 +6,7 @@
<div>
<div>
<div class="containerHeadline">
<h3><a href="{link application='chat' controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}</span></h3>
<h3><a href="{link application='chat' controller='Chat' object=$room}{/link}">{$room}</a> <span class="badge">{#$users|count}{if $room->maxUsers} / {#$room->maxUsers}{/if}</span></h3>
<p>{$room->topic|language}</p>
</div>

View File

@ -4,7 +4,7 @@
<title>{if $room}{$room} - {/if}{lang}chat.global.title{/lang} - {PAGE_TITLE|language}</title>
{include file='headInclude'}
{if $room}
{if $room && (!$room->maxUsers || $room->getUsers()|count < $room->maxUsers)}
{include file='javascriptInclude' application='chat'}
<script data-relocate="true">
//<![CDATA[
@ -94,7 +94,7 @@
</head>
<body id="tpl{$templateName|ucfirst}">
{if $room}
{if $room && (!$room->maxUsers || $room->getUsers()|count < $room->maxUsers)}
{capture assign='sidebar'}{include application='chat' file='sidebar'}{/capture}
{include file='header' sandbox=false sidebarOrientation='right'}
@ -225,6 +225,10 @@
{include file='userNotice'}
{if $room && ($room->getUsers()|count >= $room->maxUsers)}
<p class="warning">{lang room=$room}chat.global.error.join.full{/lang}</p>
{/if}
<div id="chatRoomListContainer" class="container marginTop">
<ul class="containerList">
{include application='chat' file='boxRoomList' showEmptyRooms=true}