Add attachment object types

This commit is contained in:
Tim Düsterhus 2020-10-31 18:07:45 +01:00
parent 7d3f237927
commit 762719179b
Signed by: TimWolla
GPG Key ID: 8FF75566094168AF
3 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,94 @@
<?php
/*
* Copyright (c) 2010-2020 Tim Düsterhus.
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2024-10-31
*
* 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;
use \chat\data\message\Message;
use \chat\data\message\MessageList;
use \chat\data\room\RoomCache;
use \wcf\system\WCF;
/**
* Attachment object type implementation for messages.
*/
class MessageAttachmentObjectType extends \wcf\system\attachment\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 cacheObjects(array $objectIDs) {
$messageList = new MessageList();
$messageList->setObjectIDs($objectIDs);
$messageList->readObjects();
foreach ($messageList->getObjects() as $objectID => $object) {
$this->cachedObjects[$objectID] = $object;
}
}
}

View File

@ -0,0 +1,67 @@
<?php
/*
* Copyright (c) 2010-2020 Tim Düsterhus.
*
* Use of this software is governed by the Business Source License
* included in the LICENSE file.
*
* Change Date: 2024-10-31
*
* 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;
/**
* AttachmentMessageType represents a message with an attached file.
*/
class AttachmentMessageType implements IMessageType, IDeletableMessageType {
use TCanSeeInSameRoom;
/**
* HtmlOutputProcessor to use.
* @var \wcf\system\html\output\HtmlOutputProcessor
*/
protected $processor = null;
public function __construct() {
$this->processor = new \wcf\system\html\output\HtmlOutputProcessor();
}
/**
* @inheritDoc
*/
public function getJavaScriptModuleName() {
return 'Bastelstu.be/Chat/MessageType/Plain';
}
/**
* @inheritDoc
*/
public function canDelete(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) {
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser());
return $user->getPermission('mod.chat.canDelete');
}
/**
* @see \chat\system\message\type\IMessageType::getPayload()
*/
public function getPayload(\chat\data\message\Message $message, \wcf\data\user\UserProfile $user = null) {
if ($user === null) $user = new \wcf\data\user\UserProfile(\wcf\system\WCF::getUser());
$payload = $message->payload;
$parameters = [ 'message' => $message
, 'user' => $user
, 'payload' => $payload
];
\wcf\system\event\EventHandler::getInstance()->fireAction($this, 'getPayload', $parameters);
// TODO
return $parameters['payload'];
}
}

View File

@ -132,6 +132,12 @@
<definitionname>be.bastelstu.chat.messageType</definitionname>
<classname>chat\system\message\type\WhisperMessageType</classname>
</type>
<type>
<name>be.bastelstu.chat.messageType.attachment</name>
<definitionname>be.bastelstu.chat.messageType</definitionname>
<classname>chat\system\message\type\AttachmentMessageType</classname>
</type>
<!-- /message types -->
<!-- suspensions -->
@ -168,5 +174,13 @@
<points>1</points>
</type>
<!-- /activity points -->
<!-- attachments -->
<type>
<name>be.bastelstu.chat.message</name>
<definitionname>com.woltlab.wcf.attachment.objectType</definitionname>
<classname>chat\system\attachment\MessageAttachmentObjectType</classname>
</type>
<!-- attachments -->
</import>
</data>