Not a bug Likes are rebuilt twice if profile post state is made visible

TickTackk

Well-known member
Affected version
XF 2.0.x
In file: src\XF\Entity\ProfilePost.php

Find:
PHP:
    protected function profilePostMadeVisible()
    {
        /** @var \XF\Repository\LikedContent $likeRepo */
        $likeRepo = $this->repository('XF:LikedContent');
        $likeRepo->recalculateLikeIsCounted('profile_post_comment', $this->comment_ids);
    }

Replace with:
PHP:
    protected function profilePostMadeVisible()
    {
    }

Because the likes are already rebuilt in XF:Likeable behavior.
 
It recalculates the likes for comments, not posts themselves. It is necessary to trigger manual recalculation for "child" content types when the parent changes visibility, as it is not handled by the behavior.

That said, it would be cool to have a LikeableContainer behavior to handle this automatically in the same vein as IndexableContainer.
 
As stated above, this is indeed just rebuilding the profile post comment likes (or reaction in XF 2.1) which otherwise wouldn't be set to counted. The opposite function happens in the profilePostHidden method.

FWIW, a LikeableContainer isn't a bad idea. I was going to write it off initially but of course we would use it in profile posts, as well as for comments on media items and albums. But, of course, it's not worth adding to version 2.0 at this stage, so you can expect to see it coming in XF 2.1 (from Beta 3) as ReactableContainer:
PHP:
'XF:ReactableContainer' => [
   'childContentType' => 'profile_post_comment',
   'childIds' => function($profilePost) { return $profilePost->comment_ids; },
   'stateField' => 'message_state'
],
 
Back
Top Bottom