<?php
namespace wcf\system\attachment;
use wcf\data\conversation\message\ConversationMessage;
+use wcf\data\conversation\message\ConversationMessageList;
use wcf\data\conversation\Conversation;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
return false;
}
+
+ /**
+ * @see \wcf\system\attachment\IAttachmentObjectType::cacheObjects()
+ */
+ public function cacheObjects(array $objectIDs) {
+ $messageList = new ConversationMessageList();
+ $messageList->setObjectIDs($objectIDs);
+ $messageList->readObjects();
+ $conversationIDs = array();
+ foreach ($messageList as $message) {
+ $conversationIDs[] = $message->conversationID;
+ }
+ if (!empty($conversationIDs)) {
+ $conversations = Conversation::getUserConversations($conversationIDs, WCF::getUser()->userID);
+ foreach ($messageList as $message) {
+ if (isset($conversations[$message->conversationID])) $message->setConversation($conversations[$message->conversationID]);
+ }
+ }
+ $this->cachedObjects = $messageList->getObjects();
+ }
+
+ /**
+ * @see \wcf\system\attachment\IAttachmentObjectType::setPermissions()
+ */
+ public function setPermissions(array $attachments) {
+ $postIDs = array();
+ foreach ($attachments as $attachment) {
+ // set default permissions
+ $attachment->setPermissions(array(
+ 'canDownload' => false,
+ 'canViewPreview' => false
+ ));
+
+ if ($this->getObject($attachment->objectID) === null) {
+ $messageIDs[] = $attachment->objectID;
+ }
+ }
+
+ if (!empty($messageIDs)) {
+ $this->cacheObjects($messageIDs);
+ }
+
+ foreach ($attachments as $attachment) {
+ if (($message = $this->getObject($attachment->objectID)) !== null) {
+ if (!$message->getConversation()->canRead()) continue;
+
+ $attachment->setPermissions(array(
+ 'canDownload' => true,
+ 'canViewPreview' => true
+ ));
+ }
+ else if ($attachment->tmpHash != '' && $attachment->userID == WCF::getUser()->userID) {
+ $attachment->setPermissions(array(
+ 'canDownload' => true,
+ 'canViewPreview' => true
+ ));
+ }
+ }
+ }
}