2020-10-31 17:07:45 +00:00
|
|
|
<?php
|
2022-03-04 17:10:24 +00:00
|
|
|
|
2020-10-31 17:07:45 +00:00
|
|
|
/*
|
2022-03-04 17:10:24 +00:00
|
|
|
* Copyright (c) 2010-2022 Tim Düsterhus.
|
2020-10-31 17:07:45 +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
|
2020-10-31 17:07:45 +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\attachment;
|
|
|
|
|
2022-03-04 17:10:24 +00:00
|
|
|
use chat\data\message\Message;
|
|
|
|
use chat\data\message\MessageList;
|
|
|
|
use chat\data\room\RoomCache;
|
|
|
|
use wcf\system\attachment\AbstractAttachmentObjectType;
|
|
|
|
use wcf\system\WCF;
|
|
|
|
use wcf\util\ArrayUtil;
|
2020-10-31 17:07:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attachment object type implementation for messages.
|
|
|
|
*/
|
2022-03-04 17:10:24 +00:00
|
|
|
class MessageAttachmentObjectType extends AbstractAttachmentObjectType
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function canDownload($objectID)
|
|
|
|
{
|
|
|
|
if ($objectID) {
|
|
|
|
$message = new Message($objectID);
|
|
|
|
|
|
|
|
if ($message->getMessageType()->objectType !== 'be.bastelstu.chat.messageType.attachment') {
|
|
|
|
throw new \LogicException('Unreachable');
|
|
|
|
}
|
|
|
|
$room = $message->getRoom();
|
|
|
|
|
|
|
|
return $room->canSee();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function canUpload($objectID, $parentObjectID = 0)
|
|
|
|
{
|
|
|
|
if ($objectID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!WCF::getSession()->getPermission('user.chat.canAttach')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$room = null;
|
|
|
|
if ($parentObjectID) {
|
|
|
|
$room = RoomCache::getInstance()->getRoom($parentObjectID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($room !== null) {
|
|
|
|
return $room->canSee();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function canDelete($objectID)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getMaxCount()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getMaxSize()
|
|
|
|
{
|
|
|
|
return WCF::getSession()->getPermission('user.chat.attachment.maxSize');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getAllowedExtensions()
|
|
|
|
{
|
|
|
|
return ArrayUtil::trim(\explode(
|
|
|
|
"\n",
|
|
|
|
WCF::getSession()->getPermission('user.chat.attachment.allowedExtensions')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function cacheObjects(array $objectIDs)
|
|
|
|
{
|
|
|
|
$messageList = new MessageList();
|
|
|
|
$messageList->setObjectIDs($objectIDs);
|
|
|
|
$messageList->readObjects();
|
|
|
|
|
|
|
|
foreach ($messageList->getObjects() as $objectID => $object) {
|
|
|
|
$this->cachedObjects[$objectID] = $object;
|
|
|
|
}
|
|
|
|
}
|
2020-10-31 17:07:45 +00:00
|
|
|
}
|