Changeset 1310 in ExiteCMS for trunk/forum/viewthread.php


Ignore:
Timestamp:
02/27/08 10:29:52 (4 years ago)
Author:
hverton
Message:

added code to track the datestamp of the oldest post read

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/viewthread.php

    r1307 r1310  
    194194        // include the users own posts 
    195195        $result = dbquery(" 
    196             SELECT count(*) as unread, tr.thread_last_read 
     196            SELECT count(*) as unread, tr.thread_first_read, tr.thread_last_read 
    197197                FROM ".$db_prefix."posts p 
    198198                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id 
     
    200200                    AND tr.thread_id = '".$thread_id."'  
    201201                    AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].")  
    202                     AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     202                    AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     203                        OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
    203204                GROUP BY tr.thread_id 
    204205            "); 
     
    206207        // filter the users own posts 
    207208        $result = dbquery(" 
    208             SELECT count(*) as unread, tr.thread_last_read 
     209            SELECT count(*) as unread, tr.thread_first_read, tr.thread_last_read 
    209210                FROM ".$db_prefix."posts p 
    210211                LEFT JOIN ".$db_prefix."threads_read tr ON p.thread_id = tr.thread_id 
     
    214215                    AND tr.thread_id = '".$thread_id."'  
    215216                    AND (p.post_datestamp > ".$settings['unread_threshold']." OR p.post_edittime > ".$settings['unread_threshold'].")  
    216                     AND (p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     217                    AND ((p.post_datestamp > tr.thread_last_read OR p.post_edittime > tr.thread_last_read) 
     218                        OR (p.post_datestamp < tr.thread_first_read OR (p.post_edittime != 0 AND p.post_edittime < tr.thread_first_read))) 
    217219                GROUP BY tr.thread_id 
    218220            "); 
     
    221223        $data = dbarray($result); 
    222224        $variables['unread_posts'] = $data['unread']; 
     225        $thread_first_read = $data['thread_first_read']; 
    223226        $thread_last_read = $data['thread_last_read']; 
    224227    } else { 
    225228        $variables['unread_posts'] = 0; 
     229        $thread_first_read = 0; 
    226230        $thread_last_read = time(); 
    227231    } 
    228232} else { 
    229233    $variables['unread_posts'] = 0; 
     234    $thread_first_read = 0; 
    230235    $thread_last_read = time(); 
    231236} 
     
    243248$variables['thread_has_poll'] = fpm_view(); 
    244249 
    245 // last_post_datestamp, needed to update threads_read later 
     250// init first_post_datestamp, needed to update threads_read later 
     251$first_post_datestamp = 4294967295; 
     252 
     253// init last_post_datestamp, needed to update threads_read later 
    246254$last_post_datestamp = 0; 
    247255 
     
    278286        } 
    279287        // check if this post is read or unread 
    280         $data['unread'] = $data['post_datestamp'] > $thread_last_read || $data['post_edittime'] > $thread_last_read; 
     288        $data['unread'] = $data['post_datestamp'] > $thread_last_read || $data['post_edittime'] > $thread_last_read || $data['post_datestamp'] < $thread_first_read || ($data['post_edittime'] != 0 && $data['post_edittime'] < $thread_first_read) ; 
     289 
     290        // update first_post_datestamp 
     291        if ($data['post_edittime'] == 0) { 
     292            $first_post_datestamp = min($data['post_datestamp'], $first_post_datestamp); 
     293        } else { 
     294            $first_post_datestamp = min($data['post_datestamp'], $data['post_edittime'], $first_post_datestamp); 
     295        } 
    281296 
    282297        // update last_post_datestamp 
     
    392407} 
    393408 
    394 // update the threads_read record for this user and thread when the last_post_datestamp is newer 
    395 if (iMEMBER && $last_post_datestamp) { 
    396     $result = dbquery("UPDATE ".$db_prefix."threads_read SET thread_last_read = '".$last_post_datestamp."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$thread_id."' AND thread_last_read < '".$last_post_datestamp."'"); 
     409if (iMEMBER) { 
     410    // update the threads_read record for this user and thread when the first_post_datestamp is older 
     411    if ($first_post_datestamp) { 
     412        $result = dbquery("UPDATE ".$db_prefix."threads_read SET thread_first_read = '".$first_post_datestamp."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$thread_id."' AND thread_first_read > '".$first_post_datestamp."'"); 
     413    } 
     414    // update the threads_read record for this user and thread when the last_post_datestamp is newer 
     415    if ($last_post_datestamp) { 
     416        $result = dbquery("UPDATE ".$db_prefix."threads_read SET thread_last_read = '".$last_post_datestamp."' WHERE user_id = '".$userdata['user_id']."' AND thread_id = '".$thread_id."' AND thread_last_read < '".$last_post_datestamp."'"); 
     417    } 
    397418} 
    398419 
Note: See TracChangeset for help on using the changeset viewer.