1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10: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} {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"> <dl id="groupPermissions">
<dt>{lang}wcf.acl.permissions{/lang}</dt> <dt>{lang}wcf.acl.permissions{/lang}</dt>
<dd></dd> <dd></dd>

View File

@ -962,7 +962,7 @@ Fetch the roomlist from the server and update it in the GUI.
roomList = roomList =
active: {} active: {}
available: {} available: {}
do $('.timsChatRoom').remove do $('.timsChatRoom').remove
$('#toggleRooms .badge').text data.returnValues.length $('#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.available[room.roomID] = room
roomList.active = room if room.active roomList.active = room if room.active
li = $ '<li></li>' li = $ '<li />'
li.addClass 'timsChatRoom' li.addClass 'timsChatRoom'
li.addClass 'active' if room.active li.addClass 'active' if room.active
a = $("""<a href="#{room.link}">#{WCF.String.escapeHTML(room.title)}</a>""") a = $("""<a href="#{room.link}">#{WCF.String.escapeHTML(room.title)}</a>""")
a.data 'roomID', room.roomID a.data 'roomID', room.roomID
a.appendTo li 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 $('#timsChatRoomList ul').append li
if window.history?.replaceState? if window.history?.replaceState?
$('.timsChatRoom a').click (event) -> $('.timsChatRoom a').click (event) ->
do event.preventDefault do event.preventDefault
@ -991,7 +997,7 @@ Fetch the roomlist from the server and update it in the GUI.
join target.data 'roomID' join target.data 'roomID'
$('#timsChatRoomList .active').removeClass 'active' $('#timsChatRoomList .active').removeClass 'active'
target.parent().addClass 'active' target.parent().addClass 'active'
console.log "Found #{data.returnValues.length} rooms" console.log "Found #{data.returnValues.length} rooms"
Shows an unrecoverable error with the given text. Shows an unrecoverable error with the given text.
@ -1036,6 +1042,7 @@ Joins a room.
className: 'chat\\data\\room\\RoomAction' className: 'chat\\data\\room\\RoomAction'
parameters: parameters:
roomID: roomID roomID: roomID
suppressErrors: true
success: (data) -> success: (data) ->
loading = false loading = false
roomList.active = data.returnValues roomList.active = data.returnValues
@ -1056,7 +1063,19 @@ Joins a room.
do $('#timsChatInput').enable().focus do $('#timsChatInput').enable().focus
failure: (data) -> 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: -> after: ->
isJoining = no isJoining = no

View File

@ -38,6 +38,13 @@ class RoomAddForm extends \wcf\form\AbstractForm {
*/ */
public $topic = ''; public $topic = '';
/**
* Maximum number of users
*
* @var integer
*/
public $maxUsers = 0;
/** /**
* @see \wcf\page\AbstractPage::__construct() * @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('title')) $this->title = I18nHandler::getInstance()->getValue('title');
if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic'); 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 // save room
$this->objectAction = new \chat\data\room\RoomAction(array(), 'create', array('data' => array_merge($this->additionalFields, array( $this->objectAction = new \chat\data\room\RoomAction(array(), 'create', array('data' => array_merge($this->additionalFields, array(
'title' => $this->title, 'title' => $this->title,
'topic' => $this->topic 'topic' => $this->topic,
'maxUsers' => $this->maxUsers
)))); ))));
$this->objectAction->executeAction(); $this->objectAction->executeAction();
$returnValues = $this->objectAction->getReturnValues(); $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()->save($roomID, $this->objectTypeID);
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables(); \wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
\chat\system\permission\PermissionHandler::clearCache(); \chat\system\permission\PermissionHandler::clearCache();
$this->saved(); $this->saved();
@ -144,6 +153,7 @@ public function assignVariables() {
'action' => 'add', 'action' => 'add',
'title' => $this->title, 'title' => $this->title,
'topic' => $this->topic, 'topic' => $this->topic,
'maxUsers' => $this->maxUsers,
'objectTypeID' => $this->objectTypeID '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()->save($this->roomID, $this->objectTypeID);
\wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables(); \wcf\system\acl\ACLHandler::getInstance()->disableAssignVariables();
\chat\system\permission\PermissionHandler::clearCache(); \chat\system\permission\PermissionHandler::clearCache();
// update room // update room
$this->objectAction = new \chat\data\room\RoomAction(array($this->roomID), 'update', array('data' => array_merge($this->additionalFields, array( $this->objectAction = new \chat\data\room\RoomAction(array($this->roomID), 'update', array('data' => array_merge($this->additionalFields, array(
'title' => $this->title, 'title' => $this->title,
'topic' => $this->topic 'topic' => $this->topic,
'maxUsers' => $this->maxUsers
)))); ))));
$this->objectAction->executeAction(); $this->objectAction->executeAction();
@ -113,6 +114,7 @@ public function readData() {
$this->title = $this->roomObj->title; $this->title = $this->roomObj->title;
$this->topic = $this->roomObj->topic; $this->topic = $this->roomObj->topic;
$this->maxUsers = $this->roomObj->maxUsers;
} }
} }

View File

@ -147,6 +147,7 @@ public function getRoomList() {
'roomID' => (int) $room->roomID, 'roomID' => (int) $room->roomID,
'active' => $this->parameters['room'] && $room->roomID == $this->parameters['room']->roomID, 'active' => $this->parameters['room'] && $room->roomID == $this->parameters['room']->roomID,
'userCount' => count($room->getUsers()), 'userCount' => count($room->getUsers()),
'maxUsers' => (int) $room->maxUsers,
'permissions' => array( 'permissions' => array(
'canBan' => (boolean) $room->canBan(), 'canBan' => (boolean) $room->canBan(),
'canMute' => (boolean) $room->canMute() 'canMute' => (boolean) $room->canMute()
@ -169,6 +170,12 @@ public function validateJoin() {
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new exception\UserInputException('roomID'); if ($room === null) throw new exception\UserInputException('roomID');
if (!$room->canEnter()) throw new exception\PermissionDeniedException(); 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, 'roomID' => (int) $room->roomID,
'userCount' => count($room->getUsers()), 'userCount' => count($room->getUsers()),
'maxUsers' => (int) $room->maxUsers,
'permissions' => array( 'permissions' => array(
'canBan' => (boolean) $room->canBan(), 'canBan' => (boolean) $room->canBan(),
'canMute' => (boolean) $room->canMute() 'canMute' => (boolean) $room->canMute()

View File

@ -38,6 +38,7 @@ CREATE TABLE chat1_room (
showOrder INT(10) NOT NULL DEFAULT 0, showOrder INT(10) NOT NULL DEFAULT 0,
permanent TINYINT(1) NOT NULL DEFAULT 1, permanent TINYINT(1) NOT NULL DEFAULT 1,
owner INT(10) DEFAULT NULL, owner INT(10) DEFAULT NULL,
maxUsers INT(10) NOT NULL DEFAULT 0
KEY (showOrder), KEY (showOrder),
KEY (owner) 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.rooms"><![CDATA[Chaträume]]></item>
<item name="chat.global.users"><![CDATA[Nutzer]]></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"><![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.leader"><![CDATA[Projektleiter]]></item>
<item name="chat.global.copyright.developer"><![CDATA[Entwickler]]></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.rooms"><![CDATA[Chatrooms]]></item>
<item name="chat.global.users"><![CDATA[Users]]></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"><![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.leader"><![CDATA[Project Lead]]></item>
<item name="chat.global.copyright.developer"><![CDATA[Developers]]></item> <item name="chat.global.copyright.developer"><![CDATA[Developers]]></item>

View File

@ -6,7 +6,7 @@
<div> <div>
<div> <div>
<div class="containerHeadline"> <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> <p>{$room->topic|language}</p>
</div> </div>

View File

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