diff --git a/acptemplate/roomAdd.tpl b/acptemplate/roomAdd.tpl index 0946c98..7414a6c 100644 --- a/acptemplate/roomAdd.tpl +++ b/acptemplate/roomAdd.tpl @@ -71,6 +71,22 @@ {include file='multipleLanguageInputJavascript' elementIdentifier='topic' forceSelection=false} + +
+
+ + {if $errorField == 'topic'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}chat.acp.room.topic.error.{@$errorType}{/lang} + {/if} + + {/if} +
+ +
{lang}wcf.acl.permissions{/lang}
diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 081b0fb..1c1849e 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -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.addClass 'timsChatRoom' li.addClass 'active' if room.active a = $("""#{WCF.String.escapeHTML(room.title)}""") a.data 'roomID', room.roomID a.appendTo li - $("""#{WCF.String.formatNumeric room.userCount}""").appendTo li + + 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? + + $('
    ').attr('id', 'timsChatJoinErrorDialog').append("

    #{data.returnValues.errorType}

    ").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 diff --git a/file/lib/acp/form/RoomAddForm.class.php b/file/lib/acp/form/RoomAddForm.class.php index 76f3c56..f875891 100644 --- a/file/lib/acp/form/RoomAddForm.class.php +++ b/file/lib/acp/form/RoomAddForm.class.php @@ -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 )); } diff --git a/file/lib/acp/form/RoomEditForm.class.php b/file/lib/acp/form/RoomEditForm.class.php index 44381b3..f8aa15e 100644 --- a/file/lib/acp/form/RoomEditForm.class.php +++ b/file/lib/acp/form/RoomEditForm.class.php @@ -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; } } diff --git a/file/lib/data/room/RoomAction.class.php b/file/lib/data/room/RoomAction.class.php index 8ba22aa..dd9e4bd 100644 --- a/file/lib/data/room/RoomAction.class.php +++ b/file/lib/data/room/RoomAction.class.php @@ -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() diff --git a/install.sql b/install.sql index 66d416b..91df76c 100644 --- a/install.sql +++ b/install.sql @@ -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) diff --git a/language/de.xml b/language/de.xml index a432414..e2597a8 100644 --- a/language/de.xml +++ b/language/de.xml @@ -161,6 +161,8 @@ Probieren Sie, den Chat neu zu laden