]> ruin.nu Git - ndwebbie.git/commitdiff
mark threads as read
authorMichael Andreen <harv@ruin.nu>
Sun, 7 Jan 2007 21:11:07 +0000 (21:11 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 7 Jan 2007 21:11:07 +0000 (21:11 +0000)
ND/Web/Pages/Forum.pm
templates/forum.tmpl

index 3e8f30e01a3f7ccd2046764c2663e2946216484b..a166b64ad823e0f134b7b6c6e38dc4b80e2c103d 100644 (file)
@@ -29,7 +29,7 @@ $ND::PAGES{forum} = {parse => \&parse, process => \&process, render=> \&render};
 
 sub parse {
        my ($uri) = @_;
-       if ($uri =~ m{^/.*/allUnread$}){
+       if ($uri =~ m{^/.*/allUnread}){
                param('allUnread',1);
        }
 }
@@ -52,6 +52,22 @@ sub render {
                        GROUP BY fb.fbid,fb.board});
                $board = $DBH->selectrow_hashref($boards,undef,param('b'),$ND::UID) or $ND::ERROR .= p($DBH->errstr);
        }
+       if (param('markAsRead')){
+               my $threads = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject,count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) AS unread,count(fp.fpid) AS posts, max(fp.time)::timestamp as last_post
+               FROM forum_threads ft JOIN forum_posts fp USING (ftid) LEFT OUTER JOIN (SELECT * FROM forum_thread_visits WHERE uid = $2) ftv ON ftv.ftid = ft.ftid
+               WHERE ((ft.fbid IS NULL AND $1 IS NULL) OR ft.fbid = $1) AND fp.time <= $3
+               GROUP BY ft.ftid, ft.subject
+               HAVING count(NULLIF(COALESCE(fp.time > ftv.time,TRUE),FALSE)) >= 1
+               });
+
+               $threads->bind_param('$1',$board->{id},{TYPE => DBI::SQL_INTEGER }) or $ND::ERROR .= p($DBH->errstr);
+               $threads->bind_param('$2',$ND::UID,{TYPE => DBI::SQL_INTEGER }) or $ND::ERROR .= p($DBH->errstr);
+               $threads->bind_param('$3',param('markAsRead')) or $ND::ERROR .= p($DBH->errstr);
+               $threads->execute or $ND::ERROR .= p($DBH->errstr);
+               while (my $thread = $threads->fetchrow_hashref){
+                       markThreadAsRead $thread->{id};
+               }
+       }
 
        my $thread;
        my $findThread = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject, bool_or(fa.post) AS post
@@ -85,23 +101,11 @@ sub render {
        if ($thread){ #Display the thread
                $BODY->param(Thread => viewForumThread $thread);
 
-       }elsif($board){ #List threads in this board
-               $BODY->param(Board => $board->{board});
-               $BODY->param(Post => $board->{post});
-               $BODY->param(Id => $board->{id});
-               $threads->execute($board->{id},$ND::UID,0) or $ND::ERROR .= p($DBH->errstr);
-               my $i = 0;
-               my @threads;
-               while (my $thread = $threads->fetchrow_hashref){
-                       $i++;
-                       $thread->{Odd} = $i % 2;
-                       push @threads,$thread;
-               }
-               $BODY->param(Threads => \@threads);
-
        }elsif(defined param('allUnread')){ #List threads in this board
                $BODY->param(AllUnread => 1);
                $BODY->param(Id => $board->{id});
+               my ($time) = $DBH->selectrow_array('SELECT now()::timestamp',undef);
+               $BODY->param(Date => $time);
                $categories->execute or $ND::ERROR .= p($DBH->errstr);
                my @categories;
                my $boards = $DBH->prepare(q{SELECT fb.fbid AS id,fb.board, bool_or(fa.post) AS post
@@ -133,6 +137,22 @@ sub render {
                }
                $BODY->param(Categories => \@categories);
 
+       }elsif($board){ #List threads in this board
+               $BODY->param(Board => $board->{board});
+               $BODY->param(Post => $board->{post});
+               $BODY->param(Id => $board->{id});
+               my ($time) = $DBH->selectrow_array('SELECT now()::timestamp',undef);
+               $BODY->param(Date => $time);
+               $threads->execute($board->{id},$ND::UID,0) or $ND::ERROR .= p($DBH->errstr);
+               my $i = 0;
+               my @threads;
+               while (my $thread = $threads->fetchrow_hashref){
+                       $i++;
+                       $thread->{Odd} = $i % 2;
+                       push @threads,$thread;
+               }
+               $BODY->param(Threads => \@threads);
+
        }else{ #List boards
                $BODY->param(Overview => 1);
                $categories->execute or $ND::ERROR .= p($DBH->errstr);
index 8081a48b77ea1dc628833d508d4c992b1a71526a..bb57fb2fb901a605090fbede43cb7ff347eb6e16 100644 (file)
@@ -1,6 +1,7 @@
 <TMPL_VAR Thread>
 <TMPL_IF Board>
 <h2><TMPL_VAR NAME=Board></h2>
+<p><a href="<TMPL_VAR NAME=PAGE>?b=<TMPL_VAR NAME=Id>;markAsRead=<TMPL_VAR ESCAPE=URL NAME=DATE>">Mark threads as read</a></p>
 <table class="boards">
 <tr>
        <th>Unread</th>
@@ -61,6 +62,7 @@
        <tr>
                <th></th>
                <th colspan="2"><a href="<TMPL_VAR NAME=PAGE>?b=<TMPL_VAR NAME=Id>"><TMPL_VAR NAME=Board></a></th>
+               <th><a href="<TMPL_VAR NAME=PAGE>/allUnread?b=<TMPL_VAR NAME=Id>;markAsRead=<TMPL_VAR ESCAPE=URL NAME=DATE>">Mark threads as read</a></th>
        </tr>
                <TMPL_LOOP Threads>
        <tr class="<TMPL_IF ODD>odd<TMPL_ELSE>even</TMPL_IF>">