Tims-Chat/files/lib/system/message/type/TCanSeeInSameRoom.class.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.2 KiB
PHP
Raw Normal View History

2018-08-16 22:30:59 +00:00
<?php
2022-03-04 17:10:24 +00:00
2018-08-16 22:30:59 +00:00
/*
2022-03-04 17:10:24 +00:00
* Copyright (c) 2010-2022 Tim Düsterhus.
2018-08-16 22:30:59 +00:00
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
2022-03-04 17:10:24 +00:00
* Change Date: 2026-03-04
2018-08-16 22:30:59 +00:00
*
* On the date above, in accordance with the Business Source
* License, use of this software will be governed by version 2
* or later of the General Public License.
*/
namespace chat\system\message\type;
2022-03-04 17:10:24 +00:00
use chat\data\message\Message;
use chat\data\room\Room;
use wcf\data\user\UserProfile;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
2018-08-16 22:30:59 +00:00
/**
* Adds a default canSee implementation that checks whether the message belongs to the user's active room.
*/
2022-03-04 17:10:24 +00:00
trait TCanSeeInSameRoom
{
/**
* @see \chat\system\message\type\IMessageType::canSee()
*/
public function canSee(Message $message, Room $room, ?UserProfile $user = null)
{
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
$parameters = [
'message' => $message,
'room' => $room,
'user' => $user,
'canSee' => $message->getRoom()->roomID === $room->roomID,
];
EventHandler::getInstance()->fireAction($this, 'canSee', $parameters);
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
return $parameters['canSee'];
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
/**
* @see \chat\system\message\type\IMessageType::canSeeInLog()
*/
public function canSeeInLog(Message $message, Room $room, ?UserProfile $user = null)
{
if ($user === null) {
$user = new UserProfile(WCF::getUser());
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
$parameters = [
'message' => $message,
'room' => $room,
'user' => $user,
'canSee' => $message->getRoom()->roomID === $room->roomID,
];
EventHandler::getInstance()->fireAction($this, 'canSeeInLog', $parameters);
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
return $parameters['canSee'];
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
/**
* @see \chat\system\message\type\IMessageType::supportsFastSelect()
*/
public function supportsFastSelect()
{
$parameters = [
'result' => true,
];
EventHandler::getInstance()->fireAction($this, 'supportsFastSelect', $parameters);
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
return $parameters['result'];
}
2018-08-16 22:30:59 +00:00
}