Load embedded objects for structured/viewable comment (response) lists
authorMatthias Schmidt <gravatronics@live.com>
Wed, 9 Jun 2021 13:16:18 +0000 (15:16 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 9 Jun 2021 13:16:18 +0000 (15:16 +0200)
wcfsetup/install/files/lib/data/comment/StructuredCommentList.class.php
wcfsetup/install/files/lib/data/comment/ViewableCommentList.class.php
wcfsetup/install/files/lib/data/comment/response/StructuredCommentResponseList.class.php
wcfsetup/install/files/lib/data/comment/response/ViewableCommentResponseList.class.php

index 337ab41d6a37100789f5103ede2aed26b162c47b..07b03304018651fda6bb7473911091d57d7e89e7 100644 (file)
@@ -7,6 +7,7 @@ use wcf\data\comment\response\StructuredCommentResponse;
 use wcf\data\like\object\LikeObject;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\comment\manager\ICommentManager;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\reaction\ReactionHandler;
 
 /**
@@ -110,7 +111,7 @@ class StructuredCommentList extends CommentList
         $canModerate = $this->commentManager->canModerate($this->objectTypeID, $this->objectID);
 
         // fetch response ids
-        $responseIDs = $userIDs = [];
+        $embeddedObjectIDs = $responseIDs = $userIDs = [];
         /** @var StructuredComment $comment */
         foreach ($this->objects as $comment) {
             if (!$this->minCommentTime || $comment->time < $this->minCommentTime) {
@@ -129,6 +130,10 @@ class StructuredCommentList extends CommentList
                 $userIDs[] = $comment->userID;
             }
 
+            if ($comment->hasEmbeddedObjects) {
+                $embeddedObjectIDs[] = $comment->getObjectID();
+            }
+
             $comment->setIsDeletable($this->commentManager->canDeleteComment($comment->getDecoratedObject()));
             $comment->setIsEditable($this->commentManager->canEditComment($comment->getDecoratedObject()));
         }
@@ -139,6 +144,7 @@ class StructuredCommentList extends CommentList
             $responseList->setObjectIDs(\array_keys($responseIDs));
             $responseList->readObjects();
 
+            $embeddedResponseIDs = [];
             foreach ($responseList as $response) {
                 $response = new StructuredCommentResponse($response);
 
@@ -155,6 +161,17 @@ class StructuredCommentList extends CommentList
                 if ($response->userID) {
                     $userIDs[] = $response->userID;
                 }
+
+                if ($response->hasEmbeddedObjects) {
+                    $embeddedResponseIDs[] = $response->getObjectID();
+                }
+            }
+
+            if (!empty($embeddedResponseIDs)) {
+                MessageEmbeddedObjectManager::getInstance()->loadObjects(
+                    'com.woltlab.wcf.comment.response',
+                    $embeddedResponseIDs
+                );
             }
         }
 
@@ -162,6 +179,13 @@ class StructuredCommentList extends CommentList
         if (!empty($userIDs)) {
             UserProfileRuntimeCache::getInstance()->cacheObjectIDs(\array_unique($userIDs));
         }
+
+        if (!empty($embeddedObjectIDs)) {
+            MessageEmbeddedObjectManager::getInstance()->loadObjects(
+                'com.woltlab.wcf.comment',
+                $embeddedObjectIDs
+            );
+        }
     }
 
     /**
index d5ce1f582fa88971edd40940e910c44336aa1f17..c4e28e8dc743584ba0d6d59c8d238f1d466296ed 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\data\comment;
 
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 
 /**
  * Represents a list of decorated comment objects.
@@ -33,16 +34,27 @@ class ViewableCommentList extends CommentList
         parent::readObjects();
 
         if (!empty($this->objects)) {
-            $userIDs = [];
+            $embeddedObjectIDs = $userIDs = [];
             foreach ($this->objects as $comment) {
                 if ($comment->userID) {
                     $userIDs[] = $comment->userID;
                 }
+
+                if ($comment->hasEmbeddedObjects) {
+                    $embeddedObjectIDs[] = $comment->getObjectID();
+                }
             }
 
             if (!empty($userIDs)) {
                 UserProfileRuntimeCache::getInstance()->cacheObjectIDs($userIDs);
             }
+
+            if (!empty($embeddedObjectIDs)) {
+                MessageEmbeddedObjectManager::getInstance()->loadObjects(
+                    'com.woltlab.wcf.comment',
+                    $embeddedObjectIDs
+                );
+            }
         }
     }
 }
index 6264d51d006cf9a478c12ce4a22fbf9489893555..2d7f8cc86336862dbf0ce00e00a188adc0bada0c 100644 (file)
@@ -6,6 +6,7 @@ use wcf\data\comment\Comment;
 use wcf\data\like\object\LikeObject;
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\comment\manager\ICommentManager;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\reaction\ReactionHandler;
 
 /**
@@ -77,13 +78,17 @@ class StructuredCommentResponseList extends CommentResponseList
         parent::readObjects();
 
         // get user ids
-        $userIDs = [];
+        $embeddedObjectIDs = $userIDs = [];
         foreach ($this->objects as $response) {
             if (!$this->minResponseTime || $response->time < $this->minResponseTime) {
                 $this->minResponseTime = $response->time;
             }
             $userIDs[] = $response->userID;
 
+            if ($response->hasEmbeddedObjects) {
+                $embeddedObjectIDs[] = $response->getObjectID();
+            }
+
             $response->setIsDeletable($this->commentManager->canDeleteResponse($response->getDecoratedObject()));
             $response->setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject()));
         }
@@ -92,6 +97,13 @@ class StructuredCommentResponseList extends CommentResponseList
         if (!empty($userIDs)) {
             UserProfileRuntimeCache::getInstance()->cacheObjectIDs(\array_unique($userIDs));
         }
+
+        if (!empty($embeddedObjectIDs)) {
+            MessageEmbeddedObjectManager::getInstance()->loadObjects(
+                'com.woltlab.wcf.comment.response',
+                $embeddedObjectIDs
+            );
+        }
     }
 
     /**
index 5c925913003889ffe335254488a09c0f4492f559..a9dba01d1f674ea07cb65fb71666061278131015 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\data\comment\response;
 
 use wcf\system\cache\runtime\UserProfileRuntimeCache;
+use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 
 /**
  * Represents a list of decorated comment response objects.
@@ -33,16 +34,27 @@ class ViewableCommentResponseList extends CommentResponseList
         parent::readObjects();
 
         if (!empty($this->objects)) {
-            $userIDs = [];
+            $embeddedObjectIDs = $userIDs = [];
             foreach ($this->objects as $response) {
                 if ($response->userID) {
                     $userIDs[] = $response->userID;
                 }
+
+                if ($response->hasEmbeddedObjects) {
+                    $embeddedObjectIDs[] = $response->getObjectID();
+                }
             }
 
             if (!empty($userIDs)) {
                 UserProfileRuntimeCache::getInstance()->cacheObjectIDs($userIDs);
             }
+
+            if (!empty($embeddedObjectIDs)) {
+                MessageEmbeddedObjectManager::getInstance()->loadObjects(
+                    'com.woltlab.wcf.comment.response',
+                    $embeddedObjectIDs
+                );
+            }
         }
     }
 }