Load reactions with initialization of the object
authorJoshua Rüsweg <josh@bastelstu.be>
Thu, 3 May 2018 13:21:23 +0000 (15:21 +0200)
committerJoshua Rüsweg <josh@bastelstu.be>
Thu, 3 May 2018 13:21:23 +0000 (15:21 +0200)
See #2508

wcfsetup/install/files/lib/data/like/object/LikeObject.class.php

index f1067e09962694848772c13940c5034fb4be0208..1eef13a34d177a9195b039391859af0565a1a180 100644 (file)
@@ -2,9 +2,11 @@
 declare(strict_types=1);
 namespace wcf\data\like\object;
 use wcf\data\object\type\ObjectTypeCache;
+use wcf\data\reaction\type\ReactionTypeCache;
 use wcf\data\user\User;
 use wcf\data\DatabaseObject;
 use wcf\system\WCF;
+use wcf\util\JSON;
 
 /**
  * Represents a liked object.
@@ -71,7 +73,20 @@ class LikeObject extends DatabaseObject {
                        $cachedReactions = @unserialize($data['cachedReactions']);
                        
                        if (is_array($cachedReactions)) {
-                               $this->reactions = $cachedReactions;
+                               foreach ($cachedReactions as $reactionTypeID => $reactionCount) {
+                                       $reaction = ReactionTypeCache::getInstance()->getReactionTypeByID($reactionTypeID);
+                                       
+                                       // prevent outdated reactions
+                                       if ($reaction !== null) {
+                                               $this->reactions[$reactionTypeID] = [
+                                                       'reactionCount' => $reactionCount,
+                                                       'renderedReactionIcon' => $reaction->renderIcon(),
+                                                       'renderedReactionIconEncoded' => JSON::encode($reaction->renderIcon()),
+                                                       'reactionTitle' => $reaction->getTitle(),
+                                                       'reactionType' => $reaction->type
+                                               ];
+                                       }
+                               }
                        }
                }
        }