1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Fix Suspension commands and clean up

This commit is contained in:
Tim Düsterhus 2013-05-24 01:21:46 +02:00
parent d64f11b315
commit 2936b2f3aa
14 changed files with 55 additions and 45 deletions

View File

@ -23,7 +23,7 @@ class MessageAction extends \wcf\data\AbstractDatabaseObjectAction {
/**
* Removes old messages.
*
* @return integer Number of deleted messages.
* @return integer Number of deleted messages.
*/
public function prune() {
if (CHAT_LOG_ARCHIVETIME == -1) return 0;
@ -36,8 +36,9 @@ public function prune() {
time < ?";
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
$stmt->execute(array(TIME_NOW - CHAT_LOG_ARCHIVETIME));
$objectIDs = array();
while ($objectIDs[] = $stmt->fetchColumn());
while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID;
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
}

View File

@ -46,14 +46,14 @@ public function canEnter(\wcf\data\user\User $user = null) {
$canEnter = $ph->getPermission($this, 'user.canEnter');
// room suspension
if ($canEnter && isset($suspensions[$this->roomID][Suspension::TYPE_BAN])) {
if ($suspensions[$this->roomID][Suspension::TYPE_BAN]->time > TIME_NOW) {
if ($suspensions[$this->roomID][Suspension::TYPE_BAN]->isValid()) {
$canEnter = false;
}
}
// global suspension
if ($canEnter && isset($suspensions[null][Suspension::TYPE_BAN])) {
if ($suspensions[null][Suspension::TYPE_BAN]->time > TIME_NOW) {
if ($suspensions[null][Suspension::TYPE_BAN]->isValid()) {
$canEnter = false;
}
}
@ -77,14 +77,14 @@ public function canWrite(\wcf\data\user\User $user = null) {
$canWrite = $ph->getPermission($this, 'user.canWrite');
// room suspension
if ($canWrite && isset($suspensions[$this->roomID][Suspension::TYPE_MUTE])) {
if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]->time > TIME_NOW) {
if ($suspensions[$this->roomID][Suspension::TYPE_MUTE]->isValid()) {
$canWrite = false;
}
}
// global suspension
if ($canWrite && isset($suspensions[null][Suspension::TYPE_MUTE])) {
if ($suspensions[null][Suspension::TYPE_MUTE]->time > TIME_NOW) {
if ($suspensions[null][Suspension::TYPE_MUTE]->isValid()) {
$canWrite = false;
}
}

View File

@ -79,7 +79,7 @@ public function prune() {
$stmt->execute(array(0, 'roomID'));
$objectIDs = array();
while ($objectIDs[] = $stmt->fetchColumn());
while ($objectID = $stmt->fetchColumn()) $objectIDs[] = $objectID;
return call_user_func(array($this->className, 'deleteAll'), $objectIDs);
}

View File

@ -25,6 +25,15 @@ class Suspension extends \chat\data\CHATDatabaseObject {
const TYPE_MUTE = 1;
const TYPE_BAN = 2;
/**
* Returns whether the suspension still is valid.
*
* @return boolean
*/
public function isValid() {
return $this->expires > TIME_NOW;
}
/**
* Returns all the suspensions for the specified user (current user if no user was specified).
*
@ -42,7 +51,7 @@ public static function getSuspensionsForUser(\wcf\data\user\User $user = null) {
chat".WCF_N."_suspension
WHERE
userID = ?
AND time > ?";
AND expires > ?";
$stmt = WCF::getDB()->prepareStatement($sql);
$stmt->execute(array($user->userID, TIME_NOW));

View File

@ -27,7 +27,7 @@ public function prune() {
FROM
".call_user_func(array($this->className, 'getDatabaseTableName'))."
WHERE
time < ?";
expires < ?";
$stmt = \wcf\system\WCF::getDB()->prepareStatement($sql);
$stmt->execute(array(TIME_NOW));
$objectIDs = array();

View File

@ -17,12 +17,12 @@
class BanCommand extends MuteCommand {
public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_BAN)) {
if ($suspension->time > TIME_NOW + $this->time) {
if ($suspension->expires > $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$editor = new suspension\SuspensionEditor($suspension);
$editor->delete();
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action->executeAction();
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
@ -30,7 +30,7 @@ public function executeAction() {
'userID' => $this->user->userID,
'roomID' => ChatUtil::readUserData('roomID'),
'type' => suspension\Suspension::TYPE_BAN,
'time' => TIME_NOW + $this->time
'expires' => $this->expires
)
));
$this->suspensionAction->executeAction();

View File

@ -19,12 +19,12 @@ public function executeAction() {
$room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_BAN)) {
if ($suspension->time > TIME_NOW + $this->time) {
if ($suspension->expires > $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$editor = new suspension\SuspensionEditor($suspension);
$editor->delete();
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action->executeAction();
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
@ -32,7 +32,7 @@ public function executeAction() {
'userID' => $this->user->userID,
'roomID' => null,
'type' => suspension\Suspension::TYPE_BAN,
'time' => TIME_NOW + $this->time
'expires' => $this->expires
)
));
$this->suspensionAction->executeAction();

View File

@ -19,12 +19,12 @@ public function executeAction() {
$room = new \chat\data\room\Room(null, array('roomID' => null));
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $room, suspension\Suspension::TYPE_MUTE)) {
if ($suspension->time > TIME_NOW + $this->time) {
if ($suspension->expires > $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
$editor = new suspension\SuspensionEditor($suspension);
$editor->delete();
$action = new suspension\SuspensionAction(array($suspension), 'delete');
$action->executeAction();
}
$this->suspensionAction = new suspension\SuspensionAction(array(), 'create', array(
@ -32,7 +32,7 @@ public function executeAction() {
'userID' => $this->user->userID,
'roomID' => null,
'type' => suspension\Suspension::TYPE_MUTE,
'time' => TIME_NOW + $this->time
'expires' => $this->expires
)
));
$this->suspensionAction->executeAction();

View File

@ -49,7 +49,9 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
$suspensions = \chat\data\suspension\Suspension::getSuspensionsForUser($this->user);
foreach ($suspensions as $roomSuspensions) {
foreach ($roomSuspensions as $typeSuspension) {
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->time);
if (!$typeSuspension->isValid()) continue;
$dateTime = DateUtil::getDateTimeByTimestamp($typeSuspension->expires);
$this->lines[$typeSuspension->type.'-'.$typeSuspension->roomID] = str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.date.dateTimeFormat')));
}
}

View File

@ -16,7 +16,7 @@
*/
class MuteCommand extends \chat\system\command\AbstractRestrictedCommand {
public $user = null;
public $time = 0;
public $expires = 0;
public $suspensionAction = null;
public $link = '';
public $room = null;
@ -27,8 +27,8 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
try {
list($username, $modifier) = explode(',', $commandHandler->getParameters(), 2);
$modifier = ChatUtil::timeModifier(\wcf\util\StringUtil::trim($modifier));
$this->time = strtotime($modifier, TIME_NOW);
$this->time = min(max(-0x80000000, $this->time), 0x7FFFFFFF);
$expires = strtotime($modifier, TIME_NOW);
$this->expires = min(max(-0x80000000, $expires), 0x7FFFFFFF);
}
catch (\wcf\system\exception\SystemException $e) {
throw new \chat\system\command\NotFoundException();
@ -49,7 +49,7 @@ public function __construct(\chat\system\command\CommandHandler $commandHandler)
public function executeAction() {
if ($suspension = suspension\Suspension::getSuspensionByUserRoomAndType($this->user, $this->room, suspension\Suspension::TYPE_MUTE)) {
if ($suspension->time > $this->time) {
if ($suspension->expires > $this->expires) {
throw new \wcf\system\exception\UserInputException('text', WCF::getLanguage()->get('wcf.chat.suspension.exists'));
}
@ -62,7 +62,7 @@ public function executeAction() {
'userID' => $this->user->userID,
'roomID' => ChatUtil::readUserData('roomID'),
'type' => suspension\Suspension::TYPE_MUTE,
'time' => $this->time
'expires' => $this->expires
)
));
$this->suspensionAction->executeAction();
@ -92,7 +92,7 @@ public function getType() {
public function getMessage() {
return serialize(array(
'link' => $this->link,
'until' => $this->time,
'expires' => $this->expires,
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this)))
));
}

View File

@ -15,7 +15,6 @@
*/
class UnmuteCommand extends \chat\system\command\AbstractRestrictedCommand {
public $user = null;
public $time = 0;
public $suspensionAction = null;
public $link = '';
public $room = null;
@ -71,7 +70,6 @@ public function getType() {
public function getMessage() {
return serialize(array(
'link' => $this->link,
'until' => TIME_NOW + $this->time,
'type' => str_replace(array('chat\system\command\commands\\', 'command'), '', strtolower(get_class($this)))
));
}

View File

@ -22,22 +22,22 @@ CREATE TABLE chat1_message (
color1 INT(10) NOT NULL DEFAULT 0,
color2 INT(10) NOT NULL DEFAULT 0,
KEY roomID (roomID),
KEY sender (sender),
KEY receiver (receiver)
KEY (roomID),
KEY (sender),
KEY (receiver)
);
DROP TABLE IF EXISTS chat1_room;
CREATE TABLE chat1_room (
roomID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
topic VARCHAR(255) NOT NULL,
topic VARCHAR(255) NOT NULL DEFAULT '',
showOrder INT(10) NOT NULL DEFAULT 0,
permanent TINYINT(1) NOT NULL DEFAULT 1,
owner INT(10) DEFAULT NULL,
KEY showOrder (showOrder),
KEY owner (owner)
KEY (showOrder),
KEY (owner)
);
DROP TABLE IF EXISTS chat1_suspension;
@ -46,12 +46,12 @@ CREATE TABLE chat1_suspension (
userID INT(10) NOT NULL,
roomID INT(10) DEFAULT NULL,
type TINYINT(3) NOT NULL,
time INT(10) NOT NULL,
expires INT(10) NOT NULL,
UNIQUE KEY suspension (userID, roomID, type),
KEY roomID (roomID),
KEY type (type),
KEY time (time)
KEY (roomID),
KEY (type),
KEY (time)
);
ALTER TABLE chat1_message ADD FOREIGN KEY (receiver) REFERENCES wcf1_user (userID) ON DELETE CASCADE;

View File

@ -107,10 +107,10 @@
<item name="chat.message.4"><![CDATA[ist jetzt wieder da.]]></item>
<!-- 5 = TYPE_MODERATE -->
<item name="chat.message.5.restore"><![CDATA[hat {@$link} zurückgesetzt.]]></item>
<item name="chat.message.5.mute"><![CDATA[hat {@$link} bis {@$until|plainTime} geknebelt.]]></item>
<item name="chat.message.5.ban"><![CDATA[hat {@$link} bis {@$until|plainTime} gebannt.]]></item>
<item name="chat.message.5.gmute"><![CDATA[hat {@$link} bis {@$until|plainTime} global geknebelt.]]></item>
<item name="chat.message.5.gban"><![CDATA[hat {@$link} bis {@$until|plainTime} global gebannt.]]></item>
<item name="chat.message.5.mute"><![CDATA[hat {@$link} bis {@$expires|plainTime} geknebelt.]]></item>
<item name="chat.message.5.ban"><![CDATA[hat {@$link} bis {@$expires|plainTime} gebannt.]]></item>
<item name="chat.message.5.gmute"><![CDATA[hat {@$link} bis {@$expires|plainTime} global geknebelt.]]></item>
<item name="chat.message.5.gban"><![CDATA[hat {@$link} bis {@$expires|plainTime} global gebannt.]]></item>
<item name="chat.message.5.unmute"><![CDATA[hat {@$link} entknebelt.]]></item>
<item name="chat.message.color.success"><![CDATA[Die Farbe wurde erfolgreich geändert.]]></item>

View File

@ -15,7 +15,7 @@
</authorinformation>
<requiredpackages>
<requiredpackage minversion="2.0.0 Alpha 1">com.woltlab.wcf</requiredpackage>
<requiredpackage minversion="2.0.0 Beta 1">com.woltlab.wcf</requiredpackage>
<requiredpackage file="requirements/be.bastelstu.max.wcf.jCounter.tar">be.bastelstu.max.wcf.jCounter</requiredpackage>
<requiredpackage file="requirements/be.bastelstu.wcf.nodePush.tar">be.bastelstu.wcf.nodePush</requiredpackage>
</requiredpackages>