Show all likes addon - is it possible?

MapleOne

Well-known member
Screenshot - 2022-11-22T094106.354.webp

So basically an addon that would expand that to a preset number or a show all instead of and 6 others
 
I think Andy might have that already? Could be wrong though.

No, I have a lot of Andy's tweaks and addons and I did not see anything for that.
I find it an unnecessary click that I am always having to make when it could easily be displayed.
 
Thank you because the more I hunt, the more I see other members wanting this

 
This is currently not possible without overriding the logic and potential conflicts

- Content reaction caching is hard-coded:

PHP:
public function rebuildContentReactionCache($contentType, $contentId, $isLike = false, $throw = true)
    {
    ...
        $counts = $this->db()->fetchPairs("
            SELECT reacted.reaction_id, COUNT(*) AS counts
            FROM xf_reaction_content AS reacted
            INNER JOIN xf_reaction AS reaction ON (reacted.reaction_id = reaction.reaction_id)
            WHERE content_type = ? AND content_id = ? AND reaction.active = 1
            GROUP BY reaction_id
            ORDER BY counts DESC
        ", [$contentType, $contentId]);

        if ($counts)
        {
            $latest = $this->db()->fetchAll("
                SELECT user.user_id, user.username, reacted.reaction_id
                FROM xf_reaction_content AS reacted
                INNER JOIN xf_user AS user ON (reacted.reaction_user_id = user.user_id)
                INNER JOIN xf_reaction AS reaction ON (reacted.reaction_id = reaction.reaction_id)
                WHERE reacted.content_type = ? AND reacted.content_id = ? AND reaction.active = 1
                ORDER BY reacted.reaction_date DESC
                LIMIT 5
            ", [$contentType, $contentId]);
        }
        else
        {
            $latest = [];
        }
}
  • As we will have to rebuild caches for all forum content - this can take a LOT of time and this might be unexpected for some addons
  • The templater method to display reactions is also not friendly to extensions and modifications
 
Just wondering if someone has a solution to this yet.

There was a larger board that used to have 2-3 rows of likes showing and they were using Xenforo at the time.
 
I will say, this is hardly unique to Xenforo. Circle does the same. In fact, for "comments" (what we know as "replies"), it only shows number of Likes. You have to click to see any names. For "posts" (what we know as the "original post" or "thread starter") it displays similar to Xenforo default, so 2 or 3 and then the number of others.

I think you'd need to keep some kind of limit still even if you increase it. Do you really need a post with 50 or 60 likes (possible on a large site, I have certainly seen it) showing every single one by default? But making that limit a property that can be set by the admin would be nice.

Has this ever been made a suggestion for base, by the way? I'd happily vote it up.
 
You can simply edit /src/XF/Entity/Thread.php and add a function like the following one I created, which will return a list of usernames who reacted to the first post of the thread:


Code:
public function countReactList()
    {

               $firstPost = $this->db()->fetchRow("
                    SELECT post_id, thread_id
                    FROM xf_post
                    WHERE thread_id = ?
                    LIMIT 1
                ", $this->thread_id);

                $this->first_post_id = $firstPost['post_id'];

                $reactions = \XF::db()->fetchAll('SELECT user.username as username
                        FROM xf_reaction_content AS reacted
                        INNER JOIN xf_user AS user ON (reacted.reaction_user_id = user.user_id)
                        INNER JOIN xf_reaction AS reaction ON (reacted.reaction_id = reaction.reaction_id)
                        WHERE reacted.content_type = ? AND reacted.content_id = ? AND reaction.active = 1
                        ORDER BY reacted.reaction_date DESC', ['post', $this->first_post_id]);

                       $list = array();

                       foreach($reactions as $like){
                              $list[] = $like['username'];
                       }
              
                       $list = implode(', ', $list);
              
                       return $list;
}

And then, in thread_view you can add {{ $thread.countReactList() }} wherever you'd like to display this list, eventually restricting it to certain user groups etc..

I hope it helped.

Please note this is tested on XF2.1.x , I can't guarantee for newer versions, but the concept is quite simple to understand. It's like hacking the core functions of Xenforo, there are definitely ways to turn this into an Add-On, but this is the simplest way.
 
Back
Top Bottom