XF 2.2 Private Thread Showing as Last Reply in Forum?

Gossamer

Active member
I am working on an add-on that allows my members to create threads that are flagged as Private. They can only be viewed by other members who have opted in to view these Private threads.

A member who is not supposed to view these threads do not see them in the activity feed or the thread list, which is good. I did this by extending the Thread Finder and modifying the applyVisibilityChecksInForum function.

However, these threads still appear as the "Last Reply" when viewing the Forum List. Could someone point me to what file I should be looking at to make sure the forum's "Last Reply" takes this visibility into account? I've been searching, but so far I have come up empty handed.

Thanks in advance!
 
Solution
Thank you! I couldn't really figure out how to make use of the Last reply cache. But I managed to achieve what I was looking for by modifying the Forum Entity's getNodeListExtras function.

PHP:
    public function getNodeListExtras()
    {
        $output = parent::getNodeListExtras();
        
        if ($this->last_post_date && $this->LastThread->goss_nsfw && !\XF::visitor()->can_create_view_nsfw)
        {       
            $finder = \XF::finder('XF:Thread');
            $LastThread = $finder->where('goss_nsfw', '<>', 1)->where('discussion_state', 'visible')->where('discussion_type', '<>', 'redirect')->where('node_id', $this->node_id)->order('last_post_date', 'DESC')->fetchOne();
            
            $output['is_unread'] =...

Gossamer

Active member
Thank you! I couldn't really figure out how to make use of the Last reply cache. But I managed to achieve what I was looking for by modifying the Forum Entity's getNodeListExtras function.

PHP:
    public function getNodeListExtras()
    {
        $output = parent::getNodeListExtras();
        
        if ($this->last_post_date && $this->LastThread->goss_nsfw && !\XF::visitor()->can_create_view_nsfw)
        {       
            $finder = \XF::finder('XF:Thread');
            $LastThread = $finder->where('goss_nsfw', '<>', 1)->where('discussion_state', 'visible')->where('discussion_type', '<>', 'redirect')->where('node_id', $this->node_id)->order('last_post_date', 'DESC')->fetchOne();
            
            $output['is_unread'] = $LastThread->isUnread();
            $output['last_post_id'] = $LastThread['last_post_id'];
            $output['last_post_date'] = $LastThread['last_post_date'];
            $output['last_post_user_id'] = $LastThread['last_post_user_id'];
            $output['last_post_username'] = $LastThread['last_post_username'];
            $output['last_thread_id'] = $LastThread['thread_id'];
            $output['last_thread_title'] = $this->app()->stringFormatter()->censorText($LastThread['title']);
            $output['last_thread_prefix_id'] = $LastThread['prefix_id'];
            $output['LastPostUser'] = $LastThread->LastPoster;
            $output['LastThread'] = $LastThread;
        }
        
        return $output;
    }
 
Solution

Lukas W.

Well-known member
Be aware that that's an N+1 query behavior, where you trigger one database query per node with that option enabled on the node list. If you only have 2-3 nodes, that's probably not relevant, if you're going into the dozens, you'll want to move that to a different space where you can run a single query and retrieve results for all nodes at once.
 

Gossamer

Active member
Aaah, thank you! It's only a handful of nodes and only triggers when the LastThread is one that was flagged as nsfw, so I don't expect it to pop up too often. But I'll look at that and see if I can figure out how to improve that.
 
Top