MyBB Community Forums

Full Version: threads get marked as read by just visiting forum categories
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my forum, i have new users informing us that their account will mark all threads in a category read if they go into that category to view one thread and back out. 

However in my admin account, it does not do this. I have to go to each thread to have them marked as read. I created a new user account, and i replicated this users problem. I am not sure why an admin account would be working correctly and a regular user not? Is there a setting for this?
Thank you for pointing to this issue!

As I already read about a third of the source files to understand the inner workings of MyBB, in the pursuit of finding out how to highlight unread posts in my MyBB threaded view project, I already wondered whether this can work:

In function mark_thread_read (in file inc/functions_indicators.php) the table mybb_threadsread
gets set as indicated in the MyBB documentation.

However at the end of function mark_thread_read the function fetch_unread_count (in same module) gets called.
Looking at this function you can convince yourself that table mybb_posts' field "dateline" does not get queried at all.

Thus the function fetch_unread_count cannot work correctly because of that incomplete and thus incorrect query.

ATM I am busy with other things but later tonight I'll try to find time to fix that function and post a patch.

@metulburr

If I guess correctly the following modification fixes the problem.

In file inc/functions_indicators.php, change the switch block beginning at approx. line #118 as follows:
        switch($db->type)
        {
            case "pgsql":
                                $query = $db->query("
                                        SELECT COUNT(t.tid) AS unread_count
                                        FROM ".TABLE_PREFIX."threads t
                                        LEFT JOIN ".TABLE_PREFIX."threadsread tr ON (tr.tid=t.tid AND tr.uid='{$mybb->user['uid']}')
                                        LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=t.fid AND fr.uid='{$mybb->user['uid']}')
                                        LEFT JOIN ".TABLE_PREFIX."posts pst ON (fr.fid=t.fid AND fr.uid='{$mybb->user['uid']}')
                                        WHERE t.visible=1 AND t.closed NOT LIKE 'moved|%' AND t.fid IN ($fid) AND pst.dateline > tr.dateline AND pst.dateline > $cutoff
                                ");
                                break;
//                 $query = $db->query("
//                     SELECT COUNT(t.tid) AS unread_count
//                     FROM ".TABLE_PREFIX."threads t
//                     LEFT JOIN ".TABLE_PREFIX."threadsread tr ON (tr.tid=t.tid AND tr.uid='{$mybb->user['uid']}')
//                     LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=t.fid AND fr.uid='{$mybb->user['uid']}')
//                     WHERE t.visible=1 AND t.closed NOT LIKE 'moved|%' AND t.fid IN ($fid) AND t.lastpost > COALESCE(tr.dateline,$cutoff) AND t.lastpost > COALESCE(fr.dateline,$cutoff) AND t.lastpost>$cutoff{$onlyview2}
//                 ");
//                 break;
            default:
//                                 $query = $db->query("
//                                         SELECT COUNT(t.tid) AS unread_count
//                                         FROM ".TABLE_PREFIX."threads t
//                                         LEFT JOIN ".TABLE_PREFIX."threadsread tr ON (tr.tid=t.tid AND tr.uid='{$mybb->user['uid']}')
//                                         LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=t.fid AND fr.uid='{$mybb->user['uid']}')
//                                         WHERE t.visible=1 AND t.closed NOT LIKE 'moved|%' AND t.fid IN ($fid) AND t.lastpost > IFNULL(tr.dateline,$cutoff) AND t.lastpost > IFNULL(fr.dateline,$cutoff) AND t.lastpost>$cutoff{$onlyview2}
//                                 ");
                                $query = $db->query("
                                        SELECT COUNT(t.tid) AS unread_count
                                        FROM ".TABLE_PREFIX."threads t
                                        LEFT JOIN ".TABLE_PREFIX."threadsread tr ON (tr.tid=t.tid AND tr.uid='{$mybb->user['uid']}')
                                        LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=t.fid AND fr.uid='{$mybb->user['uid']}')
                                        LEFT JOIN ".TABLE_PREFIX."posts pst ON (fr.fid=t.fid AND fr.uid='{$mybb->user['uid']}')
                                        WHERE t.visible=1 AND t.closed NOT LIKE 'moved|%' AND t.fid IN ($fid) AND pst.dateline > tr.dateline AND pst.dateline > $cutoff
                                ");
        }

        return $db->fetch_field($query, "unread_count");


The original code is commented out in the above code, just to facilitate comparing the original and the modified/corrected queries.

I did only test briefly, and it looks to me as if it now works as it should.

Could you please be so kind and check out whether my modification fixes the problem for you too?
This appears to have fixed the problem. Thanks!!!!!