1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-16 16:30:09 +00:00

Reformat PHP files as PSR-12

This commit is contained in:
Tim Düsterhus 2022-03-04 18:10:24 +01:00
parent 1a5c76500b
commit 00167fc6ed
Signed by: TimWolla
GPG Key ID: 8FF75566094168AF
115 changed files with 7658 additions and 5810 deletions

View File

@ -1,21 +1,25 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
* or later of the General Public License. * or later of the General Public License.
*/ */
use \wcf\system\box\BoxHandler; use wcf\system\box\BoxHandler;
BoxHandler::getInstance()->createBoxCondition( 'be.bastelstu.chat.roomListDashboard' BoxHandler::getInstance()->createBoxCondition(
, 'be.bastelstu.chat.box.roomList.condition' 'be.bastelstu.chat.roomListDashboard',
, 'be.bastelstu.chat.roomFilled' 'be.bastelstu.chat.box.roomList.condition',
, [ 'chatRoomIsFilled' => 1 ] 'be.bastelstu.chat.roomFilled',
[
'chatRoomIsFilled' => 1,
]
); );

View File

@ -1,35 +1,44 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
* or later of the General Public License. * or later of the General Public License.
*/ */
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use wcf\data\object\type\ObjectTypeCache;
$objectTypeID = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.chatUpdate'); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
'be.bastelstu.chat.messageType.chatUpdate'
);
if ($objectTypeID) { if ($objectTypeID) {
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => null (new MessageAction(
, 'userID' => null [ ],
, 'username' => '' 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ ]) 'roomID' => null,
'userID' => null,
'username' => '',
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([ ]),
],
] ]
] ))->executeAction();
)
)->executeAction();
} }
$CHATCore = file_get_contents(__DIR__.'/../lib/system/CHATCore.class.php'); $CHATCore = \file_get_contents(__DIR__ . '/../lib/system/CHATCore.class.php');
if (strpos($CHATCore, 'chat.phar.php') === false) { if (\strpos($CHATCore, 'chat.phar.php') === false) {
@unlink(__DIR__.'/../chat.phar.php'); @\unlink(__DIR__ . '/../chat.phar.php');
} }

View File

@ -1,18 +1,19 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
* or later of the General Public License. * or later of the General Public License.
*/ */
define('RELATIVE_CHAT_DIR', '../'); \define('RELATIVE_CHAT_DIR', '../');
require_once(RELATIVE_CHAT_DIR . '/config.inc.php'); require_once(RELATIVE_CHAT_DIR . '/config.inc.php');
require_once(RELATIVE_WCF_DIR . 'acp/global.php'); require_once(RELATIVE_WCF_DIR . 'acp/global.php');

View File

@ -1,16 +1,20 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
* or later of the General Public License. * or later of the General Public License.
*/ */
use wcf\system\request\RequestHandler;
require('./global.php'); require('./global.php');
\wcf\system\request\RequestHandler::getInstance()->handle('chat', true);
RequestHandler::getInstance()->handle('chat', true);

View File

@ -1,16 +1,17 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
* or later of the General Public License. * or later of the General Public License.
*/ */
require_once(dirname(__FILE__).'/config.inc.php'); require_once(__DIR__ . '/config.inc.php');
require_once(RELATIVE_WCF_DIR . 'global.php'); require_once(RELATIVE_WCF_DIR . 'global.php');

View File

@ -1,16 +1,20 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
* or later of the General Public License. * or later of the General Public License.
*/ */
use wcf\system\request\RequestHandler;
require('./global.php'); require('./global.php');
\wcf\system\request\RequestHandler::getInstance()->handle('chat');
RequestHandler::getInstance()->handle('chat');

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,17 +15,19 @@
namespace chat\acp\form; namespace chat\acp\form;
use \chat\data\command\CommandCache; use chat\data\command\CommandList;
use \chat\data\command\CommandTrigger; use chat\data\command\CommandTrigger;
use \chat\data\command\CommandTriggerAction; use chat\data\command\CommandTriggerAction;
use \chat\data\command\CommandTriggerEditor; use wcf\form\AbstractForm;
use \wcf\system\exception\UserInputException; use wcf\system\exception\UserInputException;
use \wcf\system\WCF; use wcf\system\WCF;
use wcf\util\StringUtil;
/** /**
* Shows the command trigger add form. * Shows the command trigger add form.
*/ */
class CommandTriggerAddForm extends \wcf\form\AbstractForm { class CommandTriggerAddForm extends AbstractForm
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -33,7 +36,9 @@ class CommandTriggerAddForm extends \wcf\form\AbstractForm {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $neededPermissions = [ 'admin.chat.canManageTriggers' ]; public $neededPermissions = [
'admin.chat.canManageTriggers',
];
/** /**
* The new trigger for the specified command * The new trigger for the specified command
@ -52,7 +57,7 @@ class CommandTriggerAddForm extends \wcf\form\AbstractForm {
* *
* @param Command * @param Command
*/ */
public $command = null; public $command;
/** /**
* The fully qualified name of the command * The fully qualified name of the command
@ -63,8 +68,9 @@ class CommandTriggerAddForm extends \wcf\form\AbstractForm {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
$commandList = new \chat\data\command\CommandList(); {
$commandList = new CommandList();
$commandList->sqlOrderBy = 'command.className'; $commandList->sqlOrderBy = 'command.className';
$commandList->readObjects(); $commandList->readObjects();
@ -76,17 +82,23 @@ public function readData() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readFormParameters() { public function readFormParameters()
{
parent::readFormParameters(); parent::readFormParameters();
if (isset($_POST['commandTrigger'])) $this->commandTrigger = \wcf\util\StringUtil::trim($_POST['commandTrigger']); if (isset($_POST['commandTrigger'])) {
if (isset($_POST['className'])) $this->className = \wcf\util\StringUtil::trim($_POST['className']); $this->commandTrigger = StringUtil::trim($_POST['commandTrigger']);
}
if (isset($_POST['className'])) {
$this->className = StringUtil::trim($_POST['className']);
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate() { public function validate()
{
parent::validate(); parent::validate();
if (empty($this->commandTrigger)) { if (empty($this->commandTrigger)) {
@ -94,13 +106,16 @@ public function validate() {
} }
// Triggers must not contain whitespace // Triggers must not contain whitespace
if (preg_match('~\s~', $this->commandTrigger)) { if (\preg_match('~\s~', $this->commandTrigger)) {
throw new UserInputException('commandTrigger', 'invalid'); throw new UserInputException('commandTrigger', 'invalid');
} }
// Check for duplicates // Check for duplicates
$trigger = CommandTrigger::getTriggerByName($this->commandTrigger); $trigger = CommandTrigger::getTriggerByName($this->commandTrigger);
if ((!isset($this->trigger) && $trigger->triggerID) || (isset($this->trigger) && $trigger->triggerID != $this->trigger->triggerID)) { if (
(!isset($this->trigger) && $trigger->triggerID)
|| (isset($this->trigger) && $trigger->triggerID != $this->trigger->triggerID)
) {
throw new UserInputException('commandTrigger', 'duplicate'); throw new UserInputException('commandTrigger', 'duplicate');
} }
@ -124,15 +139,26 @@ public function validate() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function save() { public function save()
{
parent::save(); parent::save();
$fields = [ 'commandTrigger' => $this->commandTrigger $fields = [
, 'commandID' => $this->command->commandID 'commandTrigger' => $this->commandTrigger,
'commandID' => $this->command->commandID,
]; ];
// create room // create room
$this->objectAction = new \chat\data\command\CommandTriggerAction([ ], 'create', [ 'data' => array_merge($this->additionalFields, $fields) ]); $this->objectAction = new CommandTriggerAction(
[ ],
'create',
[
'data' => \array_merge(
$this->additionalFields,
$fields
),
]
);
$this->objectAction->executeAction(); $this->objectAction->executeAction();
$this->saved(); $this->saved();
@ -147,13 +173,15 @@ public function save() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
WCF::getTPL()->assign([ 'action' => 'add' WCF::getTPL()->assign([
, 'commandTrigger' => $this->commandTrigger 'action' => 'add',
, 'className' => $this->className 'commandTrigger' => $this->commandTrigger,
, 'availableCommands' => $this->commands 'className' => $this->className,
'availableCommands' => $this->commands,
]); ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,17 +15,18 @@
namespace chat\acp\form; namespace chat\acp\form;
use \chat\data\command\CommandTrigger; use chat\data\command\CommandList;
use \chat\data\command\CommandTriggerAction; use chat\data\command\CommandTrigger;
use \chat\data\command\CommandTriggerEditor; use chat\data\command\CommandTriggerAction;
use \wcf\system\exception\IllegalLinkException; use wcf\form\AbstractForm;
use \wcf\system\exception\UserInputException; use wcf\system\exception\IllegalLinkException;
use \wcf\system\WCF; use wcf\system\WCF;
/** /**
* Shows the command trigger edit form. * Shows the command trigger edit form.
*/ */
class CommandTriggerEditForm extends CommandTriggerAddForm { class CommandTriggerEditForm extends CommandTriggerAddForm
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -42,13 +44,16 @@ class CommandTriggerEditForm extends CommandTriggerAddForm {
* *
* @param CommandTrigger * @param CommandTrigger
*/ */
public $trigger = null; public $trigger;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readParameters() { public function readParameters()
if (isset($_REQUEST['id'])) $this->triggerID = intval($_REQUEST['id']); {
if (isset($_REQUEST['id'])) {
$this->triggerID = \intval($_REQUEST['id']);
}
$this->trigger = new CommandTrigger($this->triggerID); $this->trigger = new CommandTrigger($this->triggerID);
if (!$this->trigger) { if (!$this->trigger) {
@ -61,16 +66,17 @@ public function readParameters() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
{
parent::readData(); parent::readData();
if (empty($_POST)) { if (empty($_POST)) {
$commandList = new \chat\data\command\CommandList(); $commandList = new CommandList();
$commandList->getConditionBuilder()->add('command.commandID = ?', [ $this->trigger->commandID ]); $commandList->getConditionBuilder()->add('command.commandID = ?', [ $this->trigger->commandID ]);
$commandList->readObjects(); $commandList->readObjects();
$commands = $commandList->getObjects(); $commands = $commandList->getObjects();
if (!count($commands)) { if (!\count($commands)) {
throw new IllegalLinkException(); throw new IllegalLinkException();
} }
@ -82,15 +88,28 @@ public function readData() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function save() { public function save()
\wcf\form\AbstractForm::save(); {
AbstractForm::save();
$fields = [ 'commandTrigger' => $this->commandTrigger $fields = [
, 'commandID' => $this->command->commandID 'commandTrigger' => $this->commandTrigger,
'commandID' => $this->command->commandID,
]; ];
// update trigger // update trigger
$this->objectAction = new CommandTriggerAction([ $this->trigger ], 'update', [ 'data' => array_merge($this->additionalFields, $fields) ]); $this->objectAction = new CommandTriggerAction(
[
$this->trigger,
],
'update',
[
'data' => \array_merge(
$this->additionalFields,
$fields
),
]
);
$this->objectAction->executeAction(); $this->objectAction->executeAction();
$this->saved(); $this->saved();
@ -102,11 +121,13 @@ public function save() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
WCF::getTPL()->assign([ 'action' => 'edit' WCF::getTPL()->assign([
, 'triggerID' => $this->trigger->triggerID 'action' => 'edit',
'triggerID' => $this->trigger->triggerID,
]); ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,18 +15,21 @@
namespace chat\acp\form; namespace chat\acp\form;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\room\RoomAction; use chat\data\room\RoomAction;
use \chat\data\room\RoomEditor; use chat\data\room\RoomEditor;
use \wcf\system\acl\ACLHandler; use wcf\data\package\PackageCache;
use \wcf\system\exception\UserInputException; use wcf\form\AbstractForm;
use \wcf\system\language\I18nHandler; use wcf\system\acl\ACLHandler;
use \wcf\system\WCF; use wcf\system\exception\UserInputException;
use wcf\system\language\I18nHandler;
use wcf\system\WCF;
/** /**
* Shows the room add form. * Shows the room add form.
*/ */
class RoomAddForm extends \wcf\form\AbstractForm { class RoomAddForm extends AbstractForm
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -34,7 +38,9 @@ class RoomAddForm extends \wcf\form\AbstractForm {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $neededPermissions = [ 'admin.chat.canManageRoom' ]; public $neededPermissions = [
'admin.chat.canManageRoom',
];
/** /**
* Object type ID of the ACL object type for rooms. * Object type ID of the ACL object type for rooms.
@ -69,7 +75,8 @@ class RoomAddForm extends \wcf\form\AbstractForm {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readParameters() { public function readParameters()
{
parent::readParameters(); parent::readParameters();
I18nHandler::getInstance()->register('title'); I18nHandler::getInstance()->register('title');
@ -81,31 +88,40 @@ public function readParameters() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readFormParameters() { public function readFormParameters()
{
parent::readFormParameters(); parent::readFormParameters();
// read i18n values // read i18n values
I18nHandler::getInstance()->readValues(); I18nHandler::getInstance()->readValues();
// handle i18n plain input // handle i18n plain input
if (I18nHandler::getInstance()->isPlainValue('title')) $this->title = I18nHandler::getInstance()->getValue('title'); if (I18nHandler::getInstance()->isPlainValue('title')) {
if (I18nHandler::getInstance()->isPlainValue('topic')) $this->topic = I18nHandler::getInstance()->getValue('topic'); $this->title = I18nHandler::getInstance()->getValue('title');
if (isset($_POST['userLimit'])) $this->userLimit = intval($_POST['userLimit']); }
if (isset($_POST['topicUseHtml'])) $this->topicUseHtml = true; if (I18nHandler::getInstance()->isPlainValue('topic')) {
$this->topic = I18nHandler::getInstance()->getValue('topic');
}
if (isset($_POST['userLimit'])) {
$this->userLimit = \intval($_POST['userLimit']);
}
if (isset($_POST['topicUseHtml'])) {
$this->topicUseHtml = true;
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate() { public function validate()
{
parent::validate(); parent::validate();
// validate title // validate title
if (!I18nHandler::getInstance()->validateValue('title')) { if (!I18nHandler::getInstance()->validateValue('title')) {
if (I18nHandler::getInstance()->isPlainValue('title')) { if (I18nHandler::getInstance()->isPlainValue('title')) {
throw new UserInputException('title'); throw new UserInputException('title');
} } else {
else {
throw new UserInputException('title', 'multilingual'); throw new UserInputException('title', 'multilingual');
} }
} }
@ -115,7 +131,7 @@ public function validate() {
throw new UserInputException('topic'); throw new UserInputException('topic');
} }
if (mb_strlen($this->topic) > 10000) { if (\mb_strlen($this->topic) > 10000) {
throw new UserInputException('topic', 'tooLong'); throw new UserInputException('topic', 'tooLong');
} }
@ -127,22 +143,39 @@ public function validate() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function save() { public function save()
{
parent::save(); parent::save();
$fields = [ 'title' => $this->title $fields = [
, 'topic' => $this->topic 'title' => $this->title,
, 'topicUseHtml' => (int) $this->topicUseHtml 'topic' => $this->topic,
, 'userLimit' => $this->userLimit 'topicUseHtml' => (int)$this->topicUseHtml,
, 'position' => 0 // TODO 'userLimit' => $this->userLimit,
'position' => 0, // TODO
]; ];
// create room // create room
$this->objectAction = new \chat\data\room\RoomAction([], 'create', [ 'data' => array_merge($this->additionalFields, $fields) ]); $this->objectAction = new RoomAction(
[ ],
'create',
[
'data' => \array_merge(
$this->additionalFields,
$fields
),
]
);
$returnValues = $this->objectAction->executeAction(); $returnValues = $this->objectAction->executeAction();
// save i18n values // save i18n values
$this->saveI18nValue($returnValues['returnValues'], [ 'title', 'topic' ]); $this->saveI18nValue(
$returnValues['returnValues'],
[
'title',
'topic',
]
);
// save ACL // save ACL
ACLHandler::getInstance()->save($returnValues['returnValues']->roomID, $this->aclObjectTypeID); ACLHandler::getInstance()->save($returnValues['returnValues']->roomID, $this->aclObjectTypeID);
@ -167,24 +200,25 @@ public function save() {
* @param Room $room * @param Room $room
* @param string[] $columns * @param string[] $columns
*/ */
public function saveI18nValue(Room $room, $columns) { public function saveI18nValue(Room $room, $columns)
{
$data = [ ]; $data = [ ];
foreach ($columns as $columnName) { foreach ($columns as $columnName) {
$languageItem = 'chat.room.room' . $room->roomID . '.' . $columnName; $languageItem = 'chat.room.room' . $room->roomID . '.' . $columnName;
if (I18nHandler::getInstance()->isPlainValue($columnName)) { if (I18nHandler::getInstance()->isPlainValue($columnName)) {
if ($room->$columnName === $languageItem) { if ($room->{$columnName} === $languageItem) {
I18nHandler::getInstance()->remove($languageItem); I18nHandler::getInstance()->remove($languageItem);
} }
} } else {
else { $packageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat');
$packageID = \wcf\data\package\PackageCache::getInstance()->getPackageID('be.bastelstu.chat');
I18nHandler::getInstance()->save( $columnName I18nHandler::getInstance()->save(
, $languageItem $columnName,
, 'chat.room' $languageItem,
, $packageID 'chat.room',
$packageID
); );
$data[$columnName] = $languageItem; $data[$columnName] = $languageItem;
@ -199,17 +233,18 @@ public function saveI18nValue(Room $room, $columns) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
ACLHandler::getInstance()->assignVariables($this->aclObjectTypeID); ACLHandler::getInstance()->assignVariables($this->aclObjectTypeID);
I18nHandler::getInstance()->assignVariables(); I18nHandler::getInstance()->assignVariables();
WCF::getTPL()->assign([ 'action' => 'add' WCF::getTPL()->assign([
, 'aclObjectTypeID' => $this->aclObjectTypeID 'action' => 'add',
, 'userLimit' => $this->userLimit 'aclObjectTypeID' => $this->aclObjectTypeID,
, 'topicUseHtml' => $this->topicUseHtml 'userLimit' => $this->userLimit,
'topicUseHtml' => $this->topicUseHtml,
]); ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,16 +15,20 @@
namespace chat\acp\form; namespace chat\acp\form;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\room\RoomAction; use chat\data\room\RoomAction;
use \wcf\system\acl\ACLHandler; use wcf\data\package\PackageCache;
use \wcf\system\language\I18nHandler; use wcf\form\AbstractForm;
use \wcf\system\WCF; use wcf\system\acl\ACLHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\language\I18nHandler;
use wcf\system\WCF;
/** /**
* Shows the room edit form. * Shows the room edit form.
*/ */
class RoomEditForm extends RoomAddForm { class RoomEditForm extends RoomAddForm
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -41,13 +46,16 @@ class RoomEditForm extends RoomAddForm {
* *
* @param Room * @param Room
*/ */
public $room = null; public $room;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readParameters() { public function readParameters()
if (isset($_REQUEST['id'])) $this->roomID = intval($_REQUEST['id']); {
if (isset($_REQUEST['id'])) {
$this->roomID = \intval($_REQUEST['id']);
}
$this->room = new Room($this->roomID); $this->room = new Room($this->roomID);
if (!$this->room) { if (!$this->room) {
@ -60,13 +68,24 @@ public function readParameters() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
{
parent::readData(); parent::readData();
if (empty($_POST)) { if (empty($_POST)) {
$packageID = \wcf\data\package\PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); $packageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat');
I18nHandler::getInstance()->setOptions('title', $packageID, $this->room->title, 'chat.room.room\d+.title'); I18nHandler::getInstance()->setOptions(
I18nHandler::getInstance()->setOptions('topic', $packageID, $this->room->topic, 'chat.room.room\d+.topic'); 'title',
$packageID,
$this->room->title,
'chat.room.room\d+.title'
);
I18nHandler::getInstance()->setOptions(
'topic',
$packageID,
$this->room->topic,
'chat.room.room\d+.topic'
);
$this->userLimit = $this->room->userLimit; $this->userLimit = $this->room->userLimit;
$this->topicUseHtml = $this->room->topicUseHtml; $this->topicUseHtml = $this->room->topicUseHtml;
} }
@ -75,25 +94,45 @@ public function readData() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function save() { public function save()
\wcf\form\AbstractForm::save(); {
AbstractForm::save();
$fields = [ 'title' => $this->title $fields = [
, 'topic' => $this->topic 'title' => $this->title,
, 'topicUseHtml' => (int) $this->topicUseHtml 'topic' => $this->topic,
, 'userLimit' => $this->userLimit 'topicUseHtml' => (int)$this->topicUseHtml,
, 'position' => 0 // TODO 'userLimit' => $this->userLimit,
'position' => 0, // TODO
]; ];
// update room // update room
$this->objectAction = new RoomAction([ $this->room ], 'update', [ 'data' => array_merge($this->additionalFields, $fields) ]); $this->objectAction = new RoomAction(
[ $this->room ],
'update',
[
'data' => \array_merge(
$this->additionalFields,
$fields
),
]
);
$returnValues = $this->objectAction->executeAction(); $returnValues = $this->objectAction->executeAction();
// save i18n values // save i18n values
$this->saveI18nValue($this->room, [ 'title', 'topic' ]); $this->saveI18nValue(
$this->room,
[
'title',
'topic',
]
);
// save ACL // save ACL
ACLHandler::getInstance()->save($this->room->roomID, $this->aclObjectTypeID); ACLHandler::getInstance()->save(
$this->room->roomID,
$this->aclObjectTypeID
);
$this->saved(); $this->saved();
@ -104,14 +143,16 @@ public function save() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
I18nHandler::getInstance()->assignVariables(!empty($_POST)); I18nHandler::getInstance()->assignVariables(!empty($_POST));
WCF::getTPL()->assign([ 'action' => 'edit' WCF::getTPL()->assign([
, 'roomID' => $this->room->roomID 'action' => 'edit',
, 'room' => $this->room 'roomID' => $this->room->roomID,
'room' => $this->room,
]); ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,14 @@
namespace chat\acp\page; namespace chat\acp\page;
use chat\data\command\CommandTriggerList;
use wcf\page\SortablePage;
/** /**
* Shows the command trigger list. * Shows the command trigger list.
*/ */
class CommandTriggerListPage extends \wcf\page\SortablePage { class CommandTriggerListPage extends SortablePage
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -26,17 +31,23 @@ class CommandTriggerListPage extends \wcf\page\SortablePage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $neededPermissions = [ 'admin.chat.canManageTriggers' ]; public $neededPermissions = [
'admin.chat.canManageTriggers',
];
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $objectListClassName = \chat\data\command\CommandTriggerList::class; public $objectListClassName = CommandTriggerList::class;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $validSortFields = [ 'triggerID', 'commandTrigger', 'className' ]; public $validSortFields = [
'triggerID',
'commandTrigger',
'className',
];
/** /**
* @inheritDoc * @inheritDoc
@ -46,7 +57,8 @@ class CommandTriggerListPage extends \wcf\page\SortablePage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function initObjectList() { protected function initObjectList()
{
parent::initObjectList(); parent::initObjectList();
$this->objectList->sqlSelects = 'command.className'; $this->objectList->sqlSelects = 'command.className';

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,14 @@
namespace chat\acp\page; namespace chat\acp\page;
use chat\data\room\RoomList;
use wcf\page\SortablePage;
/** /**
* Shows the room list. * Shows the room list.
*/ */
class RoomListPage extends \wcf\page\SortablePage { class RoomListPage extends SortablePage
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -26,17 +31,22 @@ class RoomListPage extends \wcf\page\SortablePage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $neededPermissions = [ 'admin.chat.canManageRoom' ]; public $neededPermissions = [
'admin.chat.canManageRoom',
];
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $objectListClassName = \chat\data\room\RoomList::class; public $objectListClassName = RoomList::class;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $validSortFields = [ 'roomID', 'title' ]; public $validSortFields = [
'roomID',
'title',
];
/** /**
* @inheritDoc * @inheritDoc

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,16 +15,22 @@
namespace chat\acp\page; namespace chat\acp\page;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\Suspension; use chat\data\room\RoomList;
use \wcf\data\user\User; use chat\data\suspension\Suspension;
use \wcf\system\WCF; use chat\data\suspension\SuspensionList;
use \wcf\util\StringUtil; use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\User;
use wcf\page\SortablePage;
use wcf\system\cache\runtime\UserRuntimeCache;
use wcf\system\WCF;
use wcf\util\StringUtil;
/** /**
* Shows the suspension list. * Shows the suspension list.
*/ */
class SuspensionListPage extends \wcf\page\SortablePage { class SuspensionListPage extends SortablePage
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -32,17 +39,24 @@ class SuspensionListPage extends \wcf\page\SortablePage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $neededPermissions = [ 'admin.chat.canManageSuspensions' ]; public $neededPermissions = [
'admin.chat.canManageSuspensions',
];
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $objectListClassName = \chat\data\suspension\SuspensionList::class; public $objectListClassName = SuspensionList::class;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public $validSortFields = [ 'suspensionID', 'time', 'expires', 'revoked' ]; public $validSortFields = [
'suspensionID',
'time',
'expires',
'revoked',
];
/** /**
* @inheritDoc * @inheritDoc
@ -58,25 +72,25 @@ class SuspensionListPage extends \wcf\page\SortablePage {
* userID filter * userID filter
* @var int * @var int
*/ */
public $userID = null; public $userID;
/** /**
* roomID filter * roomID filter
* @var int * @var int
*/ */
public $roomID = null; public $roomID;
/** /**
* objectTypeID filter * objectTypeID filter
* @var int * @var int
*/ */
public $objectTypeID = null; public $objectTypeID;
/** /**
* judgeID filter * judgeID filter
* @var int * @var int
*/ */
public $judgeID = null; public $judgeID;
/** /**
* Whether to show expired entries * Whether to show expired entries
@ -88,13 +102,13 @@ class SuspensionListPage extends \wcf\page\SortablePage {
* username filter * username filter
* @var string * @var string
*/ */
public $searchUsername = null; public $searchUsername;
/** /**
* judge's username filter * judge's username filter
* @var string * @var string
*/ */
public $searchJudge = null; public $searchJudge;
/** /**
* Array of available suspension object types * Array of available suspension object types
@ -111,15 +125,26 @@ class SuspensionListPage extends \wcf\page\SortablePage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readParameters() { public function readParameters()
{
parent::readParameters(); parent::readParameters();
if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] !== '') $this->roomID = intval($_REQUEST['roomID']); if (isset($_REQUEST['roomID']) && $_REQUEST['roomID'] !== '') {
if (isset($_REQUEST['userID']) && $_REQUEST['userID'] !== '') $this->userID = intval($_REQUEST['userID']); $this->roomID = \intval($_REQUEST['roomID']);
if (isset($_REQUEST['judgeID']) && $_REQUEST['judgeID'] !== '') $this->judgeID = intval($_REQUEST['judgeID']); }
if (isset($_REQUEST['objectTypeID']) && $_REQUEST['objectTypeID'] !== '') $this->objectTypeID = intval($_REQUEST['objectTypeID']); if (isset($_REQUEST['userID']) && $_REQUEST['userID'] !== '') {
$this->userID = \intval($_REQUEST['userID']);
}
if (isset($_REQUEST['judgeID']) && $_REQUEST['judgeID'] !== '') {
$this->judgeID = \intval($_REQUEST['judgeID']);
}
if (isset($_REQUEST['objectTypeID']) && $_REQUEST['objectTypeID'] !== '') {
$this->objectTypeID = \intval($_REQUEST['objectTypeID']);
}
// Checkboxes need special handling // Checkboxes need special handling
if (!empty($_POST) && !isset($_POST['showExpired'])) $this->showExpired = false; if (!empty($_POST) && !isset($_POST['showExpired'])) {
$this->showExpired = false;
}
if (isset($_POST['searchUsername'])) { if (isset($_POST['searchUsername'])) {
$this->searchUsername = StringUtil::trim($_POST['searchUsername']); $this->searchUsername = StringUtil::trim($_POST['searchUsername']);
@ -127,8 +152,7 @@ public function readParameters() {
if (!empty($this->searchUsername)) { if (!empty($this->searchUsername)) {
$this->userID = User::getUserByUsername($this->searchUsername)->userID; $this->userID = User::getUserByUsername($this->searchUsername)->userID;
} }
} } elseif ($this->userID !== null) {
else if ($this->userID !== null) {
$this->searchUsername = (new User($this->userID))->username; $this->searchUsername = (new User($this->userID))->username;
} }
@ -138,8 +162,7 @@ public function readParameters() {
if (!empty($this->searchJudge)) { if (!empty($this->searchJudge)) {
$this->judgeID = User::getUserByUsername($this->searchJudge)->userID; $this->judgeID = User::getUserByUsername($this->searchJudge)->userID;
} }
} } elseif ($this->judgeID !== null) {
else if ($this->judgeID !== null) {
$this->searchJudge = (new User($this->judgeID))->username; $this->searchJudge = (new User($this->judgeID))->username;
} }
} }
@ -147,17 +170,18 @@ public function readParameters() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
$this->availableObjectTypes = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.suspension'); {
$this->availableObjectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.suspension');
$roomList = new \chat\data\room\RoomList(); $roomList = new RoomList();
$roomList->sqlOrderBy = "room.position"; $roomList->sqlOrderBy = "room.position";
$roomList->readObjects(); $roomList->readObjects();
$this->availableRooms = $roomList->getObjects(); $this->availableRooms = $roomList->getObjects();
parent::readData(); parent::readData();
\wcf\system\cache\runtime\UserRuntimeCache::getInstance()->cacheObjectIDs(array_map(function (Suspension $s) { UserRuntimeCache::getInstance()->cacheObjectIDs(\array_map(static function (Suspension $s) {
return $s->userID; return $s->userID;
}, $this->objectList->getObjects())); }, $this->objectList->getObjects()));
} }
@ -165,17 +189,17 @@ public function readData() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function initObjectList() { protected function initObjectList()
{
parent::initObjectList(); parent::initObjectList();
$this->objectList->sqlSelects .= 'COALESCE(suspension.revoked, suspension.expires, 2147483647) AS expiresSort'; $this->objectList->sqlSelects .= 'COALESCE(suspension.revoked, suspension.expires, 2147483647) AS expiresSort';
if (!empty($this->availableRooms)) { if (!empty($this->availableRooms)) {
$this->objectList->getConditionBuilder()->add('(roomID IN (?) OR roomID IS NULL)', [ array_map(function (Room $room) { $this->objectList->getConditionBuilder()->add('(roomID IN (?) OR roomID IS NULL)', [ \array_map(static function (Room $room) {
return $room->roomID; return $room->roomID;
}, $this->availableRooms) ]); }, $this->availableRooms) ]);
} } else {
else {
$this->objectList->getConditionBuilder()->add('1 = 0'); $this->objectList->getConditionBuilder()->add('1 = 0');
} }
@ -186,8 +210,7 @@ protected function initObjectList() {
if ($this->roomID !== null) { if ($this->roomID !== null) {
if ($this->roomID === 0) { if ($this->roomID === 0) {
$this->objectList->getConditionBuilder()->add('roomID IS NULL'); $this->objectList->getConditionBuilder()->add('roomID IS NULL');
} } else {
else {
$this->objectList->getConditionBuilder()->add('roomID = ?', [ $this->roomID ]); $this->objectList->getConditionBuilder()->add('roomID = ?', [ $this->roomID ]);
} }
} }
@ -208,18 +231,20 @@ protected function initObjectList() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
WCF::getTPL()->assign([ 'userID' => $this->userID WCF::getTPL()->assign([
, 'roomID' => $this->roomID 'userID' => $this->userID,
, 'objectTypeID' => $this->objectTypeID 'roomID' => $this->roomID,
, 'judgeID' => $this->judgeID 'objectTypeID' => $this->objectTypeID,
, 'availableRooms' => $this->availableRooms 'judgeID' => $this->judgeID,
, 'availableObjectTypes' => $this->availableObjectTypes 'availableRooms' => $this->availableRooms,
, 'searchUsername' => $this->searchUsername 'availableObjectTypes' => $this->availableObjectTypes,
, 'searchJudge' => $this->searchJudge 'searchUsername' => $this->searchUsername,
, 'showExpired' => $this->showExpired 'searchJudge' => $this->searchJudge,
'showExpired' => $this->showExpired,
]); ]);
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,27 +15,32 @@
namespace chat\data\command; namespace chat\data\command;
use \wcf\system\WCF; use chat\system\command\ICommand;
use wcf\data\package\PackageCache;
use wcf\data\ProcessibleDatabaseObject;
use wcf\system\WCF;
/** /**
* Represents a chat command. * Represents a chat command.
*/ */
class Command extends \wcf\data\ProcessibleDatabaseObject { class Command extends ProcessibleDatabaseObject
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected static $processorInterface = \chat\system\command\ICommand::class; protected static $processorInterface = ICommand::class;
/** /**
* Returns whether this command has at least one trigger assigned. * Returns whether this command has at least one trigger assigned.
* *
* The default PlainCommand implicitely has one. * The default PlainCommand implicitely has one.
*/ */
public function hasTriggers() { public function hasTriggers()
{
static $chatPackageID = null; static $chatPackageID = null;
if ($chatPackageID === null) { if ($chatPackageID === null) {
$chatPackageID = \wcf\data\package\PackageCache::getInstance()->getPackageID('be.bastelstu.chat'); $chatPackageID = PackageCache::getInstance()->getPackageID('be.bastelstu.chat');
} }
if ($this->packageID === $chatPackageID && $this->identifier === 'plain') { if ($this->packageID === $chatPackageID && $this->identifier === 'plain') {
@ -45,7 +51,10 @@ public function hasTriggers() {
FROM chat1_command_trigger FROM chat1_command_trigger
WHERE commandID = ?"; WHERE commandID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ $this->commandID ]); $statement->execute([
$this->commandID,
]);
return $statement->fetchSingleColumn() > 0; return $statement->fetchSingleColumn() > 0;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,15 @@
namespace chat\data\command; namespace chat\data\command;
use chat\system\cache\builder\CommandCacheBuilder;
use wcf\data\package\Package;
use wcf\system\SingletonFactory;
/** /**
* Manages the command cache. * Manages the command cache.
*/ */
class CommandCache extends \wcf\system\SingletonFactory { class CommandCache extends SingletonFactory
{
/** /**
* list of cached commands * list of cached commands
* @var Command[] * @var Command[]
@ -39,8 +45,9 @@ class CommandCache extends \wcf\system\SingletonFactory {
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function init() { protected function init()
$data = \chat\system\cache\builder\CommandCacheBuilder::getInstance()->getData(); {
$data = CommandCacheBuilder::getInstance()->getData();
$this->commands = $data['commands']; $this->commands = $data['commands'];
$this->packages = $data['packages']; $this->packages = $data['packages'];
@ -53,7 +60,8 @@ protected function init() {
* @param integer $commandID * @param integer $commandID
* @return Command * @return Command
*/ */
public function getCommand($commandID) { public function getCommand($commandID)
{
if (isset($this->commands[$commandID])) { if (isset($this->commands[$commandID])) {
return $this->commands[$commandID]; return $this->commands[$commandID];
} }
@ -67,7 +75,8 @@ public function getCommand($commandID) {
* @param string $trigger * @param string $trigger
* @return Command * @return Command
*/ */
public function getCommandByTrigger($trigger) { public function getCommandByTrigger($trigger)
{
if (isset($this->triggers[$trigger])) { if (isset($this->triggers[$trigger])) {
return $this->commands[$this->triggers[$trigger]]; return $this->commands[$this->triggers[$trigger]];
} }
@ -78,11 +87,11 @@ public function getCommandByTrigger($trigger) {
/** /**
* Returns the command defined by the given package and identifier. * Returns the command defined by the given package and identifier.
* *
* @param \wcf\data\package\Package $package
* @param string $identifier * @param string $identifier
* @return Command * @return Command
*/ */
public function getCommandByPackageAndIdentifier(\wcf\data\package\Package $package, $identifier) { public function getCommandByPackageAndIdentifier(Package $package, $identifier)
{
if (isset($this->packages[$package->packageID][$identifier])) { if (isset($this->packages[$package->packageID][$identifier])) {
return $this->packages[$package->packageID][$identifier]; return $this->packages[$package->packageID][$identifier];
} }
@ -95,7 +104,8 @@ public function getCommandByPackageAndIdentifier(\wcf\data\package\Package $pack
* *
* @return Command[] * @return Command[]
*/ */
public function getCommands() { public function getCommands()
{
return $this->commands; return $this->commands;
} }
@ -104,7 +114,8 @@ public function getCommands() {
* *
* @return int[] * @return int[]
*/ */
public function getTriggers() { public function getTriggers()
{
return $this->triggers; return $this->triggers;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,13 @@
namespace chat\data\command; namespace chat\data\command;
use wcf\data\DatabaseObjectEditor;
/** /**
* Represents a chat command editor. * Represents a chat command editor.
*/ */
class CommandEditor extends \wcf\data\DatabaseObjectEditor { class CommandEditor extends DatabaseObjectEditor
{
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,8 +15,11 @@
namespace chat\data\command; namespace chat\data\command;
use wcf\data\DatabaseObjectList;
/** /**
* Represents a list of chat commands. * Represents a list of chat commands.
*/ */
class CommandList extends \wcf\data\DatabaseObjectList { class CommandList extends DatabaseObjectList
{
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,23 +15,28 @@
namespace chat\data\command; namespace chat\data\command;
use \wcf\system\WCF; use wcf\data\DatabaseObject;
use wcf\system\request\IRouteController;
use wcf\system\WCF;
/** /**
* Represents a chat command trugger. * Represents a chat command trigger.
*/ */
class CommandTrigger extends \wcf\data\DatabaseObject implements \wcf\system\request\IRouteController { class CommandTrigger extends DatabaseObject implements IRouteController
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTitle() { public function getTitle()
{
return $this->commandTrigger; return $this->commandTrigger;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getObjectID() { public function getObjectID()
{
return $this->triggerID; return $this->triggerID;
} }
@ -40,14 +46,17 @@ public function getObjectID() {
* @param string $name * @param string $name
* @return CommandTrigger * @return CommandTrigger
*/ */
public static function getTriggerByName($name) { public static function getTriggerByName($name)
{
$sql = "SELECT * $sql = "SELECT *
FROM chat1_command_trigger FROM chat1_command_trigger
WHERE commandTrigger = ?"; WHERE commandTrigger = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ $name ]); $statement->execute([ $name ]);
$row = $statement->fetchArray(); $row = $statement->fetchArray();
if (!$row) $row = []; if (!$row) {
$row = [];
}
return new self(null, $row); return new self(null, $row);
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,17 +15,24 @@
namespace chat\data\command; namespace chat\data\command;
use wcf\data\AbstractDatabaseObjectAction;
/** /**
* Executes command trigger-related actions. * Executes command trigger-related actions.
*/ */
class CommandTriggerAction extends \wcf\data\AbstractDatabaseObjectAction { class CommandTriggerAction extends AbstractDatabaseObjectAction
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $permissionsDelete = [ 'admin.chat.canManageTriggers' ]; protected $permissionsDelete = [
'admin.chat.canManageTriggers',
];
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $permissionsUpdate = [ 'admin.chat.canManageTriggers' ]; protected $permissionsUpdate = [
'admin.chat.canManageTriggers',
];
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,15 @@
namespace chat\data\command; namespace chat\data\command;
use chat\system\cache\builder\CommandCacheBuilder;
use wcf\data\DatabaseObjectEditor;
use wcf\data\IEditableCachedObject;
/** /**
* Represents a command trigger editor. * Represents a command trigger editor.
*/ */
class CommandTriggerEditor extends \wcf\data\DatabaseObjectEditor implements \wcf\data\IEditableCachedObject { class CommandTriggerEditor extends DatabaseObjectEditor implements IEditableCachedObject
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -26,7 +32,8 @@ class CommandTriggerEditor extends \wcf\data\DatabaseObjectEditor implements \wc
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function resetCache() { public static function resetCache()
\chat\system\cache\builder\CommandCacheBuilder::getInstance()->reset(); {
CommandCacheBuilder::getInstance()->reset();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,7 +15,11 @@
namespace chat\data\command; namespace chat\data\command;
use wcf\data\DatabaseObjectList;
/** /**
* Represents a list command triggers. * Represents a list command triggers.
*/ */
class CommandTriggerList extends \wcf\data\DatabaseObjectList { } class CommandTriggerList extends DatabaseObjectList
{
}

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,9 +15,11 @@
namespace chat\data\message; namespace chat\data\message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\object\type\ObjectType; use chat\data\room\RoomCache;
use \wcf\data\object\type\ObjectTypeCache; use wcf\data\DatabaseObject;
use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
/** /**
* Represents a chat message. * Represents a chat message.
@ -31,15 +34,17 @@
* @property-read integer $hasEmbeddedObjects * @property-read integer $hasEmbeddedObjects
* @property-read integer $isDeleted * @property-read integer $isDeleted
*/ */
class Message extends \wcf\data\DatabaseObject { class Message extends DatabaseObject
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function handleData($data) { protected function handleData($data)
{
parent::handleData($data); parent::handleData($data);
$this->data['payload'] = @unserialize($this->data['payload']); $this->data['payload'] = @\unserialize($this->data['payload']);
if (!is_array($this->data['payload'])) { if (!\is_array($this->data['payload'])) {
$this->data['payload'] = [ ]; $this->data['payload'] = [ ];
} }
} }
@ -47,21 +52,24 @@ protected function handleData($data) {
/** /**
* Returns whether this message already is inside the log. * Returns whether this message already is inside the log.
*/ */
public function isInLog(): bool { public function isInLog(): bool
{
return $this->time < (TIME_NOW - CHAT_ARCHIVE_AFTER); return $this->time < (TIME_NOW - CHAT_ARCHIVE_AFTER);
} }
/** /**
* Returns the message type object of this message. * Returns the message type object of this message.
*/ */
public function getMessageType(): ObjectType { public function getMessageType(): ObjectType
{
return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID);
} }
/** /**
* Returns the chat room that contains this message. * Returns the chat room that contains this message.
*/ */
public function getRoom(): Room { public function getRoom(): Room
return \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); {
return RoomCache::getInstance()->getRoom($this->roomID);
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,45 +15,74 @@
namespace chat\data\message; namespace chat\data\message;
use \chat\data\command\CommandCache; use chat\data\command\CommandCache;
use \chat\data\room\RoomCache; use chat\data\room\RoomCache;
use \wcf\data\object\type\ObjectTypeCache; use chat\data\user\User as ChatUser;
use \wcf\system\attachment\AttachmentHandler; use chat\data\user\UserAction as ChatUserAction;
use \wcf\system\exception\PermissionDeniedException; use chat\system\message\type\IDeletableMessageType;
use \wcf\system\exception\UserInputException; use wcf\data\AbstractDatabaseObjectAction;
use \wcf\system\user\activity\point\UserActivityPointHandler; use wcf\data\object\type\ObjectTypeCache;
use \wcf\system\WCF; use wcf\system\attachment\AttachmentHandler;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\push\PushHandler;
use wcf\system\user\activity\point\UserActivityPointHandler;
use wcf\system\WCF;
/** /**
* Executes chat user-related actions. * Executes chat user-related actions.
*/ */
class MessageAction extends \wcf\data\AbstractDatabaseObjectAction { class MessageAction extends AbstractDatabaseObjectAction
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function create() { public function create()
{
$message = parent::create(); $message = parent::create();
if (isset($this->parameters['updateTimestamp']) && $this->parameters['updateTimestamp']) { if (isset($this->parameters['updateTimestamp']) && $this->parameters['updateTimestamp']) {
$sql = "UPDATE chat1_room_to_user SET lastPush = ? WHERE roomID = ? AND userID = ?"; $sql = "UPDATE chat1_room_to_user
SET lastPush = ?
WHERE roomID = ?
AND userID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW, $message->roomID, $message->userID ]); $statement->execute([
TIME_NOW,
$message->roomID,
$message->userID,
]);
} }
if (isset($this->parameters['grantPoints']) && $this->parameters['grantPoints']) { if (isset($this->parameters['grantPoints']) && $this->parameters['grantPoints']) {
UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.message', $message->messageID, $message->userID); UserActivityPointHandler::getInstance()->fireEvent(
'be.bastelstu.chat.activityPointEvent.message',
$message->messageID,
$message->userID
);
} }
$pushHandler = \wcf\system\push\PushHandler::getInstance(); $pushHandler = PushHandler::getInstance();
if ($pushHandler->isEnabled() && in_array('target:channels', $pushHandler->getFeatureFlags())) { if ($pushHandler->isEnabled() && \in_array('target:channels', $pushHandler->getFeatureFlags())) {
$fastSelect = $message->getMessageType()->getProcessor()->supportsFastSelect(); $fastSelect = $message->getMessageType()->getProcessor()->supportsFastSelect();
if ($fastSelect) { if ($fastSelect) {
$target = [ 'channels' => [ 'be.bastelstu.chat.room-'.$message->roomID ] ]; $target = [
'channels' => [
'be.bastelstu.chat.room-' . $message->roomID,
],
];
} else {
$target = [
'channels' => [
'be.bastelstu.chat',
],
];
} }
else { $pushHandler->sendMessage([
$target = [ 'channels' => [ 'be.bastelstu.chat' ] ]; 'message' => 'be.bastelstu.chat.message',
} 'target' => $target,
$pushHandler->sendMessage([ 'message' => 'be.bastelstu.chat.message'
, 'target' => $target
]); ]);
} }
@ -62,7 +92,8 @@ public function create() {
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validateTrash() { public function validateTrash()
{
// read objects // read objects
if (empty($this->objects)) { if (empty($this->objects)) {
$this->readObjects(); $this->readObjects();
@ -73,10 +104,15 @@ public function validateTrash() {
} }
foreach ($this->getObjects() as $message) { foreach ($this->getObjects() as $message) {
if ($message->isDeleted) continue; if ($message->isDeleted) {
continue;
}
$messageType = $message->getMessageType()->getProcessor(); $messageType = $message->getMessageType()->getProcessor();
if (!($messageType instanceof \chat\system\message\type\IDeletableMessageType) || !$messageType->canDelete($message->getDecoratedObject())) { if (
!($messageType instanceof IDeletableMessageType)
|| !$messageType->canDelete($message->getDecoratedObject())
) {
throw new PermissionDeniedException(); throw new PermissionDeniedException();
} }
} }
@ -87,35 +123,54 @@ public function validateTrash() {
* *
* Note: Contrary to other applications there is no way to undelete a message. * Note: Contrary to other applications there is no way to undelete a message.
*/ */
public function trash() { public function trash()
{
if (empty($this->objects)) { if (empty($this->objects)) {
$this->readObjects(); $this->readObjects();
} }
$data = [ 'isDeleted' => 1 $data = [
'isDeleted' => 1,
]; ];
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.tombstone'); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
'be.bastelstu.chat.messageType.tombstone'
);
if (!$objectTypeID) { if (!$objectTypeID) {
throw new \LogicException('Missing object type'); throw new \LogicException('Missing object type');
} }
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$objectAction = new static($this->getObjects(), 'update', [ 'data' => $data ]); $objectAction = new static(
$this->getObjects(),
'update',
[
'data' => $data,
]
);
$objectAction->executeAction(); $objectAction->executeAction();
foreach ($this->getObjects() as $message) { foreach ($this->getObjects() as $message) {
if ($message->isDeleted) continue; if ($message->isDeleted) {
continue;
}
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $message->roomID (new self(
, 'userID' => null [ ],
, 'username' => '' 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'messageID' => $message->messageID ]) 'roomID' => $message->roomID,
'userID' => null,
'username' => '',
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'messageID' => $message->messageID,
]),
],
] ]
] ))->executeAction();
)
)->executeAction();
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
@ -123,9 +178,12 @@ public function trash() {
/** /**
* Prunes chat messages older than chat_log_archivetime days. * Prunes chat messages older than chat_log_archivetime days.
*/ */
public function prune() { public function prune()
{
// Check whether pruning is disabled. // Check whether pruning is disabled.
if (!CHAT_LOG_ARCHIVETIME) return; if (!CHAT_LOG_ARCHIVETIME) {
return;
}
$sql = "SELECT messageID $sql = "SELECT messageID
FROM chat1_message FROM chat1_message
@ -134,27 +192,42 @@ public function prune() {
$statement->execute([ TIME_NOW - CHAT_LOG_ARCHIVETIME * 86400 ]); $statement->execute([ TIME_NOW - CHAT_LOG_ARCHIVETIME * 86400 ]);
$messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN); $messageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
return call_user_func([$this->className, 'deleteAll'], $messageIDs); return \call_user_func(
[$this->className, 'deleteAll'],
$messageIDs
);
} }
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validatePull() { public function validatePull()
{
$this->readString('sessionID', true); $this->readString('sessionID', true);
if ($this->parameters['sessionID']) { if ($this->parameters['sessionID']) {
$this->parameters['sessionID'] = pack('H*', str_replace('-', '', $this->parameters['sessionID'])); $this->parameters['sessionID'] = \pack(
'H*',
\str_replace('-', '', $this->parameters['sessionID'])
);
} }
$this->readInteger('roomID'); $this->readInteger('roomID');
$this->readBoolean('inLog', true); $this->readBoolean('inLog', true);
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
if (!$room->canSee($user = null, $reason)) throw $reason; throw new UserInputException('roomID');
$user = new \chat\data\user\User(WCF::getUser()); }
if (!$this->parameters['inLog'] && !$user->isInRoom($room)) throw new PermissionDeniedException(); if (!$room->canSee($user = null, $reason)) {
if ($this->parameters['inLog'] && !$room->canSeeLog(null, $reason)) throw $reason; throw $reason;
}
$user = new ChatUser(WCF::getUser());
if (!$this->parameters['inLog'] && !$user->isInRoom($room)) {
throw new PermissionDeniedException();
}
if ($this->parameters['inLog'] && !$room->canSeeLog(null, $reason)) {
throw $reason;
}
$this->readInteger('from', true); $this->readInteger('from', true);
$this->readInteger('to', true); $this->readInteger('to', true);
@ -168,14 +241,19 @@ public function validatePull() {
/** /**
* Pulls messages for the given room. * Pulls messages for the given room.
*/ */
public function pull() { public function pull()
{
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
throw new UserInputException('roomID');
}
if (($sessionID = $this->parameters['sessionID'])) { if (($sessionID = $this->parameters['sessionID'])) {
if (strlen($sessionID) !== 16) throw new UserInputException('sessionID'); if (\strlen($sessionID) !== 16) {
throw new UserInputException('sessionID');
}
(new \chat\data\user\UserAction([], 'clearDeadSessions'))->executeAction(); (new ChatUserAction([], 'clearDeadSessions'))->executeAction();
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
// update timestamp // update timestamp
@ -184,9 +262,9 @@ public function pull() {
WHERE roomID = ? WHERE roomID = ?
AND userID = ?"; AND userID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW $statement->execute([ TIME_NOW,
, $room->roomID $room->roomID,
, WCF::getUser()->userID WCF::getUser()->userID,
]); ]);
$sql = "UPDATE chat1_session $sql = "UPDATE chat1_session
@ -195,24 +273,24 @@ public function pull() {
AND userID = ? AND userID = ?
AND sessionID = ?"; AND sessionID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW $statement->execute([ TIME_NOW,
, $room->roomID $room->roomID,
, WCF::getUser()->userID WCF::getUser()->userID,
, $sessionID $sessionID,
]); ]);
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
// Determine message types supporting fast select // Determine message types supporting fast select
$objectTypes = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'); $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType');
$fastSelect = array_map(function ($item) { $fastSelect = \array_map(static function ($item) {
return $item->objectTypeID; return $item->objectTypeID;
}, array_filter($objectTypes, function ($item) { }, \array_filter($objectTypes, static function ($item) {
return $item->getProcessor()->supportsFastSelect(); return $item->getProcessor()->supportsFastSelect();
})); }));
// Build fast select filter // Build fast select filter
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $condition = new PreparedStatementConditionBuilder();
$condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $room->roomID, $fastSelect, $fastSelect ]); $condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $room->roomID, $fastSelect, $fastSelect ]);
$sortOrder = 'DESC'; $sortOrder = 'DESC';
@ -239,49 +317,58 @@ public function pull() {
$objects = $objectList->getObjects(); $objects = $objectList->getObjects();
$canSeeLog = $room->canSeeLog(); $canSeeLog = $room->canSeeLog();
$messages = array_map(function (Message $item) use ($room) { $messages = \array_map(static function (Message $item) use ($room) {
return new ViewableMessage($item, $room); return new ViewableMessage($item, $room);
}, array_filter($objects, function (Message $message) use ($canSeeLog, $room) { }, \array_filter($objects, function (Message $message) use ($canSeeLog, $room) {
if ($this->parameters['inLog'] || $message->isInLog()) { if ($this->parameters['inLog'] || $message->isInLog()) {
return $canSeeLog && $message->getMessageType()->getProcessor()->canSeeInLog($message, $room); return $canSeeLog && $message->getMessageType()->getProcessor()->canSeeInLog($message, $room);
} } else {
else {
return $message->getMessageType()->getProcessor()->canSee($message, $room); return $message->getMessageType()->getProcessor()->canSee($message, $room);
} }
})); }));
$embeddedObjectMessageIDs = array_map(function ($message) { $embeddedObjectMessageIDs = \array_map(static function ($message) {
return $message->messageID; return $message->messageID;
}, array_filter($messages, function ($message) { }, \array_filter($messages, static function ($message) {
return $message->hasEmbeddedObjects; return $message->hasEmbeddedObjects;
})); }));
if (!empty($embeddedObjectMessageIDs)) { if (!empty($embeddedObjectMessageIDs)) {
// load embedded objects // load embedded objects
\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->loadObjects('be.bastelstu.chat.message', $embeddedObjectMessageIDs); MessageEmbeddedObjectManager::getInstance()->loadObjects('be.bastelstu.chat.message', $embeddedObjectMessageIDs);
} }
return [ 'messages' => $messages return [
, 'from' => $this->parameters['from'] ?: (!empty($objects) ? reset($objects)->messageID : $this->parameters['to'] + 1) 'messages' => $messages,
, 'to' => $this->parameters['to'] ?: (!empty($objects) ? end($objects)->messageID : $this->parameters['from'] - 1) 'from' => $this->parameters['from'] ?: (!empty($objects) ? \reset($objects)->messageID : $this->parameters['to'] + 1),
'to' => $this->parameters['to'] ?: (!empty($objects) ? \end($objects)->messageID : $this->parameters['from'] - 1),
]; ];
} }
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validatePush() { public function validatePush()
{
$this->readInteger('roomID'); $this->readInteger('roomID');
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
if (!$room->canSee($user = null, $reason)) throw $reason; throw new UserInputException('roomID');
$user = new \chat\data\user\User(WCF::getUser()); }
if (!$user->isInRoom($room)) throw new PermissionDeniedException(); if (!$room->canSee($user = null, $reason)) {
throw $reason;
}
$user = new ChatUser(WCF::getUser());
if (!$user->isInRoom($room)) {
throw new PermissionDeniedException();
}
$this->readInteger('commandID'); $this->readInteger('commandID');
$command = CommandCache::getInstance()->getCommand($this->parameters['commandID']); $command = CommandCache::getInstance()->getCommand($this->parameters['commandID']);
if ($command === null) throw new UserInputException('commandID'); if ($command === null) {
throw new UserInputException('commandID');
}
if (!$command->hasTriggers()) { if (!$command->hasTriggers()) {
if (!$command->getProcessor()->allowWithoutTrigger()) { if (!$command->getProcessor()->allowWithoutTrigger()) {
throw new UserInputException('commandID'); throw new UserInputException('commandID');
@ -294,12 +381,17 @@ public function validatePush() {
/** /**
* Pushes a new message into the given room. * Pushes a new message into the given room.
*/ */
public function push() { public function push()
{
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
throw new UserInputException('roomID');
}
$command = CommandCache::getInstance()->getCommand($this->parameters['commandID']); $command = CommandCache::getInstance()->getCommand($this->parameters['commandID']);
if ($command === null) throw new UserInputException('commandID'); if ($command === null) {
throw new UserInputException('commandID');
}
$processor = $command->getProcessor(); $processor = $command->getProcessor();
$processor->validate($this->parameters['parameters'], $room); $processor->validate($this->parameters['parameters'], $room);
@ -309,16 +401,25 @@ public function push() {
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validatePushAttachment() { public function validatePushAttachment()
{
$this->readInteger('roomID'); $this->readInteger('roomID');
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
if (!$room->canSee($user = null, $reason)) throw $reason; throw new UserInputException('roomID');
$user = new \chat\data\user\User(WCF::getUser()); }
if (!$user->isInRoom($room)) throw new PermissionDeniedException(); if (!$room->canSee($user = null, $reason)) {
throw $reason;
}
$user = new ChatUser(WCF::getUser());
if (!$user->isInRoom($room)) {
throw new PermissionDeniedException();
}
if (!$room->canWritePublicly(null, $reason)) throw $reason; if (!$room->canWritePublicly(null, $reason)) {
throw $reason;
}
$this->readString('tmpHash'); $this->readString('tmpHash');
} }
@ -326,45 +427,63 @@ public function validatePushAttachment() {
/** /**
* Pushes a new attachment into the given room. * Pushes a new attachment into the given room.
*/ */
public function pushAttachment() { public function pushAttachment()
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.attachment'); {
if (!$objectTypeID) throw new \LogicException('Missing object type'); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
'be.bastelstu.chat.messageType.attachment'
);
if (!$objectTypeID) {
throw new \LogicException('Missing object type');
}
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
throw new UserInputException('roomID');
}
$attachmentHandler = new AttachmentHandler('be.bastelstu.chat.message', 0, $this->parameters['tmpHash'], $room->roomID); $attachmentHandler = new AttachmentHandler(
'be.bastelstu.chat.message',
0,
$this->parameters['tmpHash'],
$room->roomID
);
$attachments = $attachmentHandler->getAttachmentList(); $attachments = $attachmentHandler->getAttachmentList();
$attachmentIDs = []; $attachmentIDs = [];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
$attachmentIDs[] = $attachment->attachmentID; $attachmentIDs[] = $attachment->attachmentID;
} }
$processor = new \wcf\system\html\input\HtmlInputProcessor(); $processor = new HtmlInputProcessor();
$processor->process(implode(' ', array_map(function ($attachmentID) { $processor->process(\implode(' ', \array_map(static function ($attachmentID) {
return '[attach=' . $attachmentID . ',none,true][/attach]'; return '[attach=' . $attachmentID . ',none,true][/attach]';
}, $attachmentIDs)), 'be.bastelstu.chat.message', 0); }, $attachmentIDs)), 'be.bastelstu.chat.message', 0);
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
/** @var Message $message */ /** @var Message $message */
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID $message = (new self(
, 'userID' => WCF::getUser()->userID [ ],
, 'username' => WCF::getUser()->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'attachmentIDs' => $attachmentIDs 'roomID' => $room->roomID,
, 'message' => $processor->getHtml() 'userID' => WCF::getUser()->userID,
]) 'username' => WCF::getUser()->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'attachmentIDs' => $attachmentIDs,
'message' => $processor->getHtml(),
]),
],
] ]
] ))->executeAction()['returnValues'];
)
)->executeAction()['returnValues'];
$attachmentHandler->updateObjectID($message->messageID); $attachmentHandler->updateObjectID($message->messageID);
$processor->setObjectID($message->messageID); $processor->setObjectID($message->messageID);
if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($processor)) { if (MessageEmbeddedObjectManager::getInstance()->registerObjects($processor)) {
(new MessageEditor($message))->update([ (new MessageEditor($message))->update([
'hasEmbeddedObjects' => 1 'hasEmbeddedObjects' => 1,
]); ]);
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,13 +15,15 @@
namespace chat\data\message; namespace chat\data\message;
use \wcf\system\attachment\AttachmentHandler; use wcf\data\DatabaseObjectEditor;
use \wcf\system\WCF; use wcf\system\attachment\AttachmentHandler;
use wcf\system\WCF;
/** /**
* Represents a chat message editor. * Represents a chat message editor.
*/ */
class MessageEditor extends \wcf\data\DatabaseObjectEditor { class MessageEditor extends DatabaseObjectEditor
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -29,7 +32,8 @@ class MessageEditor extends \wcf\data\DatabaseObjectEditor {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function deleteAll(array $messageIDs = []) { public static function deleteAll(array $messageIDs = [])
{
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$result = parent::deleteAll($messageIDs); $result = parent::deleteAll($messageIDs);

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,8 +15,11 @@
namespace chat\data\message; namespace chat\data\message;
use wcf\data\DatabaseObjectList;
/** /**
* Represents a list of chat messages. * Represents a list of chat messages.
*/ */
class MessageList extends \wcf\data\DatabaseObjectList { class MessageList extends DatabaseObjectList
{
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,18 +15,22 @@
namespace chat\data\message; namespace chat\data\message;
use \wcf\system\request\LinkHandler; use chat\data\room\Room;
use \wcf\system\WCF; use wcf\data\DatabaseObjectDecorator;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
/** /**
* Represents a chat message. * Represents a chat message.
*/ */
class ViewableMessage extends \wcf\data\DatabaseObjectDecorator implements \JsonSerializable { class ViewableMessage extends DatabaseObjectDecorator implements \JsonSerializable
{
protected static $baseClass = Message::class; protected static $baseClass = Message::class;
protected $room = null; protected $room;
public function __construct(Message $message, \chat\data\room\Room $room) { public function __construct(Message $message, Room $room)
{
parent::__construct($message); parent::__construct($message);
$this->room = $room; $this->room = $room;
@ -34,30 +39,35 @@ public function __construct(Message $message, \chat\data\room\Room $room) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function jsonSerialize() { public function jsonSerialize()
$link = LinkHandler::getInstance()->getLink('Log', [ 'application' => 'chat' {
, 'messageid' => $this->messageID $link = LinkHandler::getInstance()->getLink(
, 'object' => $this->room 'Log',
]); [
'application' => 'chat',
'messageid' => $this->messageID,
'object' => $this->room,
]
);
if ($this->isDeleted) { if ($this->isDeleted) {
$payload = false; $payload = false;
$objectType = 'be.bastelstu.chat.messageType.tombstone'; $objectType = 'be.bastelstu.chat.messageType.tombstone';
} } else {
else {
$payload = $this->getMessageType()->getProcessor()->getPayload($this->getDecoratedObject()); $payload = $this->getMessageType()->getProcessor()->getPayload($this->getDecoratedObject());
$objectType = $this->getMessageType()->objectType; $objectType = $this->getMessageType()->objectType;
} }
return [ 'messageID' => $this->messageID return [
, 'userID' => $this->userID 'messageID' => $this->messageID,
, 'username' => $this->username 'userID' => $this->userID,
, 'time' => $this->time 'username' => $this->username,
, 'payload' => $payload 'time' => $this->time,
, 'objectType' => $objectType 'payload' => $payload,
, 'link' => $link 'objectType' => $objectType,
, 'isIgnored' => WCF::getUserProfileHandler()->isIgnoredUser($this->userID) 'link' => $link,
, 'isDeleted' => (bool) $this->isDeleted 'isIgnored' => WCF::getUserProfileHandler()->isIgnoredUser($this->userID),
'isDeleted' => (bool)$this->isDeleted,
]; ];
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,12 +15,17 @@
namespace chat\data\room; namespace chat\data\room;
use \chat\system\cache\runtime\UserRuntimeCache; use chat\system\cache\runtime\UserRuntimeCache as ChatUserRuntimeCache;
use \chat\system\permission\PermissionHandler; use chat\system\permission\PermissionHandler;
use \wcf\system\exception\PermissionDeniedException; use wcf\data\DatabaseObject;
use \wcf\system\request\LinkHandler; use wcf\data\ITitledLinkObject;
use \wcf\system\WCF; use wcf\data\user\UserProfile;
use \wcf\util\StringUtil; use wcf\system\event\EventHandler;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\request\IRouteController;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\StringUtil;
/** /**
* Represents a chat room. * Represents a chat room.
@ -33,18 +39,21 @@
* @property-read integer $ownerID * @property-read integer $ownerID
* @property-read integer $topicUseHtml * @property-read integer $topicUseHtml
*/ */
final class Room extends \wcf\data\DatabaseObject implements \wcf\system\request\IRouteController final class Room extends DatabaseObject implements
, \wcf\data\ITitledLinkObject IRouteController,
, \JsonSerializable { ITitledLinkObject,
\JsonSerializable
{
/** /**
* @var ?(integer[]) * @var ?(integer[])
*/ */
private static $userToRoom = null; private static $userToRoom;
/** /**
* @see Room::getTitle() * @see Room::getTitle()
*/ */
public function __toString() { public function __toString()
{
return $this->getTitle(); return $this->getTitle();
} }
@ -53,10 +62,13 @@ public function __toString() {
* one chat room. If no user is given the current user * one chat room. If no user is given the current user
* should be assumed * should be assumed
*/ */
public static function canSeeAny(\wcf\data\user\UserProfile $user = null): bool { public static function canSeeAny(?UserProfile $user = null): bool
{
$rooms = RoomCache::getInstance()->getRooms(); $rooms = RoomCache::getInstance()->getRooms();
foreach ($rooms as $room) { foreach ($rooms as $room) {
if ($room->canSee($user)) return true; if ($room->canSee($user)) {
return true;
}
} }
return false; return false;
@ -66,17 +78,23 @@ public static function canSeeAny(\wcf\data\user\UserProfile $user = null): bool
* Returns whether the given user can see this room. * Returns whether the given user can see this room.
* If no user is given the current user should be assumed. * If no user is given the current user should be assumed.
*/ */
public function canSee(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { public function canSee(?UserProfile $user = null, ?\Exception &$reason = null): bool
{
static $cache = [ ]; static $cache = [ ];
if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; if (!isset($cache[$this->roomID])) {
if (array_key_exists($user->userID, $cache[$this->roomID])) { $cache[$this->roomID] = [];
}
if (\array_key_exists($user->userID, $cache[$this->roomID])) {
return ($reason = $cache[$this->roomID][$user->userID]) === null; return ($reason = $cache[$this->roomID][$user->userID]) === null;
} }
if (!$user->userID) { if (!$user->userID) {
$reason = new PermissionDeniedException(); $reason = new PermissionDeniedException();
return ($cache[$this->roomID][$user->userID] = $reason) === null; return ($cache[$this->roomID][$user->userID] = $reason) === null;
} }
@ -85,10 +103,11 @@ public function canSee(\wcf\data\user\UserProfile $user = null, \Exception &$rea
$result = new PermissionDeniedException(); $result = new PermissionDeniedException();
} }
$parameters = [ 'user' => $user $parameters = [
, 'result' => $result 'user' => $user,
'result' => $result,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
$reason = $parameters['result']; $reason = $parameters['result'];
if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) {
@ -102,12 +121,17 @@ public function canSee(\wcf\data\user\UserProfile $user = null, \Exception &$rea
* Returns whether the given user can see the log of this room. * Returns whether the given user can see the log of this room.
* If no user is given the current user should be assumed. * If no user is given the current user should be assumed.
*/ */
public function canSeeLog(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { public function canSeeLog(?UserProfile $user = null, ?\Exception &$reason = null): bool
{
static $cache = [ ]; static $cache = [ ];
if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; if (!isset($cache[$this->roomID])) {
if (array_key_exists($user->userID, $cache[$this->roomID])) { $cache[$this->roomID] = [];
}
if (\array_key_exists($user->userID, $cache[$this->roomID])) {
return ($reason = $cache[$this->roomID][$user->userID]) === null; return ($reason = $cache[$this->roomID][$user->userID]) === null;
} }
@ -116,10 +140,11 @@ public function canSeeLog(\wcf\data\user\UserProfile $user = null, \Exception &$
$result = new PermissionDeniedException(); $result = new PermissionDeniedException();
} }
$parameters = [ 'user' => $user $parameters = [
, 'result' => $result 'user' => $user,
'result' => $result,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeLog', $parameters);
$reason = $parameters['result']; $reason = $parameters['result'];
if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) {
@ -133,19 +158,25 @@ public function canSeeLog(\wcf\data\user\UserProfile $user = null, \Exception &$
* Returns whether the given user can join this room. * Returns whether the given user can join this room.
* If no user is given the current user should be assumed. * If no user is given the current user should be assumed.
*/ */
public function canJoin(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { public function canJoin(?UserProfile $user = null, ?\Exception &$reason = null): bool
{
static $cache = [ ]; static $cache = [ ];
if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; if (!isset($cache[$this->roomID])) {
if (array_key_exists($user->userID, $cache[$this->roomID])) { $cache[$this->roomID] = [];
}
if (\array_key_exists($user->userID, $cache[$this->roomID])) {
return ($reason = $cache[$this->roomID][$user->userID]) === null; return ($reason = $cache[$this->roomID][$user->userID]) === null;
} }
$parameters = [ 'user' => $user $parameters = [
, 'result' => null 'user' => $user,
'result' => null,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canJoin', $parameters); EventHandler::getInstance()->fireAction($this, 'canJoin', $parameters);
$reason = $parameters['result']; $reason = $parameters['result'];
if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) {
@ -159,12 +190,17 @@ public function canJoin(\wcf\data\user\UserProfile $user = null, \Exception &$re
* Returns whether the given user can write public messages in this room. * Returns whether the given user can write public messages in this room.
* If no user is given the current user should be assumed. * If no user is given the current user should be assumed.
*/ */
public function canWritePublicly(\wcf\data\user\UserProfile $user = null, \Exception &$reason = null): bool { public function canWritePublicly(?UserProfile $user = null, ?\Exception &$reason = null): bool
{
static $cache = [ ]; static $cache = [ ];
if ($user === null) $user = new \wcf\data\user\UserProfile(WCF::getUser()); if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!isset($cache[$this->roomID])) $cache[$this->roomID] = []; if (!isset($cache[$this->roomID])) {
if (array_key_exists($user->userID, $cache[$this->roomID])) { $cache[$this->roomID] = [];
}
if (\array_key_exists($user->userID, $cache[$this->roomID])) {
return ($reason = $cache[$this->roomID][$user->userID]) === null; return ($reason = $cache[$this->roomID][$user->userID]) === null;
} }
@ -173,10 +209,11 @@ public function canWritePublicly(\wcf\data\user\UserProfile $user = null, \Excep
$result = new PermissionDeniedException(); $result = new PermissionDeniedException();
} }
$parameters = [ 'user' => $user $parameters = [
, 'result' => $result 'user' => $user,
'result' => $result,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canWritePublicly', $parameters); EventHandler::getInstance()->fireAction($this, 'canWritePublicly', $parameters);
$reason = $parameters['result']; $reason = $parameters['result'];
if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) { if (!($reason === null || $reason instanceof \Exception || $reason instanceof \Throwable)) {
@ -189,14 +226,16 @@ public function canWritePublicly(\wcf\data\user\UserProfile $user = null, \Excep
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTitle() { public function getTitle()
{
return WCF::getLanguage()->get($this->title); return WCF::getLanguage()->get($this->title);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getTopic() { public function getTopic()
{
$topic = StringUtil::trim(WCF::getLanguage()->get($this->topic)); $topic = StringUtil::trim(WCF::getLanguage()->get($this->topic));
if (!$this->topicUseHtml) { if (!$this->topicUseHtml) {
@ -209,9 +248,11 @@ public function getTopic() {
/** /**
* Returns an array of users in this room. * Returns an array of users in this room.
*/ */
public function getUsers() { public function getUsers()
{
if (self::$userToRoom === null) { if (self::$userToRoom === null) {
$sql = "SELECT r2u.userID, r2u.roomID $sql = "SELECT r2u.userID,
r2u.roomID
FROM chat1_room_to_user r2u FROM chat1_room_to_user r2u
INNER JOIN wcf1_user u INNER JOIN wcf1_user u
ON r2u.userID = u.userID ON r2u.userID = u.userID
@ -222,22 +263,28 @@ public function getUsers() {
self::$userToRoom = $statement->fetchMap('roomID', 'userID', false); self::$userToRoom = $statement->fetchMap('roomID', 'userID', false);
if (!empty(self::$userToRoom)) { if (!empty(self::$userToRoom)) {
UserRuntimeCache::getInstance()->cacheObjectIDs(array_merge(...self::$userToRoom)); ChatUserRuntimeCache::getInstance()->cacheObjectIDs(\array_merge(...self::$userToRoom));
} }
} }
if (!isset(self::$userToRoom[$this->roomID])) return [ ]; if (!isset(self::$userToRoom[$this->roomID])) {
return [ ];
}
return UserRuntimeCache::getInstance()->getObjects(self::$userToRoom[$this->roomID]); return ChatUserRuntimeCache::getInstance()->getObjects(self::$userToRoom[$this->roomID]);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getLink() { public function getLink()
return LinkHandler::getInstance()->getLink('Room', [ 'application' => 'chat' {
, 'object' => $this return LinkHandler::getInstance()->getLink(
, 'forceFrontend' => true 'Room',
[
'application' => 'chat',
'object' => $this,
'forceFrontend' => true,
] ]
); );
} }
@ -245,10 +292,12 @@ public function getLink() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function jsonSerialize() { public function jsonSerialize()
return [ 'title' => $this->getTitle() {
, 'topic' => $this->getTopic() return [
, 'link' => $this->getLink() 'title' => $this->getTitle(),
'topic' => $this->getTopic(),
'link' => $this->getLink(),
]; ];
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,89 +15,137 @@
namespace chat\data\room; namespace chat\data\room;
use \chat\data\user\User as ChatUser; use chat\data\command\CommandCache;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \wcf\data\object\type\ObjectTypeCache; use chat\data\user\User as ChatUser;
use \wcf\system\cache\runtime\UserProfileRuntimeCache; use chat\data\user\UserAction as ChatUserAction;
use \wcf\system\database\util\PreparedStatementConditionBuilder; use chat\system\box\RoomListBoxController;
use \wcf\system\exception\PermissionDeniedException; use wcf\data\AbstractDatabaseObjectAction;
use \wcf\system\exception\UserInputException; use wcf\data\box\Box;
use \wcf\system\user\activity\point\UserActivityPointHandler; use wcf\data\ISortableAction;
use \wcf\system\WCF; use wcf\data\object\type\ObjectTypeCache;
use wcf\data\package\PackageCache;
use wcf\data\user\UserProfile;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\event\EventHandler;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
use wcf\system\push\PushHandler;
use wcf\system\user\activity\point\UserActivityPointHandler;
use wcf\system\WCF;
/** /**
* Executes chat room-related actions. * Executes chat room-related actions.
*/ */
class RoomAction extends \wcf\data\AbstractDatabaseObjectAction implements \wcf\data\ISortableAction { class RoomAction extends AbstractDatabaseObjectAction implements ISortableAction
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $permissionsDelete = [ 'admin.chat.canManageRoom' ]; protected $permissionsDelete = [
'admin.chat.canManageRoom',
];
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $permissionsUpdate = [ 'admin.chat.canManageRoom' ]; protected $permissionsUpdate = [
'admin.chat.canManageRoom',
];
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validateJoin() { public function validateJoin()
{
unset($this->parameters['user']); unset($this->parameters['user']);
$this->readString('sessionID'); $this->readString('sessionID');
$this->parameters['sessionID'] = pack('H*', str_replace('-', '', $this->parameters['sessionID'])); $this->parameters['sessionID'] = \pack(
'H*',
\str_replace('-', '', $this->parameters['sessionID'])
);
$this->readInteger('roomID'); $this->readInteger('roomID');
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
if (!$room->canSee($user = null, $reason)) throw $reason; throw new UserInputException('roomID');
if (!$room->canJoin($user = null, $reason)) throw $reason; }
if (!$room->canSee($user = null, $reason)) {
throw $reason;
}
if (!$room->canJoin($user = null, $reason)) {
throw $reason;
}
} }
/** /**
* Makes the given user join the current chat room. * Makes the given user join the current chat room.
*/ */
public function join() { public function join()
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.join'); {
if (!$objectTypeID) throw new \LogicException('Missing object type'); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
'be.bastelstu.chat.messageType.join'
);
if (!$objectTypeID) {
throw new \LogicException('Missing object type');
}
// User cannot be set during an AJAX request, but may be set by Tims Chat itself. // User cannot be set during an AJAX request, but may be set by Tims Chat itself.
if (!isset($this->parameters['user'])) $this->parameters['user'] = WCF::getUser(); if (!isset($this->parameters['user'])) {
$this->parameters['user'] = WCF::getUser();
}
$user = new ChatUser($this->parameters['user']); $user = new ChatUser($this->parameters['user']);
// Check parameters // Check parameters
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
throw new UserInputException('roomID');
}
$sessionID = $this->parameters['sessionID']; $sessionID = $this->parameters['sessionID'];
if (strlen($sessionID) !== 16) throw new UserInputException('sessionID'); if (\strlen($sessionID) !== 16) {
throw new UserInputException('sessionID');
}
try { try {
// Create room_to_user mapping. // Create room_to_user mapping.
$sql = "INSERT INTO chat1_room_to_user (active, roomID, userID) VALUES (?, ?, ?)"; $sql = "INSERT INTO chat1_room_to_user
(active, roomID, userID)
VALUES (?, ?, ?)";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ 0, $room->roomID, $user->userID ]); $statement->execute([ 0, $room->roomID, $user->userID ]);
} } catch (\wcf\system\database\exception\DatabaseException $e) {
catch (\wcf\system\database\exception\DatabaseException $e) {
// Ignore if there already is a mapping. // Ignore if there already is a mapping.
if ((string) $e->getCode() !== '23000') throw $e; if ((string)$e->getCode() !== '23000') {
throw $e;
}
} }
try { try {
$sql = "INSERT INTO chat1_session (roomID, userID, sessionID, lastRequest) VALUES (?, ?, ?, ?)"; $sql = "INSERT INTO chat1_session
(roomID, userID, sessionID, lastRequest)
VALUES (?, ?, ?, ?)";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ $room->roomID, $user->userID, $sessionID, TIME_NOW ]); $statement->execute([
$room->roomID,
$user->userID,
$sessionID,
TIME_NOW,
]);
} catch (\wcf\system\database\exception\DatabaseException $e) {
if ((string)$e->getCode() !== '23000') {
throw $e;
} }
catch (\wcf\system\database\exception\DatabaseException $e) {
if ((string) $e->getCode() !== '23000') throw $e;
throw new UserInputException('sessionID'); throw new UserInputException('sessionID');
} }
$markAsBack = function () use ($user, $room) { $markAsBack = static function () use ($user, $room) {
$userProfile = new \wcf\data\user\UserProfile($user->getDecoratedObject()); $userProfile = new UserProfile($user->getDecoratedObject());
$package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); $package = PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat');
$command = \chat\data\command\CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'back'); $command = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'back');
$processor = $command->getProcessor(); $processor = $command->getProcessor();
$processor->execute([ ], $room, $userProfile); $processor->execute([ ], $room, $userProfile);
}; };
@ -106,7 +155,10 @@ public function join() {
} }
// Attempt to mark the user as active in the room. // Attempt to mark the user as active in the room.
$sql = "UPDATE chat1_room_to_user SET active = ? WHERE roomID = ? AND userID = ?"; $sql = "UPDATE chat1_room_to_user
SET active = ?
WHERE roomID = ?
AND userID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ 1, $room->roomID, $user->userID ]); $statement->execute([ 1, $room->roomID, $user->userID ]);
if ($statement->getAffectedRows() === 0) { if ($statement->getAffectedRows() === 0) {
@ -115,40 +167,58 @@ public function join() {
} }
// Update lastPull. This must not be merged into the above query, because of the 'getAffectedRows' check. // Update lastPull. This must not be merged into the above query, because of the 'getAffectedRows' check.
$sql = "UPDATE chat1_room_to_user SET lastPull = ? WHERE roomID = ? AND userID = ?"; $sql = "UPDATE chat1_room_to_user
SET lastPull = ?
WHERE roomID = ?
AND userID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW, $room->roomID, $user->userID ]); $statement->execute([ TIME_NOW, $room->roomID, $user->userID ]);
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([ ]),
],
] ]
] ))->executeAction();
)
)->executeAction();
UserActivityPointHandler::getInstance()->fireEvent('be.bastelstu.chat.activityPointEvent.join', 0, $user->userID); UserActivityPointHandler::getInstance()->fireEvent(
$pushHandler = \wcf\system\push\PushHandler::getInstance(); 'be.bastelstu.chat.activityPointEvent.join',
$pushHandler->sendMessage([ 'message' => 'be.bastelstu.chat.join' 0,
, 'target' => 'registered' $user->userID
);
$pushHandler = PushHandler::getInstance();
$pushHandler->sendMessage([
'message' => 'be.bastelstu.chat.join',
'target' => 'registered',
]); ]);
} }
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validateLeave() { public function validateLeave()
{
unset($this->parameters['user']); unset($this->parameters['user']);
$this->readString('sessionID'); $this->readString('sessionID');
$this->parameters['sessionID'] = pack('H*', str_replace('-', '', $this->parameters['sessionID'])); $this->parameters['sessionID'] = \pack(
'H*',
\str_replace('-', '', $this->parameters['sessionID'])
);
$this->readInteger('roomID'); $this->readInteger('roomID');
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
throw new UserInputException('roomID');
}
// Do not check permissions: If the user is not inside the room nothing happens, if he is it // Do not check permissions: If the user is not inside the room nothing happens, if he is it
// may lead to a faster eviction of the user. // may lead to a faster eviction of the user.
} }
@ -156,31 +226,41 @@ public function validateLeave() {
/** /**
* Makes the given user leave the current chat room. * Makes the given user leave the current chat room.
*/ */
public function leave() { public function leave()
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', 'be.bastelstu.chat.messageType.leave'); {
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
'be.bastelstu.chat.messageType.leave'
);
if ($objectTypeID) { if ($objectTypeID) {
// User cannot be set during an AJAX request, but may be set by Tims Chat itself. // User cannot be set during an AJAX request, but may be set by Tims Chat itself.
if (!isset($this->parameters['user'])) $this->parameters['user'] = WCF::getUser(); if (!isset($this->parameters['user'])) {
$this->parameters['user'] = WCF::getUser();
}
$user = new ChatUser($this->parameters['user']); $user = new ChatUser($this->parameters['user']);
$room = RoomCache::getInstance()->getRoom($this->parameters['roomID']); $room = RoomCache::getInstance()->getRoom($this->parameters['roomID']);
if ($room === null) throw new UserInputException('roomID'); if ($room === null) {
throw new UserInputException('roomID');
}
$sessionID = null; $sessionID = null;
if (isset($this->parameters['sessionID'])) { if (isset($this->parameters['sessionID'])) {
$sessionID = $this->parameters['sessionID']; $sessionID = $this->parameters['sessionID'];
if (strlen($sessionID) !== 16) throw new UserInputException('sessionID'); if (\strlen($sessionID) !== 16) {
throw new UserInputException('sessionID');
}
} }
// Delete session. // Delete session.
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $condition = new PreparedStatementConditionBuilder();
$condition->add('roomID = ?', [ $room->roomID ]); $condition->add('roomID = ?', [ $room->roomID ]);
$condition->add('userID = ?', [ $user->userID ]); $condition->add('userID = ?', [ $user->userID ]);
if ($sessionID !== null) { if ($sessionID !== null) {
$condition->add('sessionID = ?', [ $sessionID ]); $condition->add('sessionID = ?', [ $sessionID ]);
} }
$sql = "DELETE FROM chat1_session $sql = "DELETE FROM chat1_session
".$condition; {$condition}";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute($condition->getParameters()); $statement->execute($condition->getParameters());
if ($statement->getAffectedRows() === 0) { if ($statement->getAffectedRows() === 0) {
@ -200,38 +280,50 @@ public function leave() {
$statement->execute([ $room->roomID, $user->userID ]); $statement->execute([ $room->roomID, $user->userID ]);
// We did not: Nothing to do here. // We did not: Nothing to do here.
if ($statement->fetchColumn()) return; if ($statement->fetchColumn()) {
return;
}
// Mark the user as inactive. // Mark the user as inactive.
$sql = "UPDATE chat1_room_to_user SET active = ? WHERE roomID = ? AND userID = ?"; $sql = "UPDATE chat1_room_to_user
SET active = ?
WHERE roomID = ?
AND userID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ 0, $room->roomID, $user->userID ]); $statement->execute([ 0, $room->roomID, $user->userID ]);
if ($statement->getAffectedRows() === 0) throw new \LogicException('Unreachable'); if ($statement->getAffectedRows() === 0) {
throw new \LogicException('Unreachable');
}
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
$commited = true; $commited = true;
} finally {
if (!$commited) {
WCF::getDB()->rollBackTransaction();
} }
finally {
if (!$commited) WCF::getDB()->rollBackTransaction();
} }
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([ ]),
],
] ]
] ))->executeAction();
)
)->executeAction();
$pushHandler = \wcf\system\push\PushHandler::getInstance(); $pushHandler = PushHandler::getInstance();
$pushHandler->sendMessage([ 'message' => 'be.bastelstu.chat.leave' $pushHandler->sendMessage([
, 'target' => 'registered' 'message' => 'be.bastelstu.chat.leave',
'target' => 'registered',
]); ]);
} } else {
else {
throw new \LogicException('Missing object type'); throw new \LogicException('Missing object type');
} }
} }
@ -239,46 +331,56 @@ public function leave() {
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validateGetUsers() { public function validateGetUsers()
{
if (empty($this->getObjects())) { if (empty($this->getObjects())) {
$this->readObjects(); $this->readObjects();
} }
if (count($this->getObjects()) !== 1) { if (\count($this->getObjects()) !== 1) {
throw new UserInputException('objectIDs'); throw new UserInputException('objectIDs');
} }
$room = $this->getObjects()[0]; $room = $this->getObjects()[0];
$user = new ChatUser(WCF::getUser()); $user = new ChatUser(WCF::getUser());
if (!$user->isInRoom($room->getDecoratedObject())) throw new PermissionDeniedException(); if (!$user->isInRoom($room->getDecoratedObject())) {
throw new PermissionDeniedException();
}
} }
/** /**
* Returns the userIDs of the users in this room. * Returns the userIDs of the users in this room.
*/ */
public function getUsers() { public function getUsers()
{
if (empty($this->getObjects())) { if (empty($this->getObjects())) {
$this->readObjects(); $this->readObjects();
} }
if (count($this->getObjects()) !== 1) { if (\count($this->getObjects()) !== 1) {
throw new UserInputException('objectIDs'); throw new UserInputException('objectIDs');
} }
$room = $this->getObjects()[0]; $room = $this->getObjects()[0];
$users = (new \chat\data\user\UserAction([ ], 'getUsersByID', [ $users = (new ChatUserAction(
'userIDs' => array_keys($room->getUsers()) [ ],
]))->executeAction()['returnValues']; 'getUsersByID',
[
'userIDs' => \array_keys($room->getUsers()),
]
))->executeAction()['returnValues'];
$users = array_map(function (array $user) use ($room) { $users = \array_map(static function (array $user) use ($room) {
$userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']); $userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']);
if (!isset($user['permissions'])) $user['permissions'] = []; if (!isset($user['permissions'])) {
$user['permissions'] = [];
}
$user['permissions']['canWritePublicly'] = $room->canWritePublicly($userProfile); $user['permissions']['canWritePublicly'] = $room->canWritePublicly($userProfile);
return $user; return $user;
}, $users); }, $users);
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getUsers', $users); EventHandler::getInstance()->fireAction($this, 'getUsers', $users);
return $users; return $users;
} }
@ -286,12 +388,12 @@ public function getUsers() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validateUpdatePosition() { public function validateUpdatePosition()
{
// validate permissions // validate permissions
if (is_array($this->permissionsUpdate) && !empty($this->permissionsUpdate)) { if (\is_array($this->permissionsUpdate) && !empty($this->permissionsUpdate)) {
WCF::getSession()->checkPermissions($this->permissionsUpdate); WCF::getSession()->checkPermissions($this->permissionsUpdate);
} } else {
else {
throw new PermissionDeniedException(); throw new PermissionDeniedException();
} }
@ -302,14 +404,17 @@ public function validateUpdatePosition() {
foreach ($this->parameters['data']['structure'][0] as $roomID) { foreach ($this->parameters['data']['structure'][0] as $roomID) {
$room = $roomList->search($roomID); $room = $roomList->search($roomID);
if ($room === null) throw new UserInputException('structure'); if ($room === null) {
throw new UserInputException('structure');
}
} }
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function updatePosition() { public function updatePosition()
{
$roomList = new RoomList(); $roomList = new RoomList();
$roomList->readObjects(); $roomList->readObjects();
@ -317,10 +422,14 @@ public function updatePosition() {
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
foreach ($this->parameters['data']['structure'][0] as $roomID) { foreach ($this->parameters['data']['structure'][0] as $roomID) {
$room = $roomList->search($roomID); $room = $roomList->search($roomID);
if ($room === null) continue; if ($room === null) {
continue;
}
$editor = new RoomEditor($room); $editor = new RoomEditor($room);
$editor->update([ 'position' => $i++ ]); $editor->update([
'position' => $i++,
]);
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
@ -328,8 +437,11 @@ public function updatePosition() {
/** /**
* Validates permissions. * Validates permissions.
*/ */
public function validateGetBoxRoomList() { public function validateGetBoxRoomList()
if (!\chat\data\room\Room::canSeeAny()) throw new \wcf\system\exception\PermissionDeniedException(); {
if (!Room::canSeeAny()) {
throw new PermissionDeniedException();
}
$this->readBoolean('isSidebar', true); $this->readBoolean('isSidebar', true);
$this->readBoolean('skipEmptyRooms', true); $this->readBoolean('skipEmptyRooms', true);
@ -338,10 +450,10 @@ public function validateGetBoxRoomList() {
unset($this->parameters['boxController']); unset($this->parameters['boxController']);
$this->readInteger('boxID', true); $this->readInteger('boxID', true);
if ($this->parameters['boxID']) { if ($this->parameters['boxID']) {
$box = new \wcf\data\box\Box($this->parameters['boxID']); $box = new Box($this->parameters['boxID']);
if ($box->boxID) { if ($box->boxID) {
$this->parameters['boxController'] = $box->getController(); $this->parameters['boxController'] = $box->getController();
if ($this->parameters['boxController'] instanceof \chat\system\box\RoomListBoxController) { if ($this->parameters['boxController'] instanceof RoomListBoxController) {
// all checks passed, end validation; otherwise throw the exception below // all checks passed, end validation; otherwise throw the exception below
return; return;
} }
@ -354,11 +466,14 @@ public function validateGetBoxRoomList() {
/** /**
* Returns dashboard roomlist. * Returns dashboard roomlist.
*/ */
public function getBoxRoomList() { public function getBoxRoomList()
{
if (isset($this->parameters['boxController'])) { if (isset($this->parameters['boxController'])) {
$this->parameters['boxController']->setActiveRoomID($this->parameters['activeRoomID']); $this->parameters['boxController']->setActiveRoomID($this->parameters['activeRoomID']);
return [ 'template' => $this->parameters['boxController']->getContent() ]; return [
'template' => $this->parameters['boxController']->getContent(),
];
} }
// Fetch all rooms, the templates have filtering in place // Fetch all rooms, the templates have filtering in place
@ -366,11 +481,14 @@ public function getBoxRoomList() {
$template = 'boxRoomList' . ($this->parameters['isSidebar'] ? 'Sidebar' : ''); $template = 'boxRoomList' . ($this->parameters['isSidebar'] ? 'Sidebar' : '');
\wcf\system\WCF::getTPL()->assign([ 'boxRoomList' => $rooms WCF::getTPL()->assign([
, 'skipEmptyRooms' => $this->parameters['skipEmptyRooms'] 'boxRoomList' => $rooms,
, 'activeRoomID' => $this->parameters['activeRoomID'] 'skipEmptyRooms' => $this->parameters['skipEmptyRooms'],
'activeRoomID' => $this->parameters['activeRoomID'],
]); ]);
return [ 'template' => \wcf\system\WCF::getTPL()->fetch($template, 'chat') ]; return [
'template' => WCF::getTPL()->fetch($template, 'chat'),
];
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,12 +15,14 @@
namespace chat\data\room; namespace chat\data\room;
use \wcf\system\WCF; use chat\system\cache\builder\RoomCacheBuilder;
use wcf\system\SingletonFactory;
/** /**
* Manages the room cache. * Manages the room cache.
*/ */
class RoomCache extends \wcf\system\SingletonFactory { class RoomCache extends SingletonFactory
{
/** /**
* List of cached rooms. * List of cached rooms.
* *
@ -37,8 +40,9 @@ class RoomCache extends \wcf\system\SingletonFactory {
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function init() { protected function init()
$this->rooms = \chat\system\cache\builder\RoomCacheBuilder::getInstance()->getData(); {
$this->rooms = RoomCacheBuilder::getInstance()->getData();
} }
/** /**
@ -47,7 +51,8 @@ protected function init() {
* @param integer $roomID * @param integer $roomID
* @return Room * @return Room
*/ */
public function getRoom($roomID) { public function getRoom($roomID)
{
if (isset($this->rooms[$roomID])) { if (isset($this->rooms[$roomID])) {
return $this->rooms[$roomID]; return $this->rooms[$roomID];
} }
@ -60,7 +65,8 @@ public function getRoom($roomID) {
* *
* @return Room[] * @return Room[]
*/ */
public function getRooms() { public function getRooms()
{
return $this->rooms; return $this->rooms;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,16 @@
namespace chat\data\room; namespace chat\data\room;
use chat\system\cache\builder\RoomCacheBuilder;
use chat\system\permission\PermissionHandler;
use wcf\data\DatabaseObjectEditor;
use wcf\data\IEditableCachedObject;
/** /**
* Represents a chat room editor. * Represents a chat room editor.
*/ */
class RoomEditor extends \wcf\data\DatabaseObjectEditor implements \wcf\data\IEditableCachedObject { class RoomEditor extends DatabaseObjectEditor implements IEditableCachedObject
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -26,8 +33,9 @@ class RoomEditor extends \wcf\data\DatabaseObjectEditor implements \wcf\data\IEd
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function resetCache() { public static function resetCache()
\chat\system\cache\builder\RoomCacheBuilder::getInstance()->reset(); {
\chat\system\permission\PermissionHandler::resetCache(); RoomCacheBuilder::getInstance()->reset();
PermissionHandler::resetCache();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,10 +15,13 @@
namespace chat\data\room; namespace chat\data\room;
use wcf\data\DatabaseObjectList;
/** /**
* Represents a list of chat rooms. * Represents a list of chat rooms.
*/ */
class RoomList extends \wcf\data\DatabaseObjectList { class RoomList extends DatabaseObjectList
{
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,24 +15,27 @@
namespace chat\data\suspension; namespace chat\data\suspension;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\User; use chat\data\room\RoomCache;
use \wcf\system\WCF; use wcf\data\DatabaseObject;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\User;
use wcf\system\cache\runtime\UserRuntimeCache;
/** /**
* Represents a chat suspension. * Represents a chat suspension.
*/ */
class Suspension extends \wcf\data\DatabaseObject implements \JsonSerializable { class Suspension extends DatabaseObject implements \JsonSerializable
{
/** /**
* Returns the active suspensions for the given (objectTypeID, Room, User) * Returns the active suspensions for the given (objectTypeID, Room, User)
* triple. * triple.
* *
* @param int $objectTypeID * @param int $objectTypeID
* @param \wcf\data\user\User $user
* @param \chat\data\room\Room $room
* @return \chat\data\suspension\Suspension[] * @return \chat\data\suspension\Suspension[]
*/ */
public static function getActiveSuspensionsByTriple($objectTypeID, User $user, Room $room) { public static function getActiveSuspensionsByTriple($objectTypeID, User $user, Room $room)
{
$suspensionList = new SuspensionList(); $suspensionList = new SuspensionList();
$suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]);
@ -42,7 +46,7 @@ public static function getActiveSuspensionsByTriple($objectTypeID, User $user, R
$suspensionList->readObjects(); $suspensionList->readObjects();
return array_filter($suspensionList->getObjects(), function (Suspension $suspension) { return \array_filter($suspensionList->getObjects(), static function (self $suspension) {
return $suspension->isActive(); return $suspension->isActive();
}); });
} }
@ -52,8 +56,9 @@ public static function getActiveSuspensionsByTriple($objectTypeID, User $user, R
* *
* @return \wcf\data\object\type\ObjectType * @return \wcf\data\object\type\ObjectType
*/ */
public function getSuspensionType() { public function getSuspensionType()
return \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID); {
return ObjectTypeCache::getInstance()->getObjectType($this->objectTypeID);
} }
/** /**
@ -61,11 +66,18 @@ public function getSuspensionType() {
* *
* @return boolean * @return boolean
*/ */
public function isActive() { public function isActive()
if ($this->revoked !== null) return false; {
if (!$this->getSuspensionType()->getProcessor()->hasEffect($this)) return false; if ($this->revoked !== null) {
return false;
}
if (!$this->getSuspensionType()->getProcessor()->hasEffect($this)) {
return false;
}
if ($this->expires === null) return true; if ($this->expires === null) {
return true;
}
return $this->expires > TIME_NOW; return $this->expires > TIME_NOW;
} }
@ -76,12 +88,13 @@ public function isActive() {
* *
* @return \chat\data\room\Room * @return \chat\data\room\Room
*/ */
public function getRoom() { public function getRoom()
{
if ($this->roomID === null) { if ($this->roomID === null) {
return null; return null;
} }
return \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); return RoomCache::getInstance()->getRoom($this->roomID);
} }
/** /**
@ -89,23 +102,26 @@ public function getRoom() {
* *
* @return \wcf\data\user\User * @return \wcf\data\user\User
*/ */
public function getUser() { public function getUser()
return \wcf\system\cache\runtime\UserRuntimeCache::getInstance()->getObject($this->userID); {
return UserRuntimeCache::getInstance()->getObject($this->userID);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function jsonSerialize() { public function jsonSerialize()
return [ 'userID' => $this->userID {
, 'username' => $this->getUser()->username return [
, 'roomID' => $this->roomID 'userID' => $this->userID,
, 'time' => $this->time 'username' => $this->getUser()->username,
, 'expires' => $this->expires 'roomID' => $this->roomID,
, 'reason' => $this->reason 'time' => $this->time,
, 'objectType' => $this->getSuspensionType()->objectType 'expires' => $this->expires,
, 'judgeID' => $this->judgeID 'reason' => $this->reason,
, 'judge' => $this->judge 'objectType' => $this->getSuspensionType()->objectType,
'judgeID' => $this->judgeID,
'judge' => $this->judge,
]; ];
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,21 +15,27 @@
namespace chat\data\suspension; namespace chat\data\suspension;
use \wcf\system\WCF; use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/** /**
* Executes suspension-related actions. * Executes suspension-related actions.
*/ */
class SuspensionAction extends \wcf\data\AbstractDatabaseObjectAction { class SuspensionAction extends AbstractDatabaseObjectAction
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $requireACP = [ 'revoke' ]; protected $requireACP = [
'revoke',
];
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validateRevoke() { public function validateRevoke()
{
if (empty($this->objects)) { if (empty($this->objects)) {
$this->readObjects(); $this->readObjects();
@ -39,30 +46,44 @@ public function validateRevoke() {
unset($this->parameters['revoker']); unset($this->parameters['revoker']);
WCF::getSession()->checkPermissions([ 'admin.chat.canManageSuspensions' ]); WCF::getSession()->checkPermissions([
'admin.chat.canManageSuspensions',
]);
foreach ($this->getObjects() as $object) { foreach ($this->getObjects() as $object) {
if (!$object->isActive()) throw new UserInputException('objectIDs', 'nonActive'); if (!$object->isActive()) {
throw new UserInputException('objectIDs', 'nonActive');
}
} }
} }
/** /**
* Revokes the suspensions * Revokes the suspensions
*/ */
public function revoke() { public function revoke()
{
if (empty($this->objects)) { if (empty($this->objects)) {
$this->readObjects(); $this->readObjects();
} }
// User cannot be set during an AJAX request, but may be set by Tims Chat itself. // User cannot be set during an AJAX request, but may be set by Tims Chat itself.
if (!isset($this->parameters['revoker'])) $this->parameters['revoker'] = WCF::getUser(); if (!isset($this->parameters['revoker'])) {
$this->parameters['revoker'] = WCF::getUser();
}
$data = [ 'revoked' => TIME_NOW $data = [
, 'revokerID' => $this->parameters['revoker']->userID 'revoked' => TIME_NOW,
, 'revoker' => $this->parameters['revoker']->username 'revokerID' => $this->parameters['revoker']->userID,
'revoker' => $this->parameters['revoker']->username,
]; ];
$objectAction = new static($this->getObjects(), 'update', [ 'data' => $data ]); $objectAction = new static(
$this->getObjects(),
'update',
[
'data' => $data,
]
);
$objectAction->executeAction(); $objectAction->executeAction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,10 +15,13 @@
namespace chat\data\suspension; namespace chat\data\suspension;
use wcf\data\DatabaseObjectEditor;
/** /**
* Represents a chat suspension editor. * Represents a chat suspension editor.
*/ */
class SuspensionEditor extends \wcf\data\DatabaseObjectEditor { class SuspensionEditor extends DatabaseObjectEditor
{
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,9 +15,11 @@
namespace chat\data\suspension; namespace chat\data\suspension;
use wcf\data\DatabaseObjectList;
/** /**
* Represents a list of chat suspensions. * Represents a list of chat suspensions.
*/ */
class SuspensionList extends \wcf\data\DatabaseObjectList { class SuspensionList extends DatabaseObjectList
{
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,12 +15,16 @@
namespace chat\data\user; namespace chat\data\user;
use \wcf\system\WCF; use chat\data\room\Room;
use chat\data\room\RoomCache;
use wcf\data\DatabaseObjectDecorator;
use wcf\system\WCF;
/** /**
* Decorates the User object to make it useful in context of Tims Chat. * Decorates the User object to make it useful in context of Tims Chat.
*/ */
class User extends \wcf\data\DatabaseObjectDecorator implements \JsonSerializable { class User extends DatabaseObjectDecorator implements \JsonSerializable
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -30,14 +35,15 @@ class User extends \wcf\data\DatabaseObjectDecorator implements \JsonSerializabl
* *
* @var int[][] * @var int[][]
*/ */
protected $roomToUser = null; protected $roomToUser;
/** /**
* Returns an array of the room_to_user arrays for this user. * Returns an array of the room_to_user arrays for this user.
* *
* @return mixed[] * @return mixed[]
*/ */
public function getRoomAssociations($skipCache = false) { public function getRoomAssociations($skipCache = false)
{
if ($this->roomToUser === null || $skipCache) { if ($this->roomToUser === null || $skipCache) {
$sql = "SELECT * $sql = "SELECT *
FROM chat1_room_to_user FROM chat1_room_to_user
@ -58,10 +64,11 @@ public function getRoomAssociations($skipCache = false) {
* *
* @return \chat\data\room\Room[] * @return \chat\data\room\Room[]
*/ */
public function getRooms($skipCache = false) { public function getRooms($skipCache = false)
return array_map(function ($assoc) { {
return \chat\data\room\RoomCache::getInstance()->getRoom($assoc['roomID']); return \array_map(static function ($assoc) {
}, array_filter($this->getRoomAssociations($skipCache), function ($assoc) { return RoomCache::getInstance()->getRoom($assoc['roomID']);
}, \array_filter($this->getRoomAssociations($skipCache), static function ($assoc) {
return $assoc['active'] === 1; return $assoc['active'] === 1;
})); }));
} }
@ -69,13 +76,16 @@ public function getRooms($skipCache = false) {
/** /**
* Returns whether the user is in the given room. * Returns whether the user is in the given room.
* *
* @param \chat\data\room\Room $room
* @return boolean * @return boolean
*/ */
public function isInRoom(\chat\data\room\Room $room, $skipCache = false) { public function isInRoom(Room $room, $skipCache = false)
{
$assoc = $this->getRoomAssociations($skipCache); $assoc = $this->getRoomAssociations($skipCache);
if (!isset($assoc[$room->roomID])) return false; if (!isset($assoc[$room->roomID])) {
return false;
}
return $assoc[$room->roomID]['active'] === 1; return $assoc[$room->roomID]['active'] === 1;
} }
@ -84,12 +94,17 @@ public function isInRoom(\chat\data\room\Room $room, $skipCache = false) {
* *
* @return mixed[][] * @return mixed[][]
*/ */
public static function getDeadSessions() { public static function getDeadSessions()
$sql = "SELECT userID, roomID, sessionID {
$sql = "SELECT userID,
roomID,
sessionID
FROM chat1_session FROM chat1_session
WHERE lastRequest < ?"; WHERE lastRequest < ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ TIME_NOW - 60 * 3 ]); $statement->execute([
TIME_NOW - 60 * 3,
]);
return $statement->fetchAll(\PDO::FETCH_ASSOC); return $statement->fetchAll(\PDO::FETCH_ASSOC);
} }
@ -97,10 +112,12 @@ public static function getDeadSessions() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function jsonSerialize() { public function jsonSerialize()
return [ 'userID' => $this->userID {
, 'username' => $this->username return [
, 'link' => $this->getLink() 'userID' => $this->userID,
'username' => $this->username,
'link' => $this->getLink(),
]; ];
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,17 +15,20 @@
namespace chat\data\user; namespace chat\data\user;
use \chat\data\room\RoomCache; use chat\data\room\Room;
use \wcf\system\cache\runtime\UserProfileRuntimeCache; use chat\data\room\RoomAction;
use \wcf\system\cache\runtime\UserRuntimeCache; use wcf\data\AbstractDatabaseObjectAction;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\cache\runtime\UserProfileRuntimeCache;
use \wcf\system\exception\UserInputException; use wcf\system\cache\runtime\UserRuntimeCache;
use \wcf\system\WCF; use wcf\system\event\EventHandler;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
/** /**
* Executes chat user-related actions. * Executes chat user-related actions.
*/ */
class UserAction extends \wcf\data\AbstractDatabaseObjectAction { class UserAction extends AbstractDatabaseObjectAction
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -33,8 +37,11 @@ class UserAction extends \wcf\data\AbstractDatabaseObjectAction {
/** /**
* Validates parameters and permissions. * Validates parameters and permissions.
*/ */
public function validateGetUsersByID() { public function validateGetUsersByID()
if (!\chat\data\room\Room::canSeeAny()) throw new PermissionDeniedException(); {
if (!Room::canSeeAny()) {
throw new PermissionDeniedException();
}
$this->readIntegerArray('userIDs'); $this->readIntegerArray('userIDs');
} }
@ -42,30 +49,34 @@ public function validateGetUsersByID() {
/** /**
* Returns information about the users identified by the given userIDs. * Returns information about the users identified by the given userIDs.
*/ */
public function getUsersByID() { public function getUsersByID()
{
$userList = UserProfileRuntimeCache::getInstance()->getObjects($this->parameters['userIDs']); $userList = UserProfileRuntimeCache::getInstance()->getObjects($this->parameters['userIDs']);
return array_map(function ($user) { return \array_map(function ($user) {
if (!$user) return null; if (!$user) {
return null;
}
$payload = [ 'image16' => $user->getAvatar()->getImageTag(16) $payload = [
, 'image24' => $user->getAvatar()->getImageTag(24) 'image16' => $user->getAvatar()->getImageTag(16),
, 'image32' => $user->getAvatar()->getImageTag(32) 'image24' => $user->getAvatar()->getImageTag(24),
, 'image48' => $user->getAvatar()->getImageTag(48) 'image32' => $user->getAvatar()->getImageTag(32),
, 'imageUrl' => $user->getAvatar()->getURL() 'image48' => $user->getAvatar()->getImageTag(48),
, 'link' => $user->getLink() 'imageUrl' => $user->getAvatar()->getURL(),
, 'anchor' => $user->getAnchorTag() 'link' => $user->getLink(),
, 'userID' => $user->userID 'anchor' => $user->getAnchorTag(),
, 'username' => $user->username 'userID' => $user->userID,
, 'userTitle' => $user->getUserTitle() 'username' => $user->username,
, 'userRankClass' => $user->getRank() ? $user->getRank()->cssClassName : null 'userTitle' => $user->getUserTitle(),
, 'formattedUsername' => $user->getFormattedUsername() 'userRankClass' => $user->getRank() ? $user->getRank()->cssClassName : null,
, 'away' => $user->chatAway 'formattedUsername' => $user->getFormattedUsername(),
, 'color1' => $user->chatColor1 'away' => $user->chatAway,
, 'color2' => $user->chatColor2 'color1' => $user->chatColor1,
'color2' => $user->chatColor2,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getUsersByID', $payload); EventHandler::getInstance()->fireAction($this, 'getUsersByID', $payload);
return $payload; return $payload;
}, $userList); }, $userList);
@ -74,22 +85,30 @@ public function getUsersByID() {
/** /**
* Clears dead clients. * Clears dead clients.
*/ */
public function clearDeadSessions() { public function clearDeadSessions()
{
$sessions = User::getDeadSessions(); $sessions = User::getDeadSessions();
if (empty($sessions)) return; if (empty($sessions)) {
$userIDs = array_map(function ($item) { return;
}
$userIDs = \array_map(static function ($item) {
return $item['userID']; return $item['userID'];
}, $sessions); }, $sessions);
$users = UserRuntimeCache::getInstance()->getObjects($userIDs); $users = UserRuntimeCache::getInstance()->getObjects($userIDs);
foreach ($sessions as $session) { foreach ($sessions as $session) {
$parameters = [ 'user' => $users[$session['userID']] $parameters = [
, 'roomID' => $session['roomID'] 'user' => $users[$session['userID']],
, 'sessionID' => $session['sessionID'] 'roomID' => $session['roomID'],
'sessionID' => $session['sessionID'],
]; ];
try { try {
(new \chat\data\room\RoomAction([ ], 'leave', $parameters))->executeAction(); (new RoomAction(
} [ ],
catch (UserInputException $e) { 'leave',
$parameters
))->executeAction();
} catch (UserInputException $e) {
// Probably some other request has been faster to remove this session, ignore // Probably some other request has been faster to remove this session, ignore
} }
} }
@ -98,21 +117,24 @@ public function clearDeadSessions() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function create() { public function create()
{
throw new \BadMethodCallException(); throw new \BadMethodCallException();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function update() { public function update()
{
throw new \BadMethodCallException(); throw new \BadMethodCallException();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function delete() { public function delete()
{
throw new \BadMethodCallException(); throw new \BadMethodCallException();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -17,7 +18,8 @@
/** /**
* Represents a list of chat users. * Represents a list of chat users.
*/ */
class UserList extends \wcf\data\user\UserList { class UserList extends \wcf\data\user\UserList
{
/** /**
* @inheritDoc * @inheritDoc
*/ */

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,16 +15,24 @@
namespace chat\page; namespace chat\page;
use \chat\data\message\MessageList; use chat\data\message\Message;
use \wcf\system\exception\IllegalLinkException; use chat\data\message\MessageList;
use \wcf\system\exception\PermissionDeniedException; use chat\data\room\RoomCache;
use \wcf\system\page\PageLocationManager; use wcf\data\object\type\ObjectTypeCache;
use \wcf\system\WCF; use wcf\page\AbstractPage;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\page\PageLocationManager;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\HeaderUtil;
/** /**
* Shows the log of a specific chat room. * Shows the log of a specific chat room.
*/ */
class LogPage extends \wcf\page\AbstractPage { class LogPage extends AbstractPage
{
use TConfiguredPage; use TConfiguredPage;
/** /**
@ -41,7 +50,7 @@ class LogPage extends \wcf\page\AbstractPage {
* The requested chat room. * The requested chat room.
* @var \chat\data\room\Room * @var \chat\data\room\Room
*/ */
public $room = null; public $room;
/** /**
* The requested message ID. * The requested message ID.
@ -53,7 +62,7 @@ class LogPage extends \wcf\page\AbstractPage {
* The requested message. * The requested message.
* @var \chat\data\message\Message * @var \chat\data\message\Message
*/ */
public $message = null; public $message;
/** /**
* The requested time. * The requested time.
@ -64,39 +73,53 @@ class LogPage extends \wcf\page\AbstractPage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readParameters() { public function readParameters()
{
parent::readParameters(); parent::readParameters();
if (isset($_GET['id'])) $this->roomID = intval($_GET['id']); if (isset($_GET['id'])) {
$this->room = \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); $this->roomID = \intval($_GET['id']);
}
$this->room = RoomCache::getInstance()->getRoom($this->roomID);
if ($this->room === null) throw new IllegalLinkException(); if ($this->room === null) {
if (!$this->room->canSee($user = null, $reason)) throw $reason; throw new IllegalLinkException();
if (!$this->room->canSeeLog($user = null, $reason)) throw $reason; }
if (!$this->room->canSee($user = null, $reason)) {
throw $reason;
}
if (!$this->room->canSeeLog($user = null, $reason)) {
throw $reason;
}
if (isset($_GET['messageid'])) $this->messageID = intval($_GET['messageid']); if (isset($_GET['messageid'])) {
$this->messageID = \intval($_GET['messageid']);
}
if ($this->messageID) { if ($this->messageID) {
$this->message = new \chat\data\message\Message($this->messageID); $this->message = new Message($this->messageID);
if (!$this->message->getMessageType()->getProcessor()->canSeeInLog($this->message, $this->room)) { if (!$this->message->getMessageType()->getProcessor()->canSeeInLog($this->message, $this->room)) {
throw new PermissionDeniedException(); throw new PermissionDeniedException();
} }
} }
if (isset($_REQUEST['datetime'])) $this->datetime = strtotime($_REQUEST['datetime']); if (isset($_REQUEST['datetime'])) {
$this->datetime = \strtotime($_REQUEST['datetime']);
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
{
parent::readData(); parent::readData();
if ($this->datetime) { if ($this->datetime) {
// Determine message types supporting fast select // Determine message types supporting fast select
$objectTypes = \wcf\data\object\type\ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'); $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType');
$fastSelect = array_map(function ($item) { $fastSelect = \array_map(static function ($item) {
return $item->objectTypeID; return $item->objectTypeID;
}, array_filter($objectTypes, function ($item) { }, \array_filter($objectTypes, static function ($item) {
// TODO: Consider a method couldAppearInLog(): bool // TODO: Consider a method couldAppearInLog(): bool
return $item->getProcessor()->supportsFastSelect(); return $item->getProcessor()->supportsFastSelect();
})); }));
@ -105,7 +128,7 @@ public function readData() {
$loops = 0; $loops = 0;
do { do {
// Build fast select filter // Build fast select filter
$condition = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $condition = new PreparedStatementConditionBuilder();
$condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $this->room->roomID, $fastSelect, $fastSelect ]); $condition->add('((roomID = ? AND objectTypeID IN (?)) OR objectTypeID NOT IN (?))', [ $this->room->roomID, $fastSelect, $fastSelect ]);
$condition->add('time >= ?', [ $this->datetime ]); $condition->add('time >= ?', [ $this->datetime ]);
if ($minimum) { if ($minimum) {
@ -114,7 +137,7 @@ public function readData() {
$sql = "SELECT messageID $sql = "SELECT messageID
FROM chat1_message FROM chat1_message
".$condition." {$condition}
ORDER BY messageID ASC"; ORDER BY messageID ASC";
$statement = WCF::getDB()->prepare($sql, 20); $statement = WCF::getDB()->prepare($sql, 20);
$statement->execute($condition->getParameters()); $statement->execute($condition->getParameters());
@ -131,24 +154,27 @@ public function readData() {
foreach ($objects as $message) { foreach ($objects as $message) {
if ($message->getMessageType()->getProcessor()->canSeeInLog($message, $this->room)) { if ($message->getMessageType()->getProcessor()->canSeeInLog($message, $this->room)) {
$parameters = [ 'application' => 'chat' $parameters = [
, 'messageid' => $message->messageID 'application' => 'chat',
, 'object' => $this->room 'messageid' => $message->messageID,
'object' => $this->room,
]; ];
\wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Log', $parameters)); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Log', $parameters));
exit; exit;
} }
$minimum = $message->messageID; $minimum = $message->messageID;
} }
} } while (++$loops <= 3);
while (++$loops <= 3);
// Do a best guess redirect to an ID that is as near as possible // Do a best guess redirect to an ID that is as near as possible
$parameters = [ 'application' => 'chat' $parameters = [
, 'messageid' => $minimum 'application' => 'chat',
, 'object' => $this->room 'messageid' => $minimum,
'object' => $this->room,
]; ];
\wcf\util\HeaderUtil::redirect(\wcf\system\request\LinkHandler::getInstance()->getLink('Log', $parameters)); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Log', $parameters));
exit; exit;
} }
} }
@ -156,15 +182,21 @@ public function readData() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
PageLocationManager::getInstance()->addParentLocation('be.bastelstu.chat.Room', $this->room->roomID, $this->room); PageLocationManager::getInstance()->addParentLocation(
WCF::getTPL()->assign([ 'room' => $this->room 'be.bastelstu.chat.Room',
, 'roomList' => \chat\data\room\RoomCache::getInstance()->getRooms() $this->room->roomID,
, 'messageID' => $this->messageID $this->room
, 'message' => $this->message );
, 'config' => $this->getConfig() WCF::getTPL()->assign([
'room' => $this->room,
'roomList' => RoomCache::getInstance()->getRooms(),
'messageID' => $this->messageID,
'message' => $this->message,
'config' => $this->getConfig(),
]); ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,12 +15,17 @@
namespace chat\page; namespace chat\page;
use \wcf\system\WCF; use chat\data\room\Room;
use chat\data\room\RoomCache;
use wcf\page\AbstractPage;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
/** /**
* Shows the list of available chat rooms. * Shows the list of available chat rooms.
*/ */
class RoomListPage extends \wcf\page\AbstractPage { class RoomListPage extends AbstractPage
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -35,27 +41,34 @@ class RoomListPage extends \wcf\page\AbstractPage {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function checkPermissions() { public function checkPermissions()
{
parent::checkPermissions(); parent::checkPermissions();
if (!\chat\data\room\Room::canSeeAny()) throw new \wcf\system\exception\PermissionDeniedException(); if (!Room::canSeeAny()) {
throw new PermissionDeniedException();
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
{
parent::readData(); parent::readData();
$this->rooms = \chat\data\room\RoomCache::getInstance()->getRooms(); $this->rooms = RoomCache::getInstance()->getRooms();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
WCF::getTPL()->assign([ 'rooms' => $this->rooms ]); WCF::getTPL()->assign([
'rooms' => $this->rooms,
]);
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,15 +15,21 @@
namespace chat\page; namespace chat\page;
use \wcf\system\exception\IllegalLinkException; use chat\data\room\RoomCache;
use \wcf\system\exception\NamedUserException; use wcf\data\package\PackageCache;
use \wcf\system\exception\PermissionDeniedException; use wcf\page\AbstractPage;
use \wcf\system\WCF; use wcf\system\attachment\AttachmentHandler;
use wcf\system\exception\IllegalLinkException;
use wcf\system\exception\NamedUserException;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\push\PushHandler;
use wcf\system\WCF;
/** /**
* Shows a specific chat room. * Shows a specific chat room.
*/ */
class RoomPage extends \wcf\page\AbstractPage { class RoomPage extends AbstractPage
{
use TConfiguredPage; use TConfiguredPage;
/** /**
@ -40,29 +47,38 @@ class RoomPage extends \wcf\page\AbstractPage {
/** /**
* The requested chat room ID. * The requested chat room ID.
* *
* @param int * @var int
*/ */
public $roomID = 0; public $roomID = 0;
/** /**
* The requested chat room. * The requested chat room.
* *
* @param \chat\data\room\Room * @var \chat\data\room\Room
*/ */
public $room = null; public $room;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readParameters() { public function readParameters()
{
parent::readParameters(); parent::readParameters();
if (isset($_GET['id'])) $this->roomID = intval($_GET['id']); if (isset($_GET['id'])) {
$this->room = \chat\data\room\RoomCache::getInstance()->getRoom($this->roomID); $this->roomID = \intval($_GET['id']);
}
$this->room = RoomCache::getInstance()->getRoom($this->roomID);
if ($this->room === null) throw new IllegalLinkException(); if ($this->room === null) {
if (!$this->room->canSee($user = null, $reason)) throw $reason; throw new IllegalLinkException();
if (!$this->room->canJoin($user = null, $reason)) throw $reason; }
if (!$this->room->canSee($user = null, $reason)) {
throw $reason;
}
if (!$this->room->canJoin($user = null, $reason)) {
throw $reason;
}
$this->canonicalURL = $this->room->getLink(); $this->canonicalURL = $this->room->getLink();
} }
@ -70,16 +86,17 @@ public function readParameters() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function checkPermissions() { public function checkPermissions()
{
parent::checkPermissions(); parent::checkPermissions();
$package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); $package = PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat');
if (stripos($package->packageVersion, 'Alpha') !== false) { if (\stripos($package->packageVersion, 'Alpha') !== false) {
$sql = "SELECT COUNT(*) FROM wcf1_user"; $sql = "SELECT COUNT(*) FROM wcf1_user";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute(); $statement->execute();
$userCount = $statement->fetchSingleColumn(); $userCount = $statement->fetchSingleColumn();
if ((($userCount > 5 && !OFFLINE) || ($userCount > 30 && OFFLINE)) && sha1(WCF_UUID) !== '643a6b3af2a6ea3d393c4d8371e75d7d1b66e0d0') { if ((($userCount > 5 && !OFFLINE) || ($userCount > 30 && OFFLINE)) && \sha1(WCF_UUID) !== '643a6b3af2a6ea3d393c4d8371e75d7d1b66e0d0') {
throw new PermissionDeniedException("Do not use alpha versions of Tims Chat in production communities!"); throw new PermissionDeniedException("Do not use alpha versions of Tims Chat in production communities!");
} }
} }
@ -88,7 +105,8 @@ public function checkPermissions() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function readData() { public function readData()
{
$sql = "SELECT 1"; $sql = "SELECT 1";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute(); $statement->execute();
@ -99,9 +117,14 @@ public function readData() {
parent::readData(); parent::readData();
// This attachment handler gets only used for the language variable `wcf.attachment.upload.limits`! // This attachment handler gets only used for the language variable `wcf.attachment.upload.limits`!
$this->attachmentHandler = new \wcf\system\attachment\AttachmentHandler('be.bastelstu.chat.message', 0, 'DEADC0DE00000000DEADC0DE00000000DEADC0DE', $this->room->roomID); $this->attachmentHandler = new AttachmentHandler(
'be.bastelstu.chat.message',
0,
'DEADC0DE00000000DEADC0DE00000000DEADC0DE',
$this->room->roomID
);
$pushHandler = \wcf\system\push\PushHandler::getInstance(); $pushHandler = PushHandler::getInstance();
$pushHandler->joinChannel('be.bastelstu.chat'); $pushHandler->joinChannel('be.bastelstu.chat');
$pushHandler->joinChannel('be.bastelstu.chat.room-' . $this->room->roomID); $pushHandler->joinChannel('be.bastelstu.chat.room-' . $this->room->roomID);
} }
@ -109,12 +132,14 @@ public function readData() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function assignVariables() { public function assignVariables()
{
parent::assignVariables(); parent::assignVariables();
WCF::getTPL()->assign([ 'room' => $this->room WCF::getTPL()->assign([
, 'config' => $this->getConfig() 'room' => $this->room,
, 'attachmentHandler' => $this->attachmentHandler 'config' => $this->getConfig(),
'attachmentHandler' => $this->attachmentHandler,
]); ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,47 +15,55 @@
namespace chat\page; namespace chat\page;
use \chat\data\command\Command; use chat\data\command\Command;
use \chat\data\command\CommandCache; use chat\data\command\CommandCache;
use \wcf\data\object\type\ObjectTypeCache; use wcf\data\object\type\ObjectTypeCache;
use \wcf\data\package\PackageCache; use wcf\data\package\PackageCache;
use wcf\system\event\EventHandler;
use wcf\util\JSON;
/** /**
* Provides a getConfig() method, returning the JSON configuration * Provides a getConfig() method, returning the JSON configuration
* for the chat's JavaSCript. * for the chat's JavaSCript.
*/ */
trait TConfiguredPage { trait TConfiguredPage
{
/** /**
* Returns the configuration for the chat's JavaScript. * Returns the configuration for the chat's JavaScript.
*/ */
public function getConfig() { public function getConfig()
{
$triggers = CommandCache::getInstance()->getTriggers(); $triggers = CommandCache::getInstance()->getTriggers();
$commands = array_map(function (Command $item) { $commands = \array_map(function (Command $item) {
$package = PackageCache::getInstance()->getPackage($item->packageID)->package; $package = PackageCache::getInstance()->getPackage($item->packageID)->package;
return [ 'package' => $package
, 'identifier' => $item->identifier return [
, 'commandID' => $item->commandID 'package' => $package,
, 'module' => $item->getProcessor()->getJavaScriptModuleName() 'identifier' => $item->identifier,
, 'isAvailable' => $item->getProcessor()->isAvailable($this->room) && ($item->hasTriggers() || $item->getProcessor()->allowWithoutTrigger()) 'commandID' => $item->commandID,
'module' => $item->getProcessor()->getJavaScriptModuleName(),
'isAvailable' => $item->getProcessor()->isAvailable($this->room) && ($item->hasTriggers() || $item->getProcessor()->allowWithoutTrigger()),
]; ];
}, CommandCache::getInstance()->getCommands()); }, CommandCache::getInstance()->getCommands());
$messageTypes = array_map(function ($item) { $messageTypes = \array_map(static function ($item) {
return [ 'module' => $item->getProcessor()->getJavaScriptModuleName() return [
'module' => $item->getProcessor()->getJavaScriptModuleName(),
]; ];
}, ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType')); }, ObjectTypeCache::getInstance()->getObjectTypes('be.bastelstu.chat.messageType'));
$config = [ 'clientVersion' => 1 $config = [
, 'reloadTime' => (int) CHAT_RELOADTIME 'clientVersion' => 1,
, 'autoAwayTime' => (int) CHAT_AUTOAWAYTIME 'reloadTime' => (int)CHAT_RELOADTIME,
, 'commands' => $commands 'autoAwayTime' => (int)CHAT_AUTOAWAYTIME,
, 'triggers' => $triggers 'commands' => $commands,
, 'messageTypes' => $messageTypes 'triggers' => $triggers,
'messageTypes' => $messageTypes,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'config', $config); EventHandler::getInstance()->fireAction($this, 'config', $config);
return \wcf\util\JSON::encode($config); return JSON::encode($config);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,25 +15,33 @@
namespace chat\system; namespace chat\system;
class CHATCore extends \wcf\system\application\AbstractApplication { use chat\page\RoomListPage;
use wcf\system\application\AbstractApplication;
use wcf\system\request\route\StaticRequestRoute;
use wcf\system\request\RouteHandler;
class CHATCore extends AbstractApplication
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $primaryController = \chat\page\RoomListPage::class; protected $primaryController = RoomListPage::class;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function __run() { public function __run()
$route = new \wcf\system\request\route\StaticRequestRoute(); {
$route = new StaticRequestRoute();
$route->setStaticController('chat', 'Log'); $route->setStaticController('chat', 'Log');
$route->setBuildSchema('/{controller}/{id}-{title}/{messageid}'); $route->setBuildSchema('/{controller}/{id}-{title}/{messageid}');
$route->setPattern('~^/?(?P<controller>[^/]+)/(?P<id>\d+)(?:-(?P<title>[^/]+))?/(?P<messageid>\d+)~x'); $route->setPattern('~^/?(?P<controller>[^/]+)/(?P<id>\d+)(?:-(?P<title>[^/]+))?/(?P<messageid>\d+)~x');
$route->setRequiredComponents([ 'id' => '~^\d+$~' $route->setRequiredComponents([
, 'messageid' => '~^\d+$~' 'id' => '~^\d+$~',
'messageid' => '~^\d+$~',
]); ]);
$route->setMatchController(true); $route->setMatchController(true);
\wcf\system\request\RouteHandler::getInstance()->addRoute($route); RouteHandler::getInstance()->addRoute($route);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,19 +15,23 @@
namespace chat\system\attachment; namespace chat\system\attachment;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\message\MessageList; use chat\data\message\MessageList;
use \chat\data\room\RoomCache; use chat\data\room\RoomCache;
use \wcf\system\WCF; use wcf\system\attachment\AbstractAttachmentObjectType;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
/** /**
* Attachment object type implementation for messages. * Attachment object type implementation for messages.
*/ */
class MessageAttachmentObjectType extends \wcf\system\attachment\AbstractAttachmentObjectType { class MessageAttachmentObjectType extends AbstractAttachmentObjectType
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDownload($objectID) { public function canDownload($objectID)
{
if ($objectID) { if ($objectID) {
$message = new Message($objectID); $message = new Message($objectID);
@ -44,7 +49,8 @@ public function canDownload($objectID) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canUpload($objectID, $parentObjectID = 0) { public function canUpload($objectID, $parentObjectID = 0)
{
if ($objectID) { if ($objectID) {
return false; return false;
} }
@ -68,35 +74,43 @@ public function canUpload($objectID, $parentObjectID = 0) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDelete($objectID) { public function canDelete($objectID)
{
return false; return false;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getMaxCount() { public function getMaxCount()
{
return 1; return 1;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getMaxSize() { public function getMaxSize()
{
return WCF::getSession()->getPermission('user.chat.attachment.maxSize'); return WCF::getSession()->getPermission('user.chat.attachment.maxSize');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getAllowedExtensions() { public function getAllowedExtensions()
return \wcf\util\ArrayUtil::trim(\explode("\n", WCF::getSession()->getPermission('user.chat.attachment.allowedExtensions'))); {
return ArrayUtil::trim(\explode(
"\n",
WCF::getSession()->getPermission('user.chat.attachment.allowedExtensions')
));
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function cacheObjects(array $objectIDs) { public function cacheObjects(array $objectIDs)
{
$messageList = new MessageList(); $messageList = new MessageList();
$messageList->setObjectIDs($objectIDs); $messageList->setObjectIDs($objectIDs);
$messageList->readObjects(); $messageList->readObjects();

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,17 +15,28 @@
namespace chat\system\box; namespace chat\system\box;
use \wcf\system\request\RequestHandler; use chat\data\room\Room;
use \wcf\system\WCF; use chat\data\room\RoomList;
use chat\page\RoomPage;
use wcf\system\box\AbstractDatabaseObjectListBoxController;
use wcf\system\request\LinkHandler;
use wcf\system\request\RequestHandler;
use wcf\system\WCF;
/** /**
* Dynamic box controller implementation for a list of rooms. * Dynamic box controller implementation for a list of rooms.
*/ */
class RoomListBoxController extends \wcf\system\box\AbstractDatabaseObjectListBoxController { class RoomListBoxController extends AbstractDatabaseObjectListBoxController
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected static $supportedPositions = [ 'contentBottom', 'contentTop', 'sidebarLeft', 'sidebarRight' ]; protected static $supportedPositions = [
'contentBottom',
'contentTop',
'sidebarLeft',
'sidebarRight',
];
/** /**
* @inheritDoc * @inheritDoc
@ -34,16 +46,17 @@ class RoomListBoxController extends \wcf\system\box\AbstractDatabaseObjectListBo
/** /**
* @var int * @var int
*/ */
protected $activeRoomID = null; protected $activeRoomID;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function __construct() { public function __construct()
{
parent::__construct(); parent::__construct();
$activeRequest = RequestHandler::getInstance()->getActiveRequest(); $activeRequest = RequestHandler::getInstance()->getActiveRequest();
if ($activeRequest && $activeRequest->getRequestObject() instanceof \chat\page\RoomPage) { if ($activeRequest && $activeRequest->getRequestObject() instanceof RoomPage) {
$this->activeRoomID = $activeRequest->getRequestObject()->room->roomID; $this->activeRoomID = $activeRequest->getRequestObject()->room->roomID;
} }
} }
@ -51,7 +64,8 @@ public function __construct() {
/** /**
* Sets the active room ID. * Sets the active room ID.
*/ */
public function setActiveRoomID($activeRoomID) { public function setActiveRoomID($activeRoomID)
{
$this->activeRoomID = $activeRoomID; $this->activeRoomID = $activeRoomID;
} }
@ -60,61 +74,71 @@ public function setActiveRoomID($activeRoomID) {
* *
* @return int * @return int
*/ */
public function getActiveRoomID() { public function getActiveRoomID()
{
return $this->activeRoomID; return $this->activeRoomID;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function hasLink() { public function hasLink()
{
return true; return true;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getLink() { public function getLink()
return \wcf\system\request\LinkHandler::getInstance()->getLink('RoomList', [ 'application' => 'chat' ]); {
return LinkHandler::getInstance()->getLink('RoomList', [
'application' => 'chat',
]);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function getObjectList() { protected function getObjectList()
return new \chat\data\room\RoomList(); {
return new RoomList();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function getTemplate() { protected function getTemplate()
{
$templateName = 'boxRoomList'; $templateName = 'boxRoomList';
if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') { if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') {
$templateName = 'boxRoomListSidebar'; $templateName = 'boxRoomListSidebar';
} }
return WCF::getTPL()->fetch($templateName, 'chat', [ 'boxRoomList' => $this->objectList return WCF::getTPL()->fetch($templateName, 'chat', [
, 'boxID' => $this->getBox()->boxID 'boxRoomList' => $this->objectList,
, 'activeRoomID' => $this->activeRoomID ?: 0 'boxID' => $this->getBox()->boxID,
'activeRoomID' => $this->activeRoomID ?: 0,
], true); ], true);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function hasContent() { public function hasContent()
{
if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') { if ($this->box->position === 'sidebarLeft' || $this->box->position === 'sidebarRight') {
parent::hasContent(); parent::hasContent();
foreach ($this->objectList as $room) { foreach ($this->objectList as $room) {
if ($room->canSee()) return true; if ($room->canSee()) {
return true;
}
} }
return false; return false;
} } else {
else { return Room::canSeeAny();
return \chat\data\room\Room::canSeeAny();
} }
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,29 +15,36 @@
namespace chat\system\cache\builder; namespace chat\system\cache\builder;
use \wcf\system\WCF; use chat\data\command\CommandList;
use wcf\system\cache\builder\AbstractCacheBuilder;
use wcf\system\WCF;
/** /**
* Caches all chat commands. * Caches all chat commands.
*/ */
class CommandCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder { class CommandCacheBuilder extends AbstractCacheBuilder
{
/** /**
* @see \wcf\system\cache\AbstractCacheBuilder::rebuild() * @inheritDoc
*/ */
public function rebuild(array $parameters) { public function rebuild(array $parameters)
$data = [ 'commands' => [ ] {
, 'triggers' => [ ] $data = [
, 'packages' => [ ] 'commands' => [ ],
'triggers' => [ ],
'packages' => [ ],
]; ];
$commandList = new \chat\data\command\CommandList(); $commandList = new CommandList();
$commandList->sqlOrderBy = 'command.commandID'; $commandList->sqlOrderBy = 'command.commandID';
$commandList->readObjects(); $commandList->readObjects();
$data['commands'] = $commandList->getObjects(); $data['commands'] = $commandList->getObjects();
foreach ($data['commands'] as $command) { foreach ($data['commands'] as $command) {
if (!isset($data['packages'][$command->packageID])) $data['packages'][$command->packageID] = [ ]; if (!isset($data['packages'][$command->packageID])) {
$data['packages'][$command->packageID] = [ ];
}
$data['packages'][$command->packageID][$command->identifier] = $command; $data['packages'][$command->packageID][$command->identifier] = $command;
} }

View File

@ -1,7 +1,8 @@
<?php <?php
/** /**
* Copyright (C) 2010-2021 Tim Düsterhus * Copyright (C) 2010-2022 Tim Düsterhus
* Copyright (C) 2010-2021 Woltlab GmbH * Copyright (C) 2010-2022 Woltlab GmbH
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -20,21 +21,25 @@
namespace chat\system\cache\builder; namespace chat\system\cache\builder;
use \wcf\system\acl\ACLHandler; use wcf\system\acl\ACLHandler;
use \wcf\system\WCF; use wcf\system\cache\builder\AbstractCacheBuilder;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
/** /**
* Caches the chat permissions for a combination of user groups. * Caches the chat permissions for a combination of user groups.
*/ */
class PermissionCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder { class PermissionCacheBuilder extends AbstractCacheBuilder
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function rebuild(array $parameters) { public function rebuild(array $parameters)
{
$data = [ ]; $data = [ ];
if (!empty($parameters)) { if (!empty($parameters)) {
$conditionBuilder = new \wcf\system\database\util\PreparedStatementConditionBuilder(); $conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]); $conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]);
$conditionBuilder->add('option_to_group.groupID IN (?)', [ $parameters ]); $conditionBuilder->add('option_to_group.groupID IN (?)', [ $parameters ]);
$sql = "SELECT option_to_group.objectID AS roomID, $sql = "SELECT option_to_group.objectID AS roomID,
@ -43,14 +48,13 @@ public function rebuild(array $parameters) {
FROM wcf1_acl_option acl_option FROM wcf1_acl_option acl_option
INNER JOIN wcf1_acl_option_to_group option_to_group INNER JOIN wcf1_acl_option_to_group option_to_group
ON option_to_group.optionID = acl_option.optionID ON option_to_group.optionID = acl_option.optionID
".$conditionBuilder; {$conditionBuilder}";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters()); $statement->execute($conditionBuilder->getParameters());
while (($row = $statement->fetchArray())) { while (($row = $statement->fetchArray())) {
if (!isset($data[$row['roomID']][$row['permission']])) { if (!isset($data[$row['roomID']][$row['permission']])) {
$data[$row['roomID']][$row['permission']] = $row['optionValue']; $data[$row['roomID']][$row['permission']] = $row['optionValue'];
} } else {
else {
$data[$row['roomID']][$row['permission']] = $row['optionValue'] || $data[$row['roomID']][$row['permission']]; $data[$row['roomID']][$row['permission']] = $row['optionValue'] || $data[$row['roomID']][$row['permission']];
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,15 +15,20 @@
namespace chat\system\cache\builder; namespace chat\system\cache\builder;
use chat\data\room\RoomList;
use wcf\system\cache\builder\AbstractCacheBuilder;
/** /**
* Caches all chat rooms. * Caches all chat rooms.
*/ */
class RoomCacheBuilder extends \wcf\system\cache\builder\AbstractCacheBuilder { class RoomCacheBuilder extends AbstractCacheBuilder
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function rebuild(array $parameters) { public function rebuild(array $parameters)
$roomList = new \chat\data\room\RoomList(); {
$roomList = new RoomList();
$roomList->sqlOrderBy = "room.position"; $roomList->sqlOrderBy = "room.position";
$roomList->readObjects(); $roomList->readObjects();

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,12 +15,16 @@
namespace chat\system\cache\runtime; namespace chat\system\cache\runtime;
use chat\data\user\UserList as ChatUserList;
use wcf\system\cache\runtime\AbstractRuntimeCache;
/** /**
* Runtime cache implementation for chat users. * Runtime cache implementation for chat users.
*/ */
class UserRuntimeCache extends \wcf\system\cache\runtime\AbstractRuntimeCache { class UserRuntimeCache extends AbstractRuntimeCache
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected $listClassName = \chat\data\user\UserList::class; protected $listClassName = ChatUserList::class;
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,32 +15,39 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\room\Room; use chat\data\command\Command;
use \wcf\data\object\type\ObjectTypeCache; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\DatabaseObjectDecorator;
use \wcf\system\exception\UserInputException; use wcf\data\IDatabaseObjectProcessor;
use wcf\data\object\type\ObjectTypeCache;
use wcf\data\user\UserProfile;
use wcf\system\exception\UserInputException;
/** /**
* Default implemention for command processors. * Default implemention for command processors.
*/ */
abstract class AbstractCommand extends \wcf\data\DatabaseObjectDecorator implements ICommand abstract class AbstractCommand extends DatabaseObjectDecorator implements
, \wcf\data\IDatabaseObjectProcessor { ICommand,
IDatabaseObjectProcessor
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected static $baseClass = \chat\data\command\Command::class; protected static $baseClass = Command::class;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
{
return true; return true;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function allowWithoutTrigger() { public function allowWithoutTrigger()
{
return false; return false;
} }
@ -49,8 +57,12 @@ public function allowWithoutTrigger() {
* @param string * @param string
* @return int * @return int
*/ */
public function getMessageObjectTypeID($objectType) { public function getMessageObjectTypeID($objectType)
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.messageType', $objectType); {
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.messageType',
$objectType
);
if (!$objectType) { if (!$objectType) {
throw new \LogicException('Missing object type'); throw new \LogicException('Missing object type');
@ -67,8 +79,9 @@ public function getMessageObjectTypeID($objectType) {
* @param string $key * @param string $key
* @return mixed The value. * @return mixed The value.
*/ */
public function assertParameter($parameters, $key) { public function assertParameter($parameters, $key)
if (array_key_exists($key, $parameters)) { {
if (\array_key_exists($key, $parameters)) {
return $parameters[$key]; return $parameters[$key];
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,70 +15,113 @@
namespace chat\system\command; namespace chat\system\command;
use \wcf\system\exception\UserInputException; use wcf\data\DatabaseObject;
use \wcf\system\bbcode\BBCodeHandler; use wcf\system\bbcode\BBCodeHandler;
use \wcf\system\message\censorship\Censorship; use wcf\system\exception\UserInputException;
use \wcf\system\WCF; use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\message\censorship\Censorship;
use wcf\system\WCF;
/** /**
* Represents a command that processes the input using HtmlInputProcessor. * Represents a command that processes the input using HtmlInputProcessor.
*/ */
abstract class AbstractInputProcessedCommand extends AbstractCommand { abstract class AbstractInputProcessedCommand extends AbstractCommand
{
/** /**
* HtmlInputProcessor to use. * HtmlInputProcessor to use.
* @var \wcf\system\html\input\HtmlInputProcessor * @var \wcf\system\html\input\HtmlInputProcessor
*/ */
protected $processor = null; protected $processor;
/** /**
* The text processed last. * The text processed last.
* @var string * @var string
*/ */
private $text = null; private $text;
public function __construct(\wcf\data\DatabaseObject $object) { public function __construct(DatabaseObject $object)
{
parent::__construct($object); parent::__construct($object);
$this->processor = new \wcf\system\html\input\HtmlInputProcessor(); $this->processor = new HtmlInputProcessor();
$this->setDisallowedBBCodes(); $this->setDisallowedBBCodes();
} }
private function setDisallowedBBCodes() { private function setDisallowedBBCodes()
BBCodeHandler::getInstance()->setDisallowedBBCodes(explode(',', WCF::getSession()->getPermission('user.chat.disallowedBBCodes'))); {
BBCodeHandler::getInstance()->setDisallowedBBCodes(\explode(
',',
WCF::getSession()->getPermission('user.chat.disallowedBBCodes')
));
} }
public function setText($text) { public function setText($text)
if ($this->text === $text) return; {
if ($this->text === $text) {
return;
}
$this->text = $text; $this->text = $text;
$this->setDisallowedBBCodes(); $this->setDisallowedBBCodes();
$this->processor->process($text, 'be.bastelstu.chat.message', 0); $this->processor->process(
$text,
'be.bastelstu.chat.message',
0
);
} }
public function validateText() { public function validateText()
{
if ($this->processor->appearsToBeEmpty()) { if ($this->processor->appearsToBeEmpty()) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty')); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty')
);
} }
$message = $this->processor->getTextContent(); $message = $this->processor->getTextContent();
// validate message length // validate message length
if (mb_strlen($message) > CHAT_MAX_LENGTH) { if (\mb_strlen($message) > CHAT_MAX_LENGTH) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', [ 'maxTextLength' => CHAT_MAX_LENGTH ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.tooLong',
[
'maxTextLength' => CHAT_MAX_LENGTH,
]
)
);
} }
// search for disallowed bbcodes // search for disallowed bbcodes
$this->setDisallowedBBCodes(); $this->setDisallowedBBCodes();
$disallowedBBCodes = $this->processor->validate(); $disallowedBBCodes = $this->processor->validate();
if (!empty($disallowedBBCodes)) { if (!empty($disallowedBBCodes)) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.disallowedBBCodes', [ 'disallowedBBCodes' => $disallowedBBCodes ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.disallowedBBCodes',
[
'disallowedBBCodes' => $disallowedBBCodes,
]
)
);
} }
// search for censored words // search for censored words
if (ENABLE_CENSORSHIP) { if (ENABLE_CENSORSHIP) {
$result = Censorship::getInstance()->test($message); $result = Censorship::getInstance()->test($message);
if ($result) { if ($result) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', [ 'censoredWords' => $result ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.censoredWordsFound',
[
'censoredWords' => $result,
]
)
);
} }
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,19 +15,21 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\Suspension; use chat\data\suspension\Suspension;
use \chat\data\suspension\SuspensionAction; use chat\data\suspension\SuspensionAction;
use \wcf\data\object\type\ObjectTypeCache; use chat\data\user\User as ChatUser;
use \wcf\data\user\UserProfile; use wcf\data\object\type\ObjectTypeCache;
use \wcf\system\exception\UserInputException; use wcf\data\user\UserProfile;
use \wcf\system\WCF; use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/** /**
* Represents a command that creates suspensions * Represents a command that creates suspensions
*/ */
abstract class AbstractSuspensionCommand extends AbstractCommand { abstract class AbstractSuspensionCommand extends AbstractCommand
{
use TNeedsUser; use TNeedsUser;
/** /**
@ -47,8 +50,11 @@ abstract protected function checkPermissions($parameters, Room $room, UserProfil
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$this->assertParameter($parameters, 'username'); $this->assertParameter($parameters, 'username');
$this->assertParameter($parameters, 'globally'); $this->assertParameter($parameters, 'globally');
@ -57,24 +63,41 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
$this->assertUser($parameters['username']); $this->assertUser($parameters['username']);
if ($parameters['duration'] !== null && $parameters['duration'] < TIME_NOW) { if ($parameters['duration'] !== null && $parameters['duration'] < TIME_NOW) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.datePast')); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable('chat.error.datePast')
);
} }
if (!empty($parameters['reason']) && mb_strlen($parameters['reason']) > 100) { if (!empty($parameters['reason']) && \mb_strlen($parameters['reason']) > 100) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', [ 'maxTextLength' => 250 ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.tooLong',
[
'maxTextLength' => 250,
]
)
);
} }
$this->checkPermissions($parameters, $room, $user); $this->checkPermissions($parameters, $room, $user);
$test = new Suspension(null, $this->getSuspensionData($parameters, $room, $user)); $test = new Suspension(null, $this->getSuspensionData($parameters, $room, $user));
if (!$test->isActive()) { if (!$test->isActive()) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.suspension.noEffect')); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable('chat.error.suspension.noEffect')
);
} }
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$data = $this->getSuspensionData($parameters, $room, $user); $data = $this->getSuspensionData($parameters, $room, $user);
$test = new Suspension(null, $data); $test = new Suspension(null, $data);
@ -83,7 +106,13 @@ public function execute($parameters, Room $room, UserProfile $user = null) {
} }
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$suspension = (new SuspensionAction([ ], 'create', [ 'data' => $data ]))->executeAction()['returnValues']; $suspension = (new SuspensionAction(
[ ],
'create',
[
'data' => $data,
]
))->executeAction()['returnValues'];
$this->afterCreate($suspension, $parameters, $room, $user); $this->afterCreate($suspension, $parameters, $room, $user);
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
@ -92,69 +121,75 @@ public function execute($parameters, Room $room, UserProfile $user = null) {
/** /**
* Creates chat messages informing about the suspension. * Creates chat messages informing about the suspension.
* *
* @param \chat\data\suspension\Suspension $suspension
* @param mixed[] $parameters * @param mixed[] $parameters
* @param \chat\data\room\Room $room
* @param \wcf\data\user\UserProfile $user
*/ */
protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user) { protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user)
{
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.suspend'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.suspend');
$target = $suspension->getUser(); $target = $suspension->getUser();
if ($suspension->getRoom() === null) { if ($suspension->getRoom() === null) {
$roomIDs = array_map(function (Room $room) use ($user) { $roomIDs = \array_map(static function (Room $room) {
return $room->roomID; return $room->roomID;
}, (new \chat\data\user\User($target))->getRooms()); }, (new ChatUser($target))->getRooms());
$roomIDs[] = $room->roomID; $roomIDs[] = $room->roomID;
} } else {
else {
$roomIDs = [ $suspension->getRoom()->roomID ]; $roomIDs = [ $suspension->getRoom()->roomID ];
} }
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'suspension' => $suspension 'roomID' => $room->roomID,
, 'roomIDs' => $roomIDs 'userID' => $user->userID,
, 'globally' => $this->isGlobally($parameters) 'username' => $user->username,
, 'target' => [ 'userID' => $target->userID 'time' => TIME_NOW,
, 'username' => $target->username 'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'suspension' => $suspension,
'roomIDs' => $roomIDs,
'globally' => $this->isGlobally($parameters),
'target' => [
'userID' => $target->userID,
'username' => $target->username,
],
]),
],
'updateTimestamp' => true,
] ]
]) ))->executeAction();
]
, 'updateTimestamp' => true
]
)
)->executeAction();
} }
/** /**
* Returns the database fields. * Returns the database fields.
* *
* @param mixed[] $parameters * @param mixed[] $parameters
* @param \chat\data\room\Room $room
* @param \wcf\data\user\UserProfile $user
* @return mixed[] * @return mixed[]
*/ */
protected function getSuspensionData($parameters, Room $room, UserProfile $user = null) { protected function getSuspensionData($parameters, Room $room, ?UserProfile $user = null)
{
$target = $this->getUser($parameters['username']); $target = $this->getUser($parameters['username']);
$globally = $this->isGlobally($parameters); $globally = $this->isGlobally($parameters);
$expires = $parameters['duration']; $expires = $parameters['duration'];
$reason = $parameters['reason'] ?: ''; $reason = $parameters['reason'] ?: '';
$roomID = $globally ? null : $room->roomID; $roomID = $globally ? null : $room->roomID;
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', $this->getObjectTypeName()); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.suspension',
$this->getObjectTypeName()
);
return [ 'time' => TIME_NOW return [
, 'expires' => $expires 'time' => TIME_NOW,
, 'roomID' => $roomID 'expires' => $expires,
, 'userID' => $target->userID 'roomID' => $roomID,
, 'objectTypeID' => $objectTypeID 'userID' => $target->userID,
, 'reason' => $reason 'objectTypeID' => $objectTypeID,
, 'judgeID' => $user->userID 'reason' => $reason,
, 'judge' => $user->username 'judgeID' => $user->userID,
'judge' => $user->username,
]; ];
} }
@ -164,7 +199,8 @@ protected function getSuspensionData($parameters, Room $room, UserProfile $user
* @param mixed[] $parameters * @param mixed[] $parameters
* @return boolean * @return boolean
*/ */
protected function isGlobally($parameters) { protected function isGlobally($parameters)
{
return $parameters['globally'] === true; return $parameters['globally'] === true;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,20 +15,22 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\Suspension; use chat\data\suspension\Suspension;
use \chat\data\suspension\SuspensionAction; use chat\data\suspension\SuspensionAction;
use \chat\data\suspension\SuspensionList; use chat\data\suspension\SuspensionList;
use \wcf\data\object\type\ObjectTypeCache; use chat\data\user\User as ChatUser;
use \wcf\data\user\UserProfile; use wcf\data\object\type\ObjectTypeCache;
use \wcf\system\exception\UserInputException; use wcf\data\user\UserProfile;
use \wcf\system\WCF; use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/** /**
* Represents a command that revokes suspensions * Represents a command that revokes suspensions
*/ */
abstract class AbstractUnsuspensionCommand extends AbstractCommand { abstract class AbstractUnsuspensionCommand extends AbstractCommand
{
use TNeedsUser; use TNeedsUser;
/** /**
@ -48,8 +51,11 @@ abstract protected function checkPermissions($parameters, Room $room, UserProfil
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$this->assertParameter($parameters, 'username'); $this->assertParameter($parameters, 'username');
$this->assertParameter($parameters, 'globally'); $this->assertParameter($parameters, 'globally');
@ -58,20 +64,30 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
$suspensions = $this->getSuspensionData($parameters, $room, $user); $suspensions = $this->getSuspensionData($parameters, $room, $user);
if (empty($suspensions)) { if (empty($suspensions)) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.suspension.remove.empty')); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable('chat.error.suspension.remove.empty')
);
} }
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$suspensions = $this->getSuspensionData($parameters, $room, $user); $suspensions = $this->getSuspensionData($parameters, $room, $user);
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
(new SuspensionAction($suspensions, 'revoke', [ ]))->executeAction(); (new SuspensionAction(
$suspensions,
'revoke',
[ ]
))->executeAction();
$this->afterCreate($suspensions, $parameters, $room, $user); $this->afterCreate($suspensions, $parameters, $room, $user);
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
@ -81,54 +97,62 @@ public function execute($parameters, Room $room, UserProfile $user = null) {
* *
* @param \chat\data\suspension\Suspension[] $suspension * @param \chat\data\suspension\Suspension[] $suspension
* @param mixed[] $parameters * @param mixed[] $parameters
* @param \chat\data\room\Room $room
* @param \wcf\data\user\UserProfile $user
*/ */
protected function afterCreate($suspensions, $parameters, Room $room, UserProfile $user) { protected function afterCreate($suspensions, $parameters, Room $room, UserProfile $user)
{
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.unsuspend'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.unsuspend');
$target = $this->getUser($parameters['username']); $target = $this->getUser($parameters['username']);
if ($this->isGlobally($parameters)) { if ($this->isGlobally($parameters)) {
$roomIDs = array_map(function (Room $room) use ($user) { $roomIDs = \array_map(static function (Room $room) {
return $room->roomID; return $room->roomID;
}, (new \chat\data\user\User($target))->getRooms()); }, (new ChatUser($target))->getRooms());
$roomIDs[] = $room->roomID; $roomIDs[] = $room->roomID;
} } else {
else { $roomIDs = [
$roomIDs = [ $room->roomID ]; $room->roomID,
];
} }
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'objectType' => $this->getObjectTypeName() 'roomID' => $room->roomID,
, 'roomIDs' => $roomIDs 'userID' => $user->userID,
, 'globally' => $this->isGlobally($parameters) 'username' => $user->username,
, 'target' => [ 'userID' => $target->userID 'time' => TIME_NOW,
, 'username' => $target->username 'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'objectType' => $this->getObjectTypeName(),
'roomIDs' => $roomIDs,
'globally' => $this->isGlobally($parameters),
'target' => [
'userID' => $target->userID,
'username' => $target->username,
],
]),
],
'updateTimestamp' => true,
] ]
]) ))->executeAction();
]
, 'updateTimestamp' => true
]
)
)->executeAction();
} }
/** /**
* Returns the active suspensions. * Returns the active suspensions.
* *
* @param mixed[] $parameters * @param mixed[] $parameters
* @param \chat\data\room\Room $room
* @param \wcf\data\user\UserProfile $user
* @return mixed[] * @return mixed[]
*/ */
protected function getSuspensionData($parameters, Room $room, UserProfile $user = null) { protected function getSuspensionData($parameters, Room $room, ?UserProfile $user = null)
{
$target = $this->getUser($parameters['username']); $target = $this->getUser($parameters['username']);
$roomID = $this->isGlobally($parameters) ? null : $room->roomID; $roomID = $this->isGlobally($parameters) ? null : $room->roomID;
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', $this->getObjectTypeName()); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.suspension',
$this->getObjectTypeName()
);
$suspensionList = new SuspensionList(); $suspensionList = new SuspensionList();
@ -138,14 +162,13 @@ protected function getSuspensionData($parameters, Room $room, UserProfile $user
$suspensionList->getConditionBuilder()->add('objectTypeID = ?', [ $objectTypeID ]); $suspensionList->getConditionBuilder()->add('objectTypeID = ?', [ $objectTypeID ]);
if ($roomID === null) { if ($roomID === null) {
$suspensionList->getConditionBuilder()->add('roomID IS NULL'); $suspensionList->getConditionBuilder()->add('roomID IS NULL');
} } else {
else {
$suspensionList->getConditionBuilder()->add('roomID = ?', [ $room->roomID ]); $suspensionList->getConditionBuilder()->add('roomID = ?', [ $room->roomID ]);
} }
$suspensionList->readObjects(); $suspensionList->readObjects();
return array_filter($suspensionList->getObjects(), function (Suspension $suspension) { return \array_filter($suspensionList->getObjects(), static function (Suspension $suspension) {
return $suspension->isActive(); return $suspension->isActive();
}); });
} }
@ -156,7 +179,8 @@ protected function getSuspensionData($parameters, Room $room, UserProfile $user
* @param mixed[] $parameters * @param mixed[] $parameters
* @return boolean * @return boolean
*/ */
protected function isGlobally($parameters) { protected function isGlobally($parameters)
{
return $parameters['globally'] === true; return $parameters['globally'] === true;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,30 +15,36 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use chat\data\user\User as ChatUser;
use \wcf\system\exception\PermissionDeniedException; use wcf\data\user\UserEditor;
use \wcf\system\exception\UserInputException; use wcf\data\user\UserProfile;
use \wcf\system\message\censorship\Censorship; use wcf\system\exception\UserInputException;
use \wcf\system\WCF; use wcf\system\message\censorship\Censorship;
use wcf\system\WCF;
/** /**
* The away command marks the user as being away. * The away command marks the user as being away.
*/ */
class AwayCommand extends AbstractCommand implements ICommand { class AwayCommand extends AbstractCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Away'; return 'Bastelstu.be/Chat/Command/Away';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$reason = $this->assertParameter($parameters, 'reason'); $reason = $this->assertParameter($parameters, 'reason');
@ -45,7 +52,15 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
if (ENABLE_CENSORSHIP) { if (ENABLE_CENSORSHIP) {
$result = Censorship::getInstance()->test($reason); $result = Censorship::getInstance()->test($reason);
if ($result) { if ($result) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', [ 'censoredWords' => $result ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.censoredWordsFound',
[
'censoredWords' => $result,
]
)
);
} }
} }
} }
@ -53,35 +68,46 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$reason = $this->assertParameter($parameters, 'reason'); $reason = $this->assertParameter($parameters, 'reason');
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.away'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.away');
$rooms = array_map(function (Room $room) use ($user) { $rooms = \array_map(static function (Room $room) use ($user) {
return [ 'roomID' => $room->roomID return [
, 'isSilent' => !$room->canWritePublicly($user) 'roomID' => $room->roomID,
'isSilent' => !$room->canWritePublicly($user),
]; ];
}, (new \chat\data\user\User($user->getDecoratedObject()))->getRooms()); }, (new ChatUser($user->getDecoratedObject()))->getRooms());
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$editor = new \wcf\data\user\UserEditor($user->getDecoratedObject()); $editor = new UserEditor($user->getDecoratedObject());
$editor->update([ 'chatAway' => $reason ]); $editor->update([
'chatAway' => $reason,
]);
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'message' => $reason 'roomID' => $room->roomID,
, 'rooms' => array_values($rooms) 'userID' => $user->userID,
]) 'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'message' => $reason,
'rooms' => \array_values($rooms),
]),
],
'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,67 +15,89 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use chat\data\user\User as ChatUser;
use \wcf\system\exception\PermissionDeniedException; use wcf\data\user\UserEditor;
use \wcf\system\WCF; use wcf\data\user\UserProfile;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
/** /**
* The back command marks the user as being back. * The back command marks the user as being back.
*/ */
class BackCommand extends AbstractCommand implements ICommand { class BackCommand extends AbstractCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function allowWithoutTrigger() { public function allowWithoutTrigger()
{
return true; return true;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Back'; return 'Bastelstu.be/Chat/Command/Back';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if ($user->chatAway === null) throw new PermissionDeniedException(); if ($user->chatAway === null) {
throw new PermissionDeniedException();
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.back'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.back');
$rooms = array_map(function (Room $room) use ($user) { $rooms = \array_map(static function (Room $room) use ($user) {
return [ 'roomID' => $room->roomID return [
, 'isSilent' => !$room->canWritePublicly($user) 'roomID' => $room->roomID,
'isSilent' => !$room->canWritePublicly($user),
]; ];
}, (new \chat\data\user\User($user->getDecoratedObject()))->getRooms()); }, (new ChatUser($user->getDecoratedObject()))->getRooms());
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$editor = new \wcf\data\user\UserEditor($user->getDecoratedObject()); $editor = new UserEditor($user->getDecoratedObject());
$editor->update([ 'chatAway' => null ]); $editor->update([
'chatAway' => null,
]);
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'rooms' => array_values($rooms) ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'rooms' => \array_values($rooms),
]),
],
'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,79 +15,96 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\Suspension; use chat\data\room\RoomAction;
use \chat\data\suspension\SuspensionAction; use chat\data\suspension\Suspension;
use \chat\system\permission\PermissionHandler; use chat\data\user\User as ChatUser;
use \wcf\data\object\type\ObjectTypeCache; use chat\system\permission\PermissionHandler;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF; use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/** /**
* The ban command creates a new be.bastelstu.chat.suspension.ban suspension. * The ban command creates a new be.bastelstu.chat.suspension.ban suspension.
*/ */
class BanCommand extends AbstractSuspensionCommand implements ICommand { class BanCommand extends AbstractSuspensionCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Ban'; return 'Bastelstu.be/Chat/Command/Ban';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getObjectTypeName() { public function getObjectTypeName()
{
return 'be.bastelstu.chat.suspension.ban'; return 'be.bastelstu.chat.suspension.ban';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function checkPermissions($parameters, Room $room, UserProfile $user) { protected function checkPermissions($parameters, Room $room, UserProfile $user)
{
$permission = $user->getPermission('mod.chat.canBan'); $permission = $user->getPermission('mod.chat.canBan');
if (!$this->isGlobally($parameters)) { if (!$this->isGlobally($parameters)) {
$permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan');
} }
if (!$permission) throw new PermissionDeniedException(); if (!$permission) {
throw new PermissionDeniedException();
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user) { protected function afterCreate(Suspension $suspension, $parameters, Room $room, UserProfile $user)
{
parent::afterCreate($suspension, $parameters, $room, $user); parent::afterCreate($suspension, $parameters, $room, $user);
$user = new \chat\data\user\User($suspension->getUser()); $user = new ChatUser($suspension->getUser());
$rooms = [ ]; $rooms = [ ];
if ($suspension->getRoom() === null) { if ($suspension->getRoom() === null) {
$rooms = $user->getRooms(); $rooms = $user->getRooms();
} } else {
else {
if ($user->isInRoom($suspension->getRoom())) { if ($user->isInRoom($suspension->getRoom())) {
$rooms = [ $suspension->getRoom() ]; $rooms = [
$suspension->getRoom(),
];
} }
} }
foreach ($rooms as $room) { foreach ($rooms as $room) {
$parameters = [ 'user' => $suspension->getUser() $parameters = [
, 'roomID' => $room->roomID 'user' => $suspension->getUser(),
'roomID' => $room->roomID,
]; ];
try { try {
(new \chat\data\room\RoomAction([ ], 'leave', $parameters))->executeAction(); (new RoomAction(
} [ ],
catch (UserInputException $e) { 'leave',
$parameters
))->executeAction();
} catch (UserInputException $e) {
// User already left // User already left
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,39 +15,51 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\message\MessageEditor; use chat\data\message\MessageEditor;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF; use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\WCF;
/** /**
* BroadcastCommand sends a broadcast into all channels. * BroadcastCommand sends a broadcast into all channels.
*/ */
class BroadcastCommand extends AbstractInputProcessedCommand implements ICommand { class BroadcastCommand extends AbstractInputProcessedCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Broadcast'; return 'Bastelstu.be/Chat/Command/Broadcast';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canBroadcast'); return $user->getPermission('mod.chat.canBroadcast');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!$user->getPermission('mod.chat.canBroadcast')) throw new PermissionDeniedException(); if (!$user->getPermission('mod.chat.canBroadcast')) {
throw new PermissionDeniedException();
}
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
$this->validateText(); $this->validateText();
@ -55,29 +68,39 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.broadcast'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.broadcast');
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID $message = (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) 'roomID' => $room->roomID,
] 'userID' => $user->userID,
, 'updateTimestamp' => true 'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'message' => $this->processor->getHtml(),
]),
],
'updateTimestamp' => true,
] ]
) )
)->executeAction()['returnValues']; )->executeAction()['returnValues'];
$this->processor->setObjectID($message->messageID); $this->processor->setObjectID($message->messageID);
if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) {
(new MessageEditor($message))->update([ (new MessageEditor($message))->update([
'hasEmbeddedObjects' => 1 'hasEmbeddedObjects' => 1,
]); ]);
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,34 +15,40 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\DatabaseObject;
use \wcf\system\exception\PermissionDeniedException; use wcf\data\user\UserEditor;
use \wcf\system\exception\UserInputException; use wcf\data\user\UserProfile;
use \wcf\system\WCF; use wcf\system\exception\PermissionDeniedException;
use \wcf\util\StringUtil; use wcf\system\exception\UserInputException;
use wcf\system\Regex;
use wcf\system\WCF;
use wcf\util\StringUtil;
/** /**
* The color command allows a user to set a color for their username * The color command allows a user to set a color for their username
*/ */
class ColorCommand extends AbstractCommand implements ICommand { class ColorCommand extends AbstractCommand implements ICommand
{
/** /**
* Regular expression matching RGB values in hexadecimal notation * Regular expression matching RGB values in hexadecimal notation
* @var \wcf\system\Regex * @var \wcf\system\Regex
*/ */
protected $colorRegex = null; protected $colorRegex;
public function __construct(\wcf\data\DatabaseObject $object) { public function __construct(DatabaseObject $object)
{
parent::__construct($object); parent::__construct($object);
$this->colorRegex = new \wcf\system\Regex('^#?([a-f0-9]{6})$', \wcf\system\Regex::CASE_INSENSITIVE); $this->colorRegex = new Regex('^#?([a-f0-9]{6})$', Regex::CASE_INSENSITIVE);
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Color'; return 'Bastelstu.be/Chat/Command/Color';
} }
@ -201,16 +208,21 @@ public function getJavaScriptModuleName() {
'white' => 0xFFFFFF, 'white' => 0xFFFFFF,
'whitesmoke' => 0xF5F5F5, 'whitesmoke' => 0xF5F5F5,
'yellow' => 0xFFFF00, 'yellow' => 0xFFFF00,
'yellowgreen' => 0x9ACD32 'yellowgreen' => 0x9ACD32,
]; ];
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!$user->getPermission('user.chat.canSetColor')) throw new PermissionDeniedException(); if (!$user->getPermission('user.chat.canSetColor')) {
throw new PermissionDeniedException();
}
foreach ($parameters as $parameter) { foreach ($parameters as $parameter) {
$value = StringUtil::trim($this->assertParameter($parameter, 'value')); $value = StringUtil::trim($this->assertParameter($parameter, 'value'));
@ -219,12 +231,28 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
switch ($this->assertParameter($parameter, 'type')) { switch ($this->assertParameter($parameter, 'type')) {
case 'hex': case 'hex':
if (!$this->colorRegex->match($value)) { if (!$this->colorRegex->match($value)) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.invalidColor', [ 'color' => $value ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'chat.error.invalidColor',
[
'color' => $value,
]
)
);
} }
break; break;
case 'word': case 'word':
if (!isset(self::$colors[$value])) { if (!isset(self::$colors[$value])) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.invalidColor', [ 'color' => $value ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'chat.error.invalidColor',
[
'color' => $value,
]
)
);
} }
break; break;
@ -237,23 +265,30 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.color'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.color');
$colors = [ ]; $colors = [ ];
if (!isset($parameters[1])) $parameters[1] = $parameters[0]; if (!isset($parameters[1])) {
$parameters[1] = $parameters[0];
}
foreach ($parameters as $key => $parameter) { foreach ($parameters as $key => $parameter) {
$value = StringUtil::trim($this->assertParameter($parameter, 'value')); $value = StringUtil::trim($this->assertParameter($parameter, 'value'));
switch ($this->assertParameter($parameter, 'type')) { switch ($this->assertParameter($parameter, 'type')) {
case 'hex': case 'hex':
$colors[$key] = hexdec($value); $colors[$key] = \hexdec($value);
break; break;
case 'word': case 'word':
if (!isset(self::$colors[$value])) throw new UserInputException('message'); if (!isset(self::$colors[$value])) {
throw new UserInputException('message');
}
$colors[$key] = self::$colors[$value]; $colors[$key] = self::$colors[$value];
break; break;
default: default:
@ -262,24 +297,30 @@ public function execute($parameters, Room $room, UserProfile $user = null) {
} }
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$editor = new \wcf\data\user\UserEditor($user->getDecoratedObject()); $editor = new UserEditor($user->getDecoratedObject());
$editor->update([ 'chatColor1' => $colors[0] $editor->update([
, 'chatColor2' => $colors[1] 'chatColor1' => $colors[0],
'chatColor2' => $colors[1],
]); ]);
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'color1' => $colors[0] 'roomID' => $room->roomID,
, 'color2' => $colors[1] 'userID' => $user->userID,
]) 'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'color1' => $colors[0],
'color2' => $colors[1],
]),
],
'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,13 +15,14 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
/** /**
* Interface for Command processors. * Interface for Command processors.
*/ */
interface ICommand { interface ICommand
{
/** /**
* Returns whether the command can be used even when * Returns whether the command can be used even when
* no trigger is configured for it. * no trigger is configured for it.
@ -48,7 +50,7 @@ public function getJavaScriptModuleName();
* @param UserProfile $user * @param UserProfile $user
* @return boolean * @return boolean
*/ */
public function isAvailable(Room $room, UserProfile $user = null); public function isAvailable(Room $room, ?UserProfile $user = null);
/** /**
* Validates the execution of the command with the given parameters * Validates the execution of the command with the given parameters
@ -60,7 +62,7 @@ public function isAvailable(Room $room, UserProfile $user = null);
* @param Room $room * @param Room $room
* @param UserProfile $user * @param UserProfile $user
*/ */
public function validate($parameters, Room $room, UserProfile $user = null); public function validate($parameters, Room $room, ?UserProfile $user = null);
/** /**
* Executes the command with the given parameters in the given room in * Executes the command with the given parameters in the given room in
@ -72,5 +74,5 @@ public function validate($parameters, Room $room, UserProfile $user = null);
* @param Room $room * @param Room $room
* @param UserProfile $user * @param UserProfile $user
*/ */
public function execute($parameters, Room $room, UserProfile $user = null); public function execute($parameters, Room $room, ?UserProfile $user = null);
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,30 +15,38 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\room\RoomCache; use chat\data\room\RoomCache;
use \wcf\data\user\User; use chat\data\user\User as ChatUser;
use \wcf\data\user\UserProfile; use wcf\data\user\User;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* The info command shows information about a single user. * The info command shows information about a single user.
*/ */
class InfoCommand extends AbstractCommand implements ICommand { class InfoCommand extends AbstractCommand implements ICommand
{
use TNeedsUser; use TNeedsUser;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Info'; return 'Bastelstu.be/Chat/Command/Info';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$this->assertUser($this->assertParameter($parameters, 'username')); $this->assertUser($this->assertParameter($parameters, 'username'));
} }
@ -45,44 +54,52 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.info'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.info');
$target = new \chat\data\user\User($this->getUser($this->assertParameter($parameters, 'username'))); $target = new ChatUser($this->getUser($this->assertParameter($parameters, 'username')));
$rooms = array_values(array_map(function ($assoc) { $rooms = \array_values(\array_map(static function ($assoc) {
$room = RoomCache::getInstance()->getRoom($assoc['roomID']); $room = RoomCache::getInstance()->getRoom($assoc['roomID']);
return [ 'title' => (string) $room return [
, 'roomID' => $assoc['roomID'] 'title' => (string)$room,
, 'lastPush' => $assoc['lastPush'] 'roomID' => $assoc['roomID'],
, 'lastPull' => $assoc['lastPull'] 'lastPush' => $assoc['lastPush'],
, 'active' => $assoc['active'] 'lastPull' => $assoc['lastPull'],
, 'link' => $room->getLink() 'active' => $assoc['active'],
'link' => $room->getLink(),
]; ];
}, array_filter($target->getRoomAssociations(), function ($assoc) { }, \array_filter($target->getRoomAssociations(), static function ($assoc) {
return RoomCache::getInstance()->getRoom($assoc['roomID'])->canSee(); return RoomCache::getInstance()->getRoom($assoc['roomID'])->canSee();
}))); })));
$payload = [ 'data' => [ 'rooms' => $rooms $payload = [
, 'away' => $target->chatAway 'data' => [
, 'user' => $target 'rooms' => $rooms,
] 'away' => $target->chatAway,
, 'caller' => $user 'user' => $target,
], 'caller' => $user,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'execute', $payload); EventHandler::getInstance()->fireAction($this, 'execute', $payload);
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize($payload['data']) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize($payload['data']),
], 'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,49 +15,75 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\exception\PermissionDeniedException;
use \wcf\system\exception\UserInputException; use wcf\system\exception\UserInputException;
use \wcf\system\message\censorship\Censorship; use wcf\system\message\censorship\Censorship;
use \wcf\system\WCF; use wcf\system\WCF;
/** /**
* MeCommand represents an action message. * MeCommand represents an action message.
*/ */
class MeCommand extends AbstractCommand implements ICommand { class MeCommand extends AbstractCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Me'; return 'Bastelstu.be/Chat/Command/Me';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!$room->canWritePublicly($user)) throw new PermissionDeniedException(); if (!$room->canWritePublicly($user)) {
throw new PermissionDeniedException();
}
$text = $this->assertParameter($parameters, 'text'); $text = $this->assertParameter($parameters, 'text');
if (mb_strlen($text) === 0) { if (\mb_strlen($text) === 0) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty')); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable('wcf.global.form.error.empty')
);
} }
// validate message length // validate message length
if (mb_strlen($text) > CHAT_MAX_LENGTH) { if (\mb_strlen($text) > CHAT_MAX_LENGTH) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.tooLong', [ 'maxTextLength' => CHAT_MAX_LENGTH ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.tooLong',
[
'maxTextLength' => CHAT_MAX_LENGTH,
]
)
);
} }
// search for censored words // search for censored words
if (ENABLE_CENSORSHIP) { if (ENABLE_CENSORSHIP) {
$result = Censorship::getInstance()->test($text); $result = Censorship::getInstance()->test($text);
if ($result) { if ($result) {
throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('wcf.message.error.censoredWordsFound', [ 'censoredWords' => $result ])); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'wcf.message.error.censoredWordsFound',
[
'censoredWords' => $result,
]
)
);
} }
} }
} }
@ -64,21 +91,30 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.me'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.me');
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'message' => $this->assertParameter($parameters, 'text') ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'message' => $this->assertParameter($parameters, 'text'),
]),
],
'updateTimestamp' => true,
'grantPoints' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
, 'grantPoints' => true
]
)
)->executeAction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,50 +15,58 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\SuspensionAction; use chat\system\permission\PermissionHandler;
use \chat\system\permission\PermissionHandler; use wcf\data\user\UserProfile;
use \wcf\data\object\type\ObjectTypeCache; use wcf\system\exception\PermissionDeniedException;
use \wcf\data\user\UserProfile; use wcf\system\WCF;
use \wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF;
/** /**
* The mute command creates a new be.bastelstu.chat.suspension.mute suspension. * The mute command creates a new be.bastelstu.chat.suspension.mute suspension.
*/ */
class MuteCommand extends AbstractSuspensionCommand implements ICommand { class MuteCommand extends AbstractSuspensionCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Mute'; return 'Bastelstu.be/Chat/Command/Mute';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getObjectTypeName() { public function getObjectTypeName()
{
return 'be.bastelstu.chat.suspension.mute'; return 'be.bastelstu.chat.suspension.mute';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function checkPermissions($parameters, Room $room, UserProfile $user) { protected function checkPermissions($parameters, Room $room, UserProfile $user)
{
$permission = $user->getPermission('mod.chat.canMute'); $permission = $user->getPermission('mod.chat.canMute');
if (!$this->isGlobally($parameters)) { if (!$this->isGlobally($parameters)) {
$permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute');
} }
if (!$permission) throw new PermissionDeniedException(); if (!$permission) {
throw new PermissionDeniedException();
}
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,38 +15,47 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\message\MessageEditor; use chat\data\message\MessageEditor;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF; use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\WCF;
/** /**
* The plain command creates a normal chat message * The plain command creates a normal chat message
*/ */
class PlainCommand extends AbstractInputProcessedCommand implements ICommand { class PlainCommand extends AbstractInputProcessedCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function allowWithoutTrigger() { public function allowWithoutTrigger()
{
return true; return true;
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Plain'; return 'Bastelstu.be/Chat/Command/Plain';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!$room->canWritePublicly($user)) throw new PermissionDeniedException(); if (!$room->canWritePublicly($user)) {
throw new PermissionDeniedException();
}
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
$this->validateText(); $this->validateText();
@ -54,30 +64,39 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.plain'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.plain');
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID $message = (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'message' => $this->processor->getHtml(),
]),
],
'updateTimestamp' => true,
'grantPoints' => true,
] ]
, 'updateTimestamp' => true ))->executeAction()['returnValues'];
, 'grantPoints' => true
]
)
)->executeAction()['returnValues'];
$this->processor->setObjectID($message->messageID); $this->processor->setObjectID($message->messageID);
if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) {
(new MessageEditor($message))->update([ (new MessageEditor($message))->update([
'hasEmbeddedObjects' => 1 'hasEmbeddedObjects' => 1,
]); ]);
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,21 +15,23 @@
namespace chat\system\command; namespace chat\system\command;
use \wcf\data\user\User; use wcf\data\user\User;
use \wcf\system\exception\UserInputException; use wcf\system\exception\UserInputException;
use \wcf\system\WCF; use wcf\system\WCF;
/** /**
* Adds helpful functions for commands that operate on a user. * Adds helpful functions for commands that operate on a user.
*/ */
trait TNeedsUser { trait TNeedsUser
{
/** /**
* Returns the user with the given username. * Returns the user with the given username.
* *
* @param string $username * @param string $username
* @return \wcf\data\user\User * @return \wcf\data\user\User
*/ */
protected function getUser($username) { protected function getUser($username)
{
static $cache = [ ]; static $cache = [ ];
if (!isset($cache[$username])) { if (!isset($cache[$username])) {
$cache[$username] = User::getUserByUsername($username); $cache[$username] = User::getUserByUsername($username);
@ -43,10 +46,21 @@ protected function getUser($username) {
* @param string $username * @param string $username
* @return \wcf\data\user\User * @return \wcf\data\user\User
*/ */
protected function assertUser($username) { protected function assertUser($username)
{
$user = $this->getUser($username); $user = $this->getUser($username);
if (!$user->userID) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.userNotFound', [ 'username' => $username ])); if (!$user->userID) {
throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'chat.error.userNotFound',
[
'username' => $username,
]
)
);
}
return $user; return $user;
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,40 +15,51 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\message\MessageEditor; use chat\data\message\MessageEditor;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\exception\PermissionDeniedException;
use \wcf\system\exception\UserInputException; use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use \wcf\system\WCF; use wcf\system\WCF;
/** /**
* TeamCommand sends a broadcast to all team members. * TeamCommand sends a broadcast to all team members.
*/ */
class TeamCommand extends AbstractInputProcessedCommand implements ICommand { class TeamCommand extends AbstractInputProcessedCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Team'; return 'Bastelstu.be/Chat/Command/Team';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canTeam'); return $user->getPermission('mod.chat.canTeam');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
if (!$user->getPermission('mod.chat.canTeam')) throw new PermissionDeniedException(); if (!$user->getPermission('mod.chat.canTeam')) {
throw new PermissionDeniedException();
}
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
$this->validateText(); $this->validateText();
@ -56,29 +68,37 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.team'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.team');
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID $message = (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'message' => $this->processor->getHtml() ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'message' => $this->processor->getHtml(),
]),
], 'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction()['returnValues'];
]
)
)->executeAction()['returnValues'];
$this->processor->setObjectID($message->messageID); $this->processor->setObjectID($message->messageID);
if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) {
(new MessageEditor($message))->update([ (new MessageEditor($message))->update([
'hasEmbeddedObjects' => 1 'hasEmbeddedObjects' => 1,
]); ]);
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,46 +15,80 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use chat\data\room\RoomAction;
use \wcf\system\exception\PermissionDeniedException; use wcf\data\user\UserProfile;
use \wcf\system\exception\UserInputException; use wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF; use wcf\system\exception\UserInputException;
use wcf\system\WCF;
/** /**
* The temproom command allows a user to manage temporary rooms. * The temproom command allows a user to manage temporary rooms.
*/ */
class TemproomCommand extends AbstractCommand implements ICommand { class TemproomCommand extends AbstractCommand implements ICommand
{
use TNeedsUser; use TNeedsUser;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Temproom'; return 'Bastelstu.be/Chat/Command/Temproom';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
switch ($this->assertParameter($parameters, 'type')) { switch ($this->assertParameter($parameters, 'type')) {
case 'create': case 'create':
if (!$user->getPermission('user.chat.canTemproom')) throw new PermissionDeniedException(); if (!$user->getPermission('user.chat.canTemproom')) {
throw new PermissionDeniedException();
}
break; break;
case 'invite': case 'invite':
if (!$room->isTemporary) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.notInTemproom')); if (!$room->isTemporary) {
if ($room->ownerID !== $user->userID) throw new PermissionDeniedException(); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable('chat.error.notInTemproom')
);
}
if ($room->ownerID !== $user->userID) {
throw new PermissionDeniedException();
}
$recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username'))); $recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username')));
if ($recipient->isIgnoredUser($user->userID)) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.userIgnoresYou', [ 'user' => $recipient ])); if ($recipient->isIgnoredUser($user->userID)) {
throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'chat.error.userIgnoresYou',
[
'user' => $recipient,
]
)
);
}
break; break;
case 'delete': case 'delete':
if (!$room->isTemporary) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.notInTemproom')); if (!$room->isTemporary) {
if ($room->ownerID !== $user->userID) throw new PermissionDeniedException(); throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'chat.error.notInTemproom'
)
);
}
if ($room->ownerID !== $user->userID) {
throw new PermissionDeniedException();
}
break; break;
default: default:
throw new UserInputException('message'); throw new UserInputException('message');
@ -63,34 +98,51 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
switch ($this->assertParameter($parameters, 'type')) { switch ($this->assertParameter($parameters, 'type')) {
case 'create': case 'create':
$fields = [ 'title' => WCF::getLanguage()->getDynamicVariable('chat.room.temporary.blueprint', [ 'user' => $user ]) $fields = [
, 'topic' => '' 'title' => WCF::getLanguage()->getDynamicVariable(
, 'position' => 999 'chat.room.temporary.blueprint',
, 'isTemporary' => true [
, 'ownerID' => $user->userID 'user' => $user,
]
),
'topic' => '',
'position' => 999,
'isTemporary' => true,
'ownerID' => $user->userID,
]; ];
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
// create room // create room
$tempRoom = (new \chat\data\room\RoomAction([], 'create', [ 'data' => $fields ]))->executeAction()['returnValues']; $tempRoom = (new RoomAction([], 'create', [
'data' => $fields,
]))->executeAction()['returnValues'];
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomCreated'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomCreated');
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'room' => $tempRoom ]) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'room' => $tempRoom,
]),
], 'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
return; return;
case 'invite': case 'invite':
$recipient = $this->getUser($this->assertParameter($parameters, 'username')); $recipient = $this->getUser($this->assertParameter($parameters, 'username'));
@ -101,33 +153,46 @@ public function execute($parameters, Room $room, UserProfile $user = null) {
VALUES (?, ?)"; VALUES (?, ?)";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ $recipient->userID, $room->roomID ]); $statement->execute([ $recipient->userID, $room->roomID ]);
} } catch (\wcf\system\database\DatabaseException $e) {
catch (\wcf\system\database\DatabaseException $e) {
WCF::getDB()->rollBackTransaction(); WCF::getDB()->rollBackTransaction();
// Duplicate key errors don't cause harm. // Duplicate key errors don't cause harm.
if ((string) $e->getCode() !== '23000') throw $e; if ((string)$e->getCode() !== '23000') {
throw $e;
}
return; return;
} }
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomInvited'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.temproomInvited');
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'recipient' => $recipient->userID 'roomID' => $room->roomID,
, 'recipientName' => $recipient->username 'userID' => $user->userID,
]) 'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'recipient' => $recipient->userID,
'recipientName' => $recipient->username,
]),
],
'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
return; return;
case 'delete': case 'delete':
(new \chat\data\room\RoomAction([ $room ], 'delete'))->executeAction(); (new RoomAction(
[
$room,
],
'delete'
))->executeAction();
return; return;
default: default:
throw new UserInputException('message'); throw new UserInputException('message');

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,51 +15,59 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\Suspension; use chat\data\suspension\Suspension;
use \chat\data\suspension\SuspensionAction; use chat\system\permission\PermissionHandler;
use \chat\system\permission\PermissionHandler; use wcf\data\user\UserProfile;
use \wcf\data\object\type\ObjectTypeCache; use wcf\system\exception\PermissionDeniedException;
use \wcf\data\user\UserProfile; use wcf\system\WCF;
use \wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF;
/** /**
* The unban command revokes a new be.bastelstu.chat.suspension.ban suspension. * The unban command revokes a new be.bastelstu.chat.suspension.ban suspension.
*/ */
class UnbanCommand extends AbstractUnsuspensionCommand implements ICommand { class UnbanCommand extends AbstractUnsuspensionCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Unban'; return 'Bastelstu.be/Chat/Command/Unban';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); return $user->getPermission('mod.chat.canBan') || PermissionHandler::get($user)->getPermission($room, 'mod.canBan');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getObjectTypeName() { public function getObjectTypeName()
{
return 'be.bastelstu.chat.suspension.ban'; return 'be.bastelstu.chat.suspension.ban';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function checkPermissions($parameters, Room $room, UserProfile $user) { protected function checkPermissions($parameters, Room $room, UserProfile $user)
{
$permission = $user->getPermission('mod.chat.canBan'); $permission = $user->getPermission('mod.chat.canBan');
if (!$this->isGlobally($parameters)) { if (!$this->isGlobally($parameters)) {
$permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan'); $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canBan');
} }
if (!$permission) throw new PermissionDeniedException(); if (!$permission) {
throw new PermissionDeniedException();
}
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,50 +15,58 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\room\Room; use chat\data\room\Room;
use \chat\data\suspension\SuspensionAction; use chat\system\permission\PermissionHandler;
use \chat\system\permission\PermissionHandler; use wcf\data\user\UserProfile;
use \wcf\data\object\type\ObjectTypeCache; use wcf\system\exception\PermissionDeniedException;
use \wcf\data\user\UserProfile; use wcf\system\WCF;
use \wcf\system\exception\PermissionDeniedException;
use \wcf\system\WCF;
/** /**
* The unmute command revokes a new be.bastelstu.chat.suspension.mute suspension. * The unmute command revokes a new be.bastelstu.chat.suspension.mute suspension.
*/ */
class UnmuteCommand extends AbstractUnsuspensionCommand implements ICommand { class UnmuteCommand extends AbstractUnsuspensionCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Unmute'; return 'Bastelstu.be/Chat/Command/Unmute';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function isAvailable(Room $room, UserProfile $user = null) { public function isAvailable(Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); return $user->getPermission('mod.chat.canMute') || PermissionHandler::get($user)->getPermission($room, 'mod.canMute');
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getObjectTypeName() { public function getObjectTypeName()
{
return 'be.bastelstu.chat.suspension.mute'; return 'be.bastelstu.chat.suspension.mute';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
protected function checkPermissions($parameters, Room $room, UserProfile $user) { protected function checkPermissions($parameters, Room $room, UserProfile $user)
{
$permission = $user->getPermission('mod.chat.canMute'); $permission = $user->getPermission('mod.chat.canMute');
if (!$this->isGlobally($parameters)) { if (!$this->isGlobally($parameters)) {
$permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute'); $permission = $permission || PermissionHandler::get($user)->getPermission($room, 'mod.canMute');
} }
if (!$permission) throw new PermissionDeniedException(); if (!$permission) {
throw new PermissionDeniedException();
}
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,61 +15,75 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\User; use chat\data\room\RoomList;
use \wcf\data\user\UserProfile; use chat\data\user\User as ChatUser;
use wcf\data\user\UserProfile;
use wcf\system\WCF;
/** /**
* The where command shows the distribution of users among * The where command shows the distribution of users among
* the different chat rooms. * the different chat rooms.
*/ */
class WhereCommand extends AbstractCommand implements ICommand { class WhereCommand extends AbstractCommand implements ICommand
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Where'; return 'Bastelstu.be/Chat/Command/Where';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.where'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.where');
$roomList = new \chat\data\room\RoomList(); $roomList = new RoomList();
$roomList->readObjects(); $roomList->readObjects();
$rooms = array_map(function (Room $room) { $rooms = \array_map(static function (Room $room) {
$users = array_map(function (\chat\data\user\User $user) { $users = \array_map(static function (ChatUser $user) {
return $user->jsonSerialize(); return $user->jsonSerialize();
}, $room->getUsers()); }, $room->getUsers());
return [ 'roomID' => $room->roomID return [
, 'users' => array_values($users) 'roomID' => $room->roomID,
'users' => \array_values($users),
]; ];
}, array_filter($roomList->getObjects(), function (Room $room) { }, \array_filter($roomList->getObjects(), static function (Room $room) {
return $room->canSee(); return $room->canSee();
})); }));
(new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize($rooms) 'roomID' => $room->roomID,
'userID' => $user->userID,
'username' => $user->username,
'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize($rooms),
], 'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction();
]
)
)->executeAction();
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,35 +15,51 @@
namespace chat\system\command; namespace chat\system\command;
use \chat\data\message\MessageAction; use chat\data\message\MessageAction;
use \chat\data\message\MessageEditor; use chat\data\message\MessageEditor;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use \wcf\system\exception\UserInputException; use wcf\system\exception\UserInputException;
use \wcf\system\WCF; use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
use wcf\system\WCF;
/** /**
* The whisper command creates a private message * The whisper command creates a private message
* between two chat users. * between two chat users.
*/ */
class WhisperCommand extends AbstractInputProcessedCommand implements ICommand { class WhisperCommand extends AbstractInputProcessedCommand implements ICommand
{
use TNeedsUser; use TNeedsUser;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/Command/Whisper'; return 'Bastelstu.be/Chat/Command/Whisper';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function validate($parameters, Room $room, UserProfile $user = null) { public function validate($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username'))); $recipient = new UserProfile($this->assertUser($this->assertParameter($parameters, 'username')));
if ($recipient->isIgnoredUser($user->userID)) throw new UserInputException('message', WCF::getLanguage()->getDynamicVariable('chat.error.userIgnoresYou', [ 'user' => $recipient ])); if ($recipient->isIgnoredUser($user->userID)) {
throw new UserInputException(
'message',
WCF::getLanguage()->getDynamicVariable(
'chat.error.userIgnoresYou',
[
'user' => $recipient,
]
)
);
}
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
$this->validateText(); $this->validateText();
@ -51,33 +68,41 @@ public function validate($parameters, Room $room, UserProfile $user = null) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function execute($parameters, Room $room, UserProfile $user = null) { public function execute($parameters, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.whisper'); $objectTypeID = $this->getMessageObjectTypeID('be.bastelstu.chat.messageType.whisper');
$recipient = $this->assertUser($this->assertParameter($parameters, 'username')); $recipient = $this->assertUser($this->assertParameter($parameters, 'username'));
$this->setText($this->assertParameter($parameters, 'text')); $this->setText($this->assertParameter($parameters, 'text'));
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
$message = (new MessageAction([ ], 'create', [ 'data' => [ 'roomID' => $room->roomID $message = (new MessageAction(
, 'userID' => $user->userID [ ],
, 'username' => $user->username 'create',
, 'time' => TIME_NOW [
, 'objectTypeID' => $objectTypeID 'data' => [
, 'payload' => serialize([ 'message' => $this->processor->getHtml() 'roomID' => $room->roomID,
, 'recipient' => $recipient->userID 'userID' => $user->userID,
, 'recipientName' => $recipient->username 'username' => $user->username,
]) 'time' => TIME_NOW,
'objectTypeID' => $objectTypeID,
'payload' => \serialize([
'message' => $this->processor->getHtml(),
'recipient' => $recipient->userID,
'recipientName' => $recipient->username,
]),
],
'updateTimestamp' => true,
] ]
, 'updateTimestamp' => true ))->executeAction()['returnValues'];
]
)
)->executeAction()['returnValues'];
$this->processor->setObjectID($message->messageID); $this->processor->setObjectID($message->messageID);
if (\wcf\system\message\embedded\object\MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) { if (MessageEmbeddedObjectManager::getInstance()->registerObjects($this->processor)) {
(new MessageEditor($message))->update([ (new MessageEditor($message))->update([
'hasEmbeddedObjects' => 1 'hasEmbeddedObjects' => 1,
]); ]);
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,15 +15,17 @@
namespace chat\system\condition\room; namespace chat\system\condition\room;
use \chat\data\room\RoomList; use chat\data\room\RoomList;
use \wcf\data\DatabaseObject; use wcf\data\DatabaseObjectList;
use \wcf\data\DatabaseObjectList; use wcf\system\condition\AbstractCheckboxCondition;
use \wcf\system\exception\SystemException; use wcf\system\condition\IObjectListCondition;
use wcf\system\exception\ParentClassException;
/** /**
* Condition implementation for rooms to only include non-empty rooms in lists. * Condition implementation for rooms to only include non-empty rooms in lists.
*/ */
class RoomFilledCondition extends \wcf\system\condition\AbstractCheckboxCondition implements \wcf\system\condition\IObjectListCondition { class RoomFilledCondition extends AbstractCheckboxCondition implements IObjectListCondition
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -36,9 +39,10 @@ class RoomFilledCondition extends \wcf\system\condition\AbstractCheckboxConditio
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData) { public function addObjectListCondition(DatabaseObjectList $objectList, array $conditionData)
{
if (!($objectList instanceof RoomList)) { if (!($objectList instanceof RoomList)) {
throw new \wcf\system\exception\ParentClassException(get_class($objectList), RoomList::class); throw new ParentClassException(\get_class($objectList), RoomList::class);
} }
$objectList->getConditionBuilder()->add("EXISTS (SELECT 1 FROM chat" . WCF_N . "_room_to_user r2u WHERE r2u.roomID = room.roomID AND active = ?)", [ 1 ]); $objectList->getConditionBuilder()->add("EXISTS (SELECT 1 FROM chat" . WCF_N . "_room_to_user r2u WHERE r2u.roomID = room.roomID AND active = ?)", [ 1 ]);

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,22 +15,30 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \wcf\system\WCF; use chat\data\message\MessageAction;
use chat\data\user\UserAction as ChatUserAction;
use wcf\system\event\listener\IParameterizedEventListener;
use wcf\system\WCF;
/** /**
* Vaporizes unneeded data. * Vaporizes unneeded data.
*/ */
class HourlyCleanUpCronjobExecuteChatCleanUpListener implements \wcf\system\event\listener\IParameterizedEventListener { class HourlyCleanUpCronjobExecuteChatCleanUpListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
(new \chat\data\message\MessageAction([ ], 'prune'))->executeAction(); {
(new \chat\data\user\UserAction([], 'clearDeadSessions'))->executeAction(); (new MessageAction([ ], 'prune'))->executeAction();
(new ChatUserAction([ ], 'clearDeadSessions'))->executeAction();
$sql = "UPDATE chat1_room_to_user $sql = "UPDATE chat1_room_to_user
SET active = ? SET active = ?
WHERE (roomID, userID) NOT IN (SELECT roomID, userID FROM chat1_session) WHERE (roomID, userID) NOT IN (
SELECT roomID, userID
FROM chat1_session
)
AND active = ?"; AND active = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ 0, 1 ]); $statement->execute([ 0, 1 ]);

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,29 +15,37 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \wcf\system\WCF; use chat\data\room\RoomAction;
use chat\data\room\RoomList;
use wcf\system\event\listener\IParameterizedEventListener;
use wcf\system\WCF;
/** /**
* Removes empty temporary rooms. * Removes empty temporary rooms.
*/ */
class HourlyCleanUpCronjobExecuteTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { class HourlyCleanUpCronjobExecuteTemproomListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
$roomList = new \chat\data\room\RoomList(); {
$roomList = new RoomList();
$roomList->getConditionBuilder()->add('isTemporary = ?', [ 1 ]); $roomList->getConditionBuilder()->add('isTemporary = ?', [ 1 ]);
$roomList->readObjects(); $roomList->readObjects();
$toDelete = [ ]; $toDelete = [ ];
WCF::getDB()->beginTransaction(); WCF::getDB()->beginTransaction();
foreach ($roomList as $room) { foreach ($roomList as $room) {
if (count($room->getUsers()) === 0) { if (\count($room->getUsers()) === 0) {
$toDelete[] = $room; $toDelete[] = $room;
} }
} }
if (!empty($toDelete)) { if (!empty($toDelete)) {
(new \chat\data\room\RoomAction($toDelete, 'delete'))->executeAction(); (new RoomAction(
$toDelete,
'delete'
))->executeAction();
} }
WCF::getDB()->commitTransaction(); WCF::getDB()->commitTransaction();
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,18 +15,21 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\data\suspension\Suspension; use chat\data\room\RoomCache;
use \wcf\data\object\type\ObjectTypeCache; use chat\data\suspension\Suspension;
use \wcf\system\WCF; use chat\data\suspension\SuspensionList;
use wcf\system\event\listener\IParameterizedEventListener;
/** /**
* Fetches information about the users suspensions * Fetches information about the users suspensions
*/ */
class InfoCommandSuspensionsListener implements \wcf\system\event\listener\IParameterizedEventListener { class InfoCommandSuspensionsListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
{
if (!$parameters['caller']->getPermission('admin.chat.canManageSuspensions')) { if (!$parameters['caller']->getPermission('admin.chat.canManageSuspensions')) {
return; return;
} }
@ -34,24 +38,25 @@ public function execute($eventObj, $className, $eventName, array &$parameters) {
$parameters['data']['suspensions'] = [ ]; $parameters['data']['suspensions'] = [ ];
$suspensionList = new \chat\data\suspension\SuspensionList(); $suspensionList = new SuspensionList();
$suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]); $suspensionList->getConditionBuilder()->add('(expires IS NULL OR expires > ?)', [ TIME_NOW ]);
$suspensionList->getConditionBuilder()->add('revoked IS NULL'); $suspensionList->getConditionBuilder()->add('revoked IS NULL');
$suspensionList->getConditionBuilder()->add('userID = ?', [ $target->userID ]); $suspensionList->getConditionBuilder()->add('userID = ?', [ $target->userID ]);
$suspensionList->sqlOrderBy = 'expires ASC, time ASC'; $suspensionList->sqlOrderBy = 'expires ASC, time ASC';
$suspensionList->readObjects(); $suspensionList->readObjects();
$suspensions = array_filter($suspensionList->getObjects(), function (Suspension $suspension) { $suspensions = \array_filter($suspensionList->getObjects(), static function (Suspension $suspension) {
return $suspension->isActive(); return $suspension->isActive();
}); });
$parameters['data']['suspensions'] = array_values(array_map(function ($suspension) { $parameters['data']['suspensions'] = \array_values(\array_map(static function ($suspension) {
$room = \chat\data\room\RoomCache::getInstance()->getRoom($suspension->roomID); $room = RoomCache::getInstance()->getRoom($suspension->roomID);
$suspension = $suspension->jsonSerialize(); $suspension = $suspension->jsonSerialize();
if ($room) { if ($room) {
$suspension['room'] = [ 'title' => $room->getTitle() $suspension['room'] = [
, 'link' => $room->getLink() 'title' => $room->getTitle(),
'link' => $room->getLink(),
]; ];
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,26 +15,32 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\data\command\CommandCache; use chat\data\command\CommandCache;
use \wcf\system\cache\runtime\UserProfileRuntimeCache; use wcf\data\package\PackageCache;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\event\listener\IParameterizedEventListener;
/** /**
* Adds moderator permissiosn to the user object. * Adds moderator permissions to the user object.
*/ */
class RoomActionGetUsersModeratorListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomActionGetUsersModeratorListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$users) { public function execute($eventObj, $className, $eventName, array &$users)
{
$room = $eventObj->getObjects()[0]->getDecoratedObject(); $room = $eventObj->getObjects()[0]->getDecoratedObject();
$package = \wcf\data\package\PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat'); $package = PackageCache::getInstance()->getPackageByIdentifier('be.bastelstu.chat');
$muteCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'mute')->getProcessor(); $muteCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'mute')->getProcessor();
$banCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'ban')->getProcessor(); $banCommand = CommandCache::getInstance()->getCommandByPackageAndIdentifier($package, 'ban')->getProcessor();
$users = array_map(function (array $user) use ($room, $muteCommand, $banCommand) { $users = \array_map(static function (array $user) use ($room, $muteCommand, $banCommand) {
$userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']); $userProfile = UserProfileRuntimeCache::getInstance()->getObject($user['userID']);
if (!isset($user['permissions'])) $user['permissions'] = []; if (!isset($user['permissions'])) {
$user['permissions'] = [];
}
$user['permissions']['canMute'] = $muteCommand->isAvailable($room, $userProfile); $user['permissions']['canMute'] = $muteCommand->isAvailable($room, $userProfile);
$user['permissions']['canBan'] = $banCommand->isAvailable($room, $userProfile); $user['permissions']['canBan'] = $banCommand->isAvailable($room, $userProfile);

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,25 +15,39 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\data\suspension\Suspension; use chat\data\suspension\Suspension;
use \wcf\data\object\type\ObjectTypeCache; use wcf\data\object\type\ObjectTypeCache;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\event\listener\IParameterizedEventListener;
use \wcf\system\WCF; use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
/** /**
* Denies access to banned users. * Denies access to banned users.
*/ */
class RoomCanJoinBanListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomCanJoinBanListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', 'be.bastelstu.chat.suspension.ban'); {
if (!$objectTypeID) throw new \LogicException('Unreachable'); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.suspension',
'be.bastelstu.chat.suspension.ban'
);
if (!$objectTypeID) {
throw new \LogicException('Unreachable');
}
$suspensions = Suspension::getActiveSuspensionsByTriple($objectTypeID, $parameters['user']->getDecoratedObject(), $eventObj); $suspensions = Suspension::getActiveSuspensionsByTriple(
$objectTypeID,
$parameters['user']->getDecoratedObject(),
$eventObj
);
if (!empty($suspensions)) { if (!empty($suspensions)) {
$parameters['result'] = new PermissionDeniedException(WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.ban')); $parameters['result'] = new PermissionDeniedException(
WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.ban')
);
} }
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,29 +15,43 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\system\permission\PermissionHandler; use chat\data\user\User as ChatUser;
use \wcf\system\exception\PermissionDeniedException; use chat\system\permission\PermissionHandler;
use \wcf\system\WCF; use wcf\system\event\listener\IParameterizedEventListener;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
/** /**
* Denies access when room is full. * Denies access when room is full.
*/ */
class RoomCanJoinUserLimitListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomCanJoinUserLimitListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
if ($eventObj->userLimit === 0) return; {
if ($eventObj->userLimit === 0) {
return;
}
$users = $eventObj->getUsers(); $users = $eventObj->getUsers();
if (count($users) < $eventObj->userLimit) return; if (\count($users) < $eventObj->userLimit) {
return;
}
$user = new \chat\data\user\User($parameters['user']->getDecoratedObject()); $user = new ChatUser($parameters['user']->getDecoratedObject());
if ($user->isInRoom($eventObj)) return; if ($user->isInRoom($eventObj)) {
return;
}
$canIgnoreLimit = PermissionHandler::get($parameters['user'])->getPermission($eventObj, 'mod.canIgnoreUserLimit'); $canIgnoreLimit = PermissionHandler::get($parameters['user'])->getPermission($eventObj, 'mod.canIgnoreUserLimit');
if ($canIgnoreLimit) return; if ($canIgnoreLimit) {
return;
}
$parameters['result'] = new PermissionDeniedException(WCF::getLanguage()->get('chat.error.roomFull')); $parameters['result'] = new PermissionDeniedException(
WCF::getLanguage()->get('chat.error.roomFull')
);
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
@ -14,30 +15,42 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\system\permission\PermissionHandler; use chat\data\user\User as ChatUser;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\event\listener\IParameterizedEventListener;
use \wcf\system\WCF; use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
/** /**
* Denies access to temporary rooms, unless invited. * Denies access to temporary rooms, unless invited.
*/ */
class RoomCanSeeTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomCanSeeTemproomListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
if (!$eventObj->isTemporary) return; {
if (!$eventObj->isTemporary) {
return;
}
$user = new \chat\data\user\User($parameters['user']->getDecoratedObject()); $user = new ChatUser($parameters['user']->getDecoratedObject());
if ($eventObj->ownerID === $user->userID) return; if ($eventObj->ownerID === $user->userID) {
return;
}
$sql = "SELECT COUNT(*) $sql = "SELECT COUNT(*)
FROM chat1_room_temporary_invite FROM chat1_room_temporary_invite
WHERE userID = ? WHERE userID = ?
AND roomID = ?"; AND roomID = ?";
$statement = WCF::getDB()->prepare($sql); $statement = WCF::getDB()->prepare($sql);
$statement->execute([ $user->userID, $eventObj->roomID ]); $statement->execute([
if ($statement->fetchSingleColumn() > 0) return; $user->userID,
$eventObj->roomID,
]);
if ($statement->fetchSingleColumn() > 0) {
return;
}
$parameters['result'] = new PermissionDeniedException(); $parameters['result'] = new PermissionDeniedException();
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,25 +15,39 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\data\suspension\Suspension; use chat\data\suspension\Suspension;
use \wcf\data\object\type\ObjectTypeCache; use wcf\data\object\type\ObjectTypeCache;
use \wcf\system\exception\PermissionDeniedException; use wcf\system\event\listener\IParameterizedEventListener;
use \wcf\system\WCF; use wcf\system\exception\PermissionDeniedException;
use wcf\system\WCF;
/** /**
* Denies access to muted users. * Denies access to muted users.
*/ */
class RoomCanWritePubliclyMuteListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomCanWritePubliclyMuteListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
$objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName('be.bastelstu.chat.suspension', 'be.bastelstu.chat.suspension.mute'); {
if (!$objectTypeID) throw new \LogicException('Unreachable'); $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeIDByName(
'be.bastelstu.chat.suspension',
'be.bastelstu.chat.suspension.mute'
);
if (!$objectTypeID) {
throw new \LogicException('Unreachable');
}
$suspensions = Suspension::getActiveSuspensionsByTriple($objectTypeID, $parameters['user']->getDecoratedObject(), $eventObj); $suspensions = Suspension::getActiveSuspensionsByTriple(
$objectTypeID,
$parameters['user']->getDecoratedObject(),
$eventObj
);
if (!empty($suspensions)) { if (!empty($suspensions)) {
$parameters['result'] = new PermissionDeniedException(WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.mute')); $parameters['result'] = new PermissionDeniedException(
WCF::getLanguage()->getDynamicVariable('chat.suspension.info.be.bastelstu.chat.suspension.mute')
);
} }
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,16 +15,21 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use wcf\system\event\listener\IParameterizedEventListener;
use wcf\system\exception\PermissionDeniedException;
/** /**
* Disallow editing of temprooms in ACP. * Disallow editing of temprooms in ACP.
*/ */
class RoomEditFormTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomEditFormTemproomListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
{
if ($eventObj->room->isTemporary) { if ($eventObj->room->isTemporary) {
throw new \wcf\system\exception\PermissionDeniedException(); throw new PermissionDeniedException();
} }
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,14 +15,18 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use wcf\system\event\listener\IParameterizedEventListener;
/** /**
* Hides temprooms in ACP. * Hides temprooms in ACP.
*/ */
class RoomListPageTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { class RoomListPageTemproomListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
{
$eventObj->objectList->getConditionBuilder()->add('isTemporary = ?', [ 0 ]); $eventObj->objectList->getConditionBuilder()->add('isTemporary = ?', [ 0 ]);
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 3 * License, use of this software will be governed by version 3
@ -14,17 +15,20 @@
namespace chat\system\event\listener; namespace chat\system\event\listener;
use \chat\data\room\Room; use chat\data\room\Room;
use wcf\system\event\listener\IParameterizedEventListener;
/** /**
* Hides temprooms in ACP. * Hides temprooms in ACP.
*/ */
class SuspensionListPageTemproomListener implements \wcf\system\event\listener\IParameterizedEventListener { class SuspensionListPageTemproomListener implements IParameterizedEventListener
{
/** /**
* @see \wcf\system\event\listener\IParameterizedEventListener::execute() * @inheritDoc
*/ */
public function execute($eventObj, $className, $eventName, array &$parameters) { public function execute($eventObj, $className, $eventName, array &$parameters)
$eventObj->availableRooms = array_filter($eventObj->availableRooms, function (Room $room) { {
$eventObj->availableRooms = \array_filter($eventObj->availableRooms, static function (Room $room) {
return !$room->isTemporary; return !$room->isTemporary;
}); });
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,62 +15,86 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use chat\data\message\Message;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\system\WCF;
/** /**
* AttachmentMessageType represents a message with an attached file. * AttachmentMessageType represents a message with an attached file.
*/ */
class AttachmentMessageType implements IMessageType, IDeletableMessageType { class AttachmentMessageType implements IMessageType, IDeletableMessageType
{
use TCanSeeInSameRoom; use TCanSeeInSameRoom;
/** /**
* HtmlOutputProcessor to use. * HtmlOutputProcessor to use.
* @var \wcf\system\html\output\HtmlOutputProcessor * @var \wcf\system\html\output\HtmlOutputProcessor
*/ */
protected $processor = null; protected $processor;
public function __construct() { public function __construct()
$this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); {
$this->processor = new HtmlOutputProcessor();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Plain'; return 'Bastelstu.be/Chat/MessageType/Plain';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function canDelete(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canDelete'); return $user->getPermission('mod.chat.canDelete');
} }
/** /**
* @see \chat\system\message\type\IMessageType::getPayload() * @inheritDoc
*/ */
public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function getPayload(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$payload = $message->payload; $payload = $message->payload;
$payload['formattedMessage'] = null; $payload['formattedMessage'] = null;
$payload['plaintextMessage'] = null; $payload['plaintextMessage'] = null;
$parameters = [ 'message' => $message $parameters = [
, 'user' => $user 'message' => $message,
, 'payload' => $payload 'user' => $user,
'payload' => $payload,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters);
if ($parameters['payload']['formattedMessage'] === null) { if ($parameters['payload']['formattedMessage'] === null) {
$this->processor->setOutputType('text/html'); $this->processor->setOutputType('text/html');
$this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); $this->processor->process(
$parameters['payload']['message'],
'be.bastelstu.chat.message',
$message->messageID
);
$parameters['payload']['formattedMessage'] = $this->processor->getHtml(); $parameters['payload']['formattedMessage'] = $this->processor->getHtml();
} }
if ($parameters['payload']['plaintextMessage'] === null) { if ($parameters['payload']['plaintextMessage'] === null) {
$this->processor->setOutputType('text/plain'); $this->processor->setOutputType('text/plain');
$this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); $this->processor->process(
$parameters['payload']['message'],
'be.bastelstu.chat.message',
$message->messageID
);
$parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); $parameters['payload']['plaintextMessage'] = $this->processor->getHtml();
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,67 +15,80 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* AwayMessageType represents a notice that a user now is away from chat. * AwayMessageType represents a notice that a user now is away from chat.
*/ */
class AwayMessageType implements IMessageType { class AwayMessageType implements IMessageType
{
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Away'; return 'Bastelstu.be/Chat/MessageType/Away';
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$roomIDs = array_map(function ($item) { $roomIDs = \array_map(static function ($item) {
return $item['roomID']; return $item['roomID'];
}, $message->payload['rooms']); }, $message->payload['rooms']);
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => in_array($room->roomID, $roomIDs, true) 'user' => $user,
'canSee' => \in_array($room->roomID, $roomIDs, true),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @inheritDoc
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$roomIDs = array_map(function ($item) { $roomIDs = \array_map(static function ($item) {
return $item['roomID']; return $item['roomID'];
}, $message->payload['rooms']); }, $message->payload['rooms']);
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => in_array($room->roomID, $roomIDs, true) 'user' => $user,
'canSee' => \in_array($room->roomID, $roomIDs, true),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,67 +15,80 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* BackMessageType represents a notice that a user now is now back. * BackMessageType represents a notice that a user now is now back.
*/ */
class BackMessageType implements IMessageType { class BackMessageType implements IMessageType
{
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Back'; return 'Bastelstu.be/Chat/MessageType/Back';
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$roomIDs = array_map(function ($item) { $roomIDs = \array_map(static function ($item) {
return $item['roomID']; return $item['roomID'];
}, $message->payload['rooms']); }, $message->payload['rooms']);
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => in_array($room->roomID, $roomIDs, true) 'user' => $user,
'canSee' => \in_array($room->roomID, $roomIDs, true),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @inheritDoc
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$roomIDs = array_map(function ($item) { $roomIDs = \array_map(static function ($item) {
return $item['roomID']; return $item['roomID'];
}, $message->payload['rooms']); }, $message->payload['rooms']);
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => in_array($room->roomID, $roomIDs, true) 'user' => $user,
'canSee' => \in_array($room->roomID, $roomIDs, true),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,59 +15,53 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\system\WCF;
/** /**
* BroadcastMessageType represents a broadcasted message. * BroadcastMessageType represents a broadcasted message.
*/ */
class BroadcastMessageType extends PlainMessageType { class BroadcastMessageType extends PlainMessageType
{
/** /**
* HtmlOutputProcessor to use. * HtmlOutputProcessor to use.
* @var \wcf\system\html\output\HtmlOutputProcessor * @var \wcf\system\html\output\HtmlOutputProcessor
*/ */
protected $processor = null; protected $processor;
public function __construct() { public function __construct()
$this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); {
$this->processor = new HtmlOutputProcessor();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Broadcast'; return 'Bastelstu.be/Chat/MessageType/Broadcast';
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$parameters = [ 'message' => $message $user = new UserProfile(WCF::getUser());
, 'room' => $room
, 'user' => $user
, 'canSee' => true
];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee'];
} }
/** $parameters = [
* @see \chat\system\message\type\IMessageType::canSeeInLog() 'message' => $message,
*/ 'room' => $room,
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { 'user' => $user,
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); 'canSee' => true,
$parameters = [ 'message' => $message
, 'room' => $room
, 'user' => $user
, 'canSee' => true
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
@ -74,16 +69,40 @@ public function canSeeInLog(Message $message, Room $room, UserProfile $user = nu
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [
'message' => $message,
'room' => $room,
'user' => $user,
'canSee' => true,
];
EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee'];
}
/**
* @inheritDoc
*/
public function canDelete(Message $message, ?UserProfile $user = null)
{
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canDelete'); return $user->getPermission('mod.chat.canDelete');
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,41 +15,46 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
/** /**
* ChatUpdateMessageType informs the chat about a back end update. * ChatUpdateMessageType informs the chat about a back end update.
*/ */
class ChatUpdateMessageType implements IMessageType { class ChatUpdateMessageType implements IMessageType
{
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/ChatUpdate'; return 'Bastelstu.be/Chat/MessageType/ChatUpdate';
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
{
return true; return true;
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @inheritDoc
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
{
return true; return true;
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,50 +15,60 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* ColorMessageType represents a color message. * ColorMessageType represents a color message.
*/ */
class ColorMessageType implements IMessageType { class ColorMessageType implements IMessageType
{
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Color'; return 'Bastelstu.be/Chat/MessageType/Color';
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => true 'user' => $user,
'canSee' => true,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @inheritDoc
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
{
return false; return false;
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,13 +15,14 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
/** /**
* An IDeletableMessageType defines that the implementing message type supports message deletion. * An IDeletableMessageType defines that the implementing message type supports message deletion.
*/ */
interface IDeletableMessageType extends IMessageType { interface IDeletableMessageType extends IMessageType
{
/** /**
* Returns whether the given user may delete the given message. If no * Returns whether the given user may delete the given message. If no
* user is given the active user should be assumed. * user is given the active user should be assumed.
@ -29,5 +31,5 @@ interface IDeletableMessageType extends IMessageType {
* @param UserProfile $user * @param UserProfile $user
* @return boolean * @return boolean
*/ */
public function canDelete(Message $message, UserProfile $user = null); public function canDelete(Message $message, ?UserProfile $user = null);
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,14 +15,15 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
/** /**
* An IMessageType defines how a message of a certain type is acted upon. * An IMessageType defines how a message of a certain type is acted upon.
*/ */
interface IMessageType { interface IMessageType
{
/** /**
* Returns the name of the JavaScript module. * Returns the name of the JavaScript module.
* *
@ -38,7 +40,7 @@ public function getJavaScriptModuleName();
* @param UserProfile $user * @param UserProfile $user
* @return boolean * @return boolean
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null); public function canSee(Message $message, Room $room, ?UserProfile $user = null);
/** /**
* Returns whether the given user may see the given message in the * Returns whether the given user may see the given message in the
@ -49,7 +51,7 @@ public function canSee(Message $message, Room $room, UserProfile $user = null);
* @param UserProfile $user * @param UserProfile $user
* @return boolean * @return boolean
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null); public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null);
/** /**
* Returns a filtered / extended version of the message payload. If no * Returns a filtered / extended version of the message payload. If no
@ -59,7 +61,7 @@ public function canSeeInLog(Message $message, Room $room, UserProfile $user = nu
* @param UserProfile $user * @param UserProfile $user
* @return array * @return array
*/ */
public function getPayload(Message $message, UserProfile $user = null); public function getPayload(Message $message, ?UserProfile $user = null);
/** /**
* Returns whether this message type supports fast select of applicable messages: * Returns whether this message type supports fast select of applicable messages:

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -17,14 +18,16 @@
/** /**
* InfoMessageType represents the reply to InfoCommand. * InfoMessageType represents the reply to InfoCommand.
*/ */
class InfoMessageType implements IMessageType { class InfoMessageType implements IMessageType
{
use TCanSeeCreator; use TCanSeeCreator;
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Info'; return 'Bastelstu.be/Chat/MessageType/Info';
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -17,14 +18,16 @@
/** /**
* JoinMessageType represents a join message. * JoinMessageType represents a join message.
*/ */
class JoinMessageType implements IMessageType { class JoinMessageType implements IMessageType
{
use TCanSeeInSameRoom; use TCanSeeInSameRoom;
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Join'; return 'Bastelstu.be/Chat/MessageType/Join';
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -17,14 +18,16 @@
/** /**
* LeaveMessageType represents a leave message. * LeaveMessageType represents a leave message.
*/ */
class LeaveMessageType implements IMessageType { class LeaveMessageType implements IMessageType
{
use TCanSeeInSameRoom; use TCanSeeInSameRoom;
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Leave'; return 'Bastelstu.be/Chat/MessageType/Leave';
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,25 +15,34 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use chat\data\message\Message;
use wcf\data\user\UserProfile;
use wcf\system\WCF;
/** /**
* MeMessageType represents an action message. * MeMessageType represents an action message.
*/ */
class MeMessageType implements IMessageType, IDeletableMessageType { class MeMessageType implements IMessageType, IDeletableMessageType
{
use TCanSeeInSameRoom; use TCanSeeInSameRoom;
use TDefaultPayload; use TDefaultPayload;
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Me'; return 'Bastelstu.be/Chat/MessageType/Me';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function canDelete(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canDelete'); return $user->getPermission('mod.chat.canDelete');
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,62 +15,86 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use chat\data\message\Message;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\system\WCF;
/** /**
* PlainMessageType represents a normal message. * PlainMessageType represents a normal message.
*/ */
class PlainMessageType implements IMessageType, IDeletableMessageType { class PlainMessageType implements IMessageType, IDeletableMessageType
{
use TCanSeeInSameRoom; use TCanSeeInSameRoom;
/** /**
* HtmlOutputProcessor to use. * HtmlOutputProcessor to use.
* @var \wcf\system\html\output\HtmlOutputProcessor * @var \wcf\system\html\output\HtmlOutputProcessor
*/ */
protected $processor = null; protected $processor;
public function __construct() { public function __construct()
$this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); {
$this->processor = new HtmlOutputProcessor();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Plain'; return 'Bastelstu.be/Chat/MessageType/Plain';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function canDelete(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canDelete'); return $user->getPermission('mod.chat.canDelete');
} }
/** /**
* @see \chat\system\message\type\IMessageType::getPayload() * @inheritDoc
*/ */
public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function getPayload(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$payload = $message->payload; $payload = $message->payload;
$payload['formattedMessage'] = null; $payload['formattedMessage'] = null;
$payload['plaintextMessage'] = null; $payload['plaintextMessage'] = null;
$parameters = [ 'message' => $message $parameters = [
, 'user' => $user 'message' => $message,
, 'payload' => $payload 'user' => $user,
'payload' => $payload,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters);
if ($parameters['payload']['formattedMessage'] === null) { if ($parameters['payload']['formattedMessage'] === null) {
$this->processor->setOutputType('text/html'); $this->processor->setOutputType('text/html');
$this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); $this->processor->process(
$parameters['payload']['message'],
'be.bastelstu.chat.message',
$message->messageID
);
$parameters['payload']['formattedMessage'] = $this->processor->getHtml(); $parameters['payload']['formattedMessage'] = $this->processor->getHtml();
} }
if ($parameters['payload']['plaintextMessage'] === null) { if ($parameters['payload']['plaintextMessage'] === null) {
$this->processor->setOutputType('text/plain'); $this->processor->setOutputType('text/plain');
$this->processor->process($parameters['payload']['message'], 'be.bastelstu.chat.message', $message->messageID); $this->processor->process(
$parameters['payload']['message'],
'be.bastelstu.chat.message',
$message->messageID
);
$parameters['payload']['plaintextMessage'] = $this->processor->getHtml(); $parameters['payload']['plaintextMessage'] = $this->processor->getHtml();
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,75 +15,92 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* SuspendMessageType informs about suspensions. * SuspendMessageType informs about suspensions.
*/ */
class SuspendMessageType implements IMessageType { class SuspendMessageType implements IMessageType
{
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Suspend'; return 'Bastelstu.be/Chat/MessageType/Suspend';
} }
/** /**
* @see \chat\system\message\type\IMessageType::getPayload() * @inheritDoc
*/ */
public function getPayload(Message $message, UserProfile $user = null) { public function getPayload(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$payload = $message->payload; $payload = $message->payload;
unset($payload['roomIDs']); unset($payload['roomIDs']);
$parameters = [ 'message' => $message $parameters = [
, 'user' => $user 'message' => $message,
, 'payload' => $payload 'user' => $user,
'payload' => $payload,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters);
return $parameters['payload']; return $parameters['payload'];
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => in_array($room->roomID, $message->payload['roomIDs'], true) 'user' => $user,
'canSee' => \in_array($room->roomID, $message->payload['roomIDs'], true),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @inheritDoc
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => in_array($room->roomID, $message->payload['roomIDs'], true) 'user' => $user,
'canSee' => \in_array($room->roomID, $message->payload['roomIDs'], true),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,27 +15,34 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* Adds a default canSee implementation that checks whether the message was created by the user and * Adds a default canSee implementation that checks whether the message was created by the user and
* whether the message belongs to the user's active room. * whether the message belongs to the user's active room.
*/ */
trait TCanSeeCreator { trait TCanSeeCreator
{
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @see \chat\system\message\type\IMessageType::canSee()
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => $user->userID === $message->userID && $message->getRoom()->roomID === $room->roomID 'user' => $user,
'canSee' => $user->userID === $message->userID && $message->getRoom()->roomID === $room->roomID,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
@ -42,25 +50,32 @@ public function canSee(Message $message, Room $room, UserProfile $user = null) {
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @see \chat\system\message\type\IMessageType::canSeeInLog()
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => false 'user' => $user,
'canSee' => false,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @see \chat\system\message\type\IMessageType::supportsFastSelect()
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
$parameters = [ 'result' => true ]; {
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); $parameters = [
'result' => true,
];
EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters);
return $parameters['result']; return $parameters['result'];
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,26 +15,33 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* Adds a default canSee implementation that checks whether the message belongs to the user's active room. * Adds a default canSee implementation that checks whether the message belongs to the user's active room.
*/ */
trait TCanSeeInSameRoom { trait TCanSeeInSameRoom
{
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @see \chat\system\message\type\IMessageType::canSee()
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => $message->getRoom()->roomID === $room->roomID 'user' => $user,
'canSee' => $message->getRoom()->roomID === $room->roomID,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
@ -41,25 +49,32 @@ public function canSee(Message $message, Room $room, UserProfile $user = null) {
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @see \chat\system\message\type\IMessageType::canSeeInLog()
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => $message->getRoom()->roomID === $room->roomID 'user' => $user,
'canSee' => $message->getRoom()->roomID === $room->roomID,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @see \chat\system\message\type\IMessageType::supportsFastSelect()
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
$parameters = [ 'result' => true ]; {
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters); $parameters = [
'result' => true,
];
EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters);
return $parameters['result']; return $parameters['result'];
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,23 +15,33 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use chat\data\message\Message;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
/** /**
* Default implementation for 'getPayload'. * Default implementation for 'getPayload'.
*/ */
trait TDefaultPayload { trait TDefaultPayload
{
/** /**
* @see \chat\system\message\type\IMessageType::getPayload() * @see \chat\system\message\type\IMessageType::getPayload()
*/ */
public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function getPayload(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$payload = $message->payload; $payload = $message->payload;
$parameters = [ 'message' => $message $parameters = [
, 'user' => $user 'message' => $message,
, 'payload' => $payload 'user' => $user,
'payload' => $payload,
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters); EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters);
return $parameters['payload']; return $parameters['payload'];
} }

View File

@ -1,11 +1,12 @@
<?php <?php
/* /*
* Copyright (c) 2010-2021 Tim Düsterhus. * Copyright (c) 2010-2022 Tim Düsterhus.
* *
* Use of this software is governed by the Business Source License * Use of this software is governed by the Business Source License
* included in the LICENSE file. * included in the LICENSE file.
* *
* Change Date: 2025-03-05 * Change Date: 2026-03-04
* *
* On the date above, in accordance with the Business Source * On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2 * License, use of this software will be governed by version 2
@ -14,76 +15,94 @@
namespace chat\system\message\type; namespace chat\system\message\type;
use \chat\data\message\Message; use chat\data\message\Message;
use \chat\data\room\Room; use chat\data\room\Room;
use \wcf\data\user\UserProfile; use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\html\output\HtmlOutputProcessor;
use wcf\system\WCF;
/** /**
* TeamMessageType represents a team internal message. * TeamMessageType represents a team internal message.
*/ */
class TeamMessageType extends PlainMessageType { class TeamMessageType extends PlainMessageType
{
/** /**
* HtmlOutputProcessor to use. * HtmlOutputProcessor to use.
* @var \wcf\system\html\output\HtmlOutputProcessor * @var \wcf\system\html\output\HtmlOutputProcessor
*/ */
protected $processor = null; protected $processor;
public function __construct() { public function __construct()
$this->processor = new \wcf\system\html\output\HtmlOutputProcessor(); {
$this->processor = new HtmlOutputProcessor();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getJavaScriptModuleName() { public function getJavaScriptModuleName()
{
return 'Bastelstu.be/Chat/MessageType/Team'; return 'Bastelstu.be/Chat/MessageType/Team';
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) { public function canDelete(Message $message, ?UserProfile $user = null)
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
return $user->getPermission('mod.chat.canDelete'); return $user->getPermission('mod.chat.canDelete');
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSee() * @inheritDoc
*/ */
public function canSee(Message $message, Room $room, UserProfile $user = null) { public function canSee(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => $user->getPermission('mod.chat.canTeam') 'user' => $user,
'canSee' => $user->getPermission('mod.chat.canTeam'),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSee', $parameters); EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see \chat\system\message\type\IMessageType::canSeeInLog() * @inheritDoc
*/ */
public function canSeeInLog(Message $message, Room $room, UserProfile $user = null) { public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
if ($user === null) $user = new UserProfile(\wcf\system\WCF::getUser()); {
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
$parameters = [ 'message' => $message $parameters = [
, 'room' => $room 'message' => $message,
, 'user' => $user 'room' => $room,
, 'canSee' => $user->getPermission('mod.chat.canTeam') 'user' => $user,
'canSee' => $user->getPermission('mod.chat.canTeam'),
]; ];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters); EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
return $parameters['canSee']; return $parameters['canSee'];
} }
/** /**
* @see»\chat\system\message\type\IMessageType::supportsFastSelect() * @inheritDoc
*/ */
public function supportsFastSelect() { public function supportsFastSelect()
{
return false; return false;
} }
} }

Some files were not shown because too many files have changed in this diff Show More