3 namespace wcf\data\conversation\message
;
5 use wcf\data\attachment\GroupedAttachmentList
;
6 use wcf\data\conversation\Conversation
;
7 use wcf\data\
object\type\ObjectTypeCache
;
8 use wcf\system\cache\runtime\UserProfileRuntimeCache
;
9 use wcf\system\message\embedded\
object\MessageEmbeddedObjectManager
;
12 * Represents a list of viewable conversation messages.
15 * @copyright 2001-2019 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Data\Conversation\Message
19 * @method ViewableConversationMessage current()
20 * @method ViewableConversationMessage[] getObjects()
21 * @method ViewableConversationMessage|null getSingleObject()
22 * @method ViewableConversationMessage|null seach($objectID)
23 * @property ViewableConversationMessage[] $objects
25 class ViewableConversationMessageList
extends ConversationMessageList
30 public $sqlOrderBy = 'conversation_message.time';
35 public $decoratorClassName = ViewableConversationMessage
::class;
38 * attachment object ids
41 public $attachmentObjectIDs = [];
44 * ids of the messages with embedded objects
47 public $embeddedObjectMessageIDs = [];
51 * @var GroupedAttachmentList
53 protected $attachmentList;
59 protected $maxPostTime = 0;
62 * enables/disables the loading of attachments
65 protected $attachmentLoading = true;
68 * enables/disables the loading of embedded objects
71 protected $embeddedObjectLoading = true;
77 protected $conversation;
82 public function readObjects()
84 if ($this->objectIDs
=== null) {
85 $this->readObjectIDs();
88 parent
::readObjects();
91 foreach ($this->objects
as $message) {
92 if ($message->time
> $this->maxPostTime
) {
93 $this->maxPostTime
= $message->time
;
95 if ($this->conversation
!== null) {
96 $message->setConversation($this->conversation
);
99 if ($message->attachments
) {
100 $this->attachmentObjectIDs
[] = $message->messageID
;
103 if ($message->hasEmbeddedObjects
) {
104 $this->embeddedObjectMessageIDs
[] = $message->messageID
;
106 if ($message->userID
) {
107 $userIDs[] = $message->userID
;
111 if (!empty($userIDs)) {
112 UserProfileRuntimeCache
::getInstance()->cacheObjectIDs($userIDs);
115 if ($this->embeddedObjectLoading
) {
116 $this->readEmbeddedObjects();
118 if ($this->attachmentLoading
) {
119 $this->readAttachments();
124 * Reads the embedded objects of the messages in the list.
126 public function readEmbeddedObjects()
128 if (!empty($this->embeddedObjectMessageIDs
)) {
129 // add message objects to attachment object cache to save SQL queries
130 ObjectTypeCache
::getInstance()
131 ->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'com.woltlab.wcf.conversation.message')
133 ->setCachedObjects($this->objects
);
135 // load embedded objects
136 MessageEmbeddedObjectManager
::getInstance()
137 ->loadObjects('com.woltlab.wcf.conversation.message', $this->embeddedObjectMessageIDs
);
142 * Reads the list of attachments.
144 public function readAttachments()
146 if (!empty($this->attachmentObjectIDs
)) {
147 $this->attachmentList
= new GroupedAttachmentList('com.woltlab.wcf.conversation.message');
148 $this->attachmentList
->getConditionBuilder()
149 ->add('attachment.objectID IN (?)', [$this->attachmentObjectIDs
]);
150 $this->attachmentList
->readObjects();
155 * Returns the max post time.
159 public function getMaxPostTime()
161 return $this->maxPostTime
;
165 * Returns the list of attachments.
167 * @return GroupedAttachmentList
169 public function getAttachmentList()
171 return $this->attachmentList
;
175 * Enables/disables the loading of attachments.
177 * @param bool $enable
179 public function enableAttachmentLoading($enable = true)
181 $this->attachmentLoading
= $enable;
185 * Enables/disables the loading of embedded objects.
187 * @param bool $enable
189 public function enableEmbeddedObjectLoading($enable = true)
191 $this->embeddedObjectLoading
= $enable;
195 * Sets active conversation.
197 * @param Conversation $conversation
199 public function setConversation(Conversation
$conversation)
201 $this->conversation
= $conversation;