Fixed New reply notifications can be missing as a result of merging threads/posts

Steffen

Well-known member
Affected version
2.1.2
Consider two threads A and B with the last post in thread B being more recent than the last post in thread A. Consider furthermore that a user has completely read thread A but not thread B (or at least not its most recent post). Now, a moderator merges thread B into thread A (or merges the last post of thread B into thread A). Now assume that someone else replies to thread A. The problem is that our user won't be notified of such replies in thread A (because it already contains at least one unread post, namely the last post of the former thread B).

Could XenForo update the xf_thread_read table when merging posts/threads?
 
I'm just wondering if we could do something along the lines of
SQL:
UPDATE xf_thread_read AS dst
LEFT JOIN xf_thread_read AS src ON (dst.user_id = src.user_id AND src.thread_id = ?)
SET dst.thread_read_date = LEAST(dst.thread_read_date, src.thread_read_date)
WHERE dst.thread_id = ?;
Passing in the IDs of the source and destination threads...
 
... of course that only handles one thread being merged into another - I forgot that you can merge multiple!
 
Might have a reasonable solution - to be called after updateUserCounters() in the thread merger:
PHP:
    protected function updateThreadReadData()
    {
        $sourceThreadIds = $this->db()->quote(array_keys($this->sourceThreads));

        $this->db()->query("
            UPDATE xf_thread_read AS tr_dest,
            (
                SELECT MIN(thread_read_date) AS min_thread_read_date, user_id
                FROM xf_thread_read
                WHERE thread_id IN({$sourceThreadIds})
                GROUP BY user_id
            ) AS tr_src
            SET tr_dest.thread_read_date = tr_src.min_thread_read_date
            WHERE tr_dest.user_id = tr_src.user_id
            AND tr_dest.thread_id = ?
        ", $this->target->thread_id);
    }
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.5).

Change log:
Update the xf_thread_read table after a thread merge to reflect the earliest read date for each source thread for each user, so that unread posts from source threads are not marked as read when they are merged into a destination thread whose original content has itself already been read
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
@Kier shouldn't there be a check for tr_dest.thread_read_date > tr_src.min_thread_read_date in the where statement?, that way if the destination thread has an older read date it will not cause notifications to unexpectedly fail in the resulting thread
 
So am I right in thinking if two threads are merged, whichever way round (old > new or new >old) all members watching either will not lose existing notifications, whether based on specifically watching either thread or based on participation in either (if that is what they have in their prefs).

Sorry if this is obvious from the above fix
 
Top Bottom