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

Implement a “pseudo global” room

The „global“ room can be activated on a user group basis.
This allows for bots processing messages from all rooms and responding to them.
This commit is contained in:
Maximilian Mader 2014-08-03 00:41:28 +02:00
parent d22c209e8d
commit c2fe53fdb0
7 changed files with 65 additions and 13 deletions

View File

@ -54,6 +54,11 @@ public function validateSend() {
$this->parameters['userData']['away'] = WCF::getUser()->chatAway;
// read and validate room
$this->readInteger('roomID', true);
if (\wcf\system\WCF::getSession()->getPermission('admin.chat.isInAllRooms') && $this->parameters['roomID'] !== 0) {
$this->parameters['userData']['roomID'] = $this->parameters['roomID'];
}
$this->parameters['room'] = room\RoomCache::getInstance()->getRoom($this->parameters['userData']['roomID']);
if ($this->parameters['room'] === null) throw new \wcf\system\exception\IllegalLinkException();
if (!$this->parameters['room']->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();

View File

@ -30,7 +30,10 @@ public static function getNewestMessages(\chat\data\room\Room $room, $number = C
$messageList->sqlOrderBy = "message.messageID DESC";
$messageList->sqlLimit = $number;
$messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
if ($room->roomID !== \chat\data\room\Room::GLOBAL_ROOM) {
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
}
$messageList->readObjects();
return array_reverse($messageList->getObjects());
@ -38,7 +41,7 @@ public static function getNewestMessages(\chat\data\room\Room $room, $number = C
/**
* Reads the messages since the given message-id for the given room.
*
*
* @param \chat\data\room\Room $room
* @param integer $since
* @return array<\chat\data\message\Message>
@ -47,15 +50,26 @@ public static function getMessagesSince(\chat\data\room\Room $room, $since) {
$messageList = new static();
$messageList->sqlOrderBy = "message.messageID ASC";
$messageList->getConditionBuilder()->add('message.messageID > ?', array($since));
$messageList->getConditionBuilder()->add('
((
message.receiver IS NULL
AND message.roomID = ?
)
OR message.receiver = ?
OR message.sender = ?)',
array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
);
if ($room->roomID !== \chat\data\room\Room::GLOBAL_ROOM) {
$messageList->getConditionBuilder()->add('
((
message.receiver IS NULL
AND message.roomID = ?
)
OR message.receiver = ?
OR message.sender = ?)',
array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
);
}
else {
$messageList->getConditionBuilder()->add('
(message.receiver IS NULL
OR message.receiver = ?
OR message.sender = ?)',
array(\wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
);
}
$messageList->readObjects();
return $messageList->getObjects();
@ -73,7 +87,11 @@ public static function getMessagesBetween(\chat\data\room\Room $room, $start, $e
$messageList = new static();
$messageList->sqlOrderBy = "message.messageID ASC";
$messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
if ($room->roomID !== \chat\data\room\Room::GLOBAL_ROOM) {
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
}
$messageList->getConditionBuilder()->add('message.time BETWEEN ? AND ?', array($start, $end));
$messageList->readObjects();

View File

@ -30,6 +30,11 @@ class Room extends \chat\data\CHATDatabaseObject implements \wcf\system\request\
*/
protected static $users = null;
/**
* room id of the “global” pseudo chat room
*/
const GLOBAL_ROOM = -1;
/**
* @see \wcf\data\chat\room\ChatRoom::getTitle();
*/
@ -194,6 +199,13 @@ public function getUsers() {
self::$users[$user->chatRoomID][$userID] = $user;
}
}
if ($this->roomID === self::GLOBAL_ROOM) {
return array_reduce(self::$users, function($a, $b) {
return $a + $b;
}, array());
}
if (!isset(self::$users[$this->roomID])) self::$users[$this->roomID] = array();
return self::$users[$this->roomID];

View File

@ -94,7 +94,13 @@ public function readMessages() {
* Initializes the room databaseobject.
*/
public function readRoom() {
$this->room = \chat\data\room\RoomCache::getInstance()->getRoom(WCF::getUser()->chatRoomID);
if (\wcf\system\WCF::getSession()->getPermission('admin.chat.isInAllRooms')) {
$this->room = new \chat\data\room\Room(null, array('roomID' => \chat\data\room\Room::GLOBAL_ROOM));
}
else {
$this->room = \chat\data\room\RoomCache::getInstance()->getRoom(WCF::getUser()->chatRoomID);
}
if (!$this->room) throw new IllegalLinkException();
if (!$this->room->canEnter()) throw new \wcf\system\exception\PermissionDeniedException();
}

View File

@ -85,6 +85,8 @@
<item name="wcf.acp.group.option.admin.chat.canReadLog"><![CDATA[Kann Protokoll einsehen]]></item>
<item name="wcf.acp.group.option.admin.chat.canManageSuspensions"><![CDATA[Kann Sanktionen verwalten]]></item>
<item name="wcf.acp.group.option.admin.chat.canManageSuspensions.description"><![CDATA[Impliziert „Kann bannen“, „Kann knebeln“, „Kann global bannen“, „Kann global knebeln“ und gegenbenenfalls weitere Rechte.]]></item>
<item name="wcf.acp.group.option.admin.chat.isInAllRooms"><![CDATA[Ist in allen Räumen]]></item>
<item name="wcf.acp.group.option.admin.chat.isInAllRooms.description"><![CDATA[Eine Aktivierung dieser Option bewirkt, dass Nachrichten aus allen Räumen an den Benutzer gesendet werden.<br /><strong>Achtung:</strong> Die Aktivierung dieser Option führt dazu, dass der Chat für Ihre Mitglieder unbenutzbar wird. Ziehen Sie das Aktivieren dieser Option nur für computergestützte Anwendungen (Bots) in Betracht!<!-- HC SVNT DRACONES -->]]></item>
</category>
<category name="wcf.acp.option">

View File

@ -85,6 +85,8 @@
<item name="wcf.acp.group.option.admin.chat.canReadLog"><![CDATA[Can see protocol]]></item>
<item name="wcf.acp.group.option.admin.chat.canManageSuspensions"><![CDATA[Can manage suspensions]]></item>
<item name="wcf.acp.group.option.admin.chat.canManageSuspensions.description"><![CDATA[Implies “Can ban”, “Can mute”, “Can ban globally”, “Can mute globally” und possibly other permissions.]]></item>
<item name="wcf.acp.group.option.admin.chat.isInAllRooms"><![CDATA[Is in all rooms]]></item>
<item name="wcf.acp.group.option.admin.chat.isInAllRooms.description"><![CDATA[Enabling this option will send messages from all rooms to the client.<br /><strong>Warning:</strong> Enabling this option might render the chat useless for your members! Only activate it for bots accessing the chat.<!-- HC SVNT DRACONES -->]]></item>
</category>
<category name="wcf.acp.option">

View File

@ -157,6 +157,13 @@ pdf]]></defaultvalue>
<admindefaultvalue>1</admindefaultvalue>
<usersonly>1</usersonly>
</option>
<option name="admin.chat.isInAllRooms">
<categoryname>admin.chat</categoryname>
<optiontype>boolean</optiontype>
<defaultvalue>0</defaultvalue>
<admindefaultvalue>0</admindefaultvalue>
<usersonly>1</usersonly>
</option>
</options>
</import>
</data>