From: Michael Andreen Date: Tue, 2 Jan 2007 02:39:22 +0000 (+0000) Subject: mark threads as read X-Git-Url: https://ruin.nu/git/?a=commitdiff_plain;ds=sidebyside;h=6d6177b5221cc6d74b58c73c91f33bc8132649db;p=ndwebbie.git mark threads as read --- diff --git a/ND.pm b/ND.pm index 404c879..c54bb77 100755 --- a/ND.pm +++ b/ND.pm @@ -43,6 +43,7 @@ sub handler { local $ND::BODY; local $ND::TICK; local %ND::GROUPS; + local $ND::ERROR; local $ND::PAGE = $ND::req->param('page'); if ($ENV{'SCRIPT_NAME'} =~ /(\w+)(\.(pl|php|pm))?$/){ @@ -55,7 +56,9 @@ sub handler { sub page { our $DBH = ND::DB::DB(); - my $error = ''; + $DBH->do(q{SET timezone = 'GMT'}); + + our $ERROR = ''; chdir '/var/www/ndawn/code'; @@ -100,9 +103,9 @@ sub page { } unless (my $return = do "$ND::PAGE.pl"){ - $error .= "

couldn't parse $ND::PAGE: $@

" if $@; - $error .= "

couldn't do $ND::PAGE: $!

" unless defined $return && defined $!; - $error .= "

couldn't run $ND::PAGE

" unless $return; + $ERROR .= "

couldn't parse $ND::PAGE: $@

" if $@; + $ERROR .= "

couldn't do $ND::PAGE: $!

" unless defined $return && defined $!; + $ERROR .= "

couldn't run $ND::PAGE

" unless $return; } unless ($XML){ @@ -123,7 +126,7 @@ sub page { $TEMPLATE->param(Coords => param('coords') ? param('coords') : '1:1:1'); } - $TEMPLATE->param(Error => $error); + $TEMPLATE->param(Error => $ERROR); $ND::TEMPLATE->param(BODY => $ND::BODY->output); my $output = $TEMPLATE->output; print header(-type=> $type, -charset => 'utf-8', -Content_Length => length $output); diff --git a/ND/Include.pm b/ND/Include.pm index bec7dd5..e51d0e6 100644 --- a/ND/Include.pm +++ b/ND/Include.pm @@ -20,12 +20,13 @@ package ND::Include; use strict; use warnings FATAL => 'all'; +use CGI qw{:standard}; require Exporter; our @ISA = qw/Exporter/; our @EXPORT = qw/isMember isHC isDC isBC isOfficer isScanner isIntel isTech parseMarkup min max listTargets - alliances intelquery generateClaimXml/; + alliances intelquery generateClaimXml markThreadAsRead/; sub isMember { return exists $ND::GROUPS{Members} || isTech(); @@ -67,6 +68,18 @@ sub parseMarkup { return $text; } +sub markThreadAsRead { + my ($thread) = @_; + my $rows = $ND::DBH->do(q{UPDATE forum_thread_visits SET time = now() +WHERE uid = $1 AND ftid = $2},undef,$ND::UID,$thread); + if ($rows == 0){ + $ND::DBH->do(q{INSERT INTO forum_thread_visits (uid,ftid) VALUES ($1,$2)} + ,undef,$ND::UID,$thread) or $ND::ERROR .= p($ND::DBH->errstr); + }else{ + $ND::ERROR .= p($ND::DBH->errstr); + } +} + sub min { my ($x,$y) = @_; return ($x > $y ? $y : $x); diff --git a/forum.pl b/forum.pl index c7f0d04..8f2698f 100644 --- a/forum.pl +++ b/forum.pl @@ -27,7 +27,14 @@ our $DBH; my $error; my $thread; -#TODO: fetch thread info. +if(param('t')){ + my $query = $DBH->prepare(q{SELECT ft.ftid AS id,ft.subject, bool_or(fa.post) AS post +FROM forum_boards fb NATURAL JOIN forum_access fa NATURAL JOIN forum_threads ft +WHERE ft.ftid = $1 AND (gid = -1 OR gid IN (SELECT gid FROM groupmembers + WHERE uid = $2)) +GROUP BY ft.ftid,ft.subject}); + $thread = $DBH->selectrow_hashref($query,undef,param('t'),$ND::UID) or $error .= p($DBH->errstr); +} my $board; if(param('b')){ @@ -40,8 +47,31 @@ GROUP BY fb.fbid,fb.board}); } if ($thread){ #Display the thread + $BODY->param(Thread => 1); + $BODY->param(Subject => $thread->{subject}); + $BODY->param(Id => $thread->{id}); + $BODY->param(Post => $thread->{post}); + + my $posts = $DBH->prepare(q{SELECT u.username,date_trunc('minute',fp.time::timestamp) AS time,fp.message,COALESCE(fp.time > ftv.time,TRUE) AS unread +FROM forum_threads ft JOIN forum_posts fp USING (ftid) NATURAL JOIN users u LEFT OUTER JOIN forum_thread_visits ftv ON ftv.ftid = ft.ftid +WHERE ft.ftid = $1}); + $posts->execute($thread->{id}) or $error .= p($DBH->errstr); + my @posts; + my $old = 1; + while (my $post = $posts->fetchrow_hashref){ + if ($old && $post->{unread}){ + $old = 0; + push @posts,{Username=> 'New posts', Message => ''}; + } + $post->{message} = parseMarkup($post->{message}); + push @posts,$post; + } + $BODY->param(Posts => \@posts); + + markThreadAsRead($thread->{id}); + }elsif($board){ #List threads in this board - $BODY->param(Board => 1); + $BODY->param(Board => $board->{board}); $BODY->param(Post => $board->{post}); $BODY->param(Id => $board->{id}); 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 diff --git a/templates/forum.tmpl b/templates/forum.tmpl index 7f2095c..8363113 100644 --- a/templates/forum.tmpl +++ b/templates/forum.tmpl @@ -1,7 +1,15 @@ +

+ +
+ : + +
+
+

diff --git a/templates/skel.tmpl b/templates/skel.tmpl index 7da889d..b259899 100644 --- a/templates/skel.tmpl +++ b/templates/skel.tmpl @@ -13,6 +13,7 @@

Tick:

Member menu

Unread