diff options
author | Yorhel <git@yorhel.nl> | 2009-10-10 15:51:57 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-10-10 15:51:57 +0200 |
commit | 5ce2ce4c494feef5940c032549472a52b5282ad1 (patch) | |
tree | 89efb88dc1fc0afbb2d4ba3b29a37e154453edeb /lib | |
parent | 1e125f67ab50a5de477c538b3f7dd27a9ec3c62f (diff) |
Display number of unread posts in user menu
Instead of displaying the total number of threads. Posts are marked as
read when the thread is opened.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/DB/Discussions.pm | 12 | ||||
-rw-r--r-- | lib/VNDB/DB/Users.pm | 8 | ||||
-rw-r--r-- | lib/VNDB/Handler/Discussions.pm | 5 |
3 files changed, 23 insertions, 2 deletions
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm index 26beaaee..60487098 100644 --- a/lib/VNDB/DB/Discussions.pm +++ b/lib/VNDB/DB/Discussions.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount|; +our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount dbPostRead|; # Options: id, type, iid, results, page, what, notusers @@ -243,5 +243,15 @@ sub dbPostAdd { } +sub dbPostRead { # thread id, user id, last post number + my($s, $tid, $uid, $num) = @_; + $s->dbExec(q| + UPDATE threads_boards + SET lastread = ? + WHERE tid = ? AND type = 'u' AND iid = ?|, + $num, $tid, $uid); +} + + 1; diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm index b2cd1a31..cb25b9fe 100644 --- a/lib/VNDB/DB/Users.pm +++ b/lib/VNDB/DB/Users.pm @@ -54,7 +54,13 @@ sub dbUserGet { '(SELECT COUNT(DISTINCT vid) FROM tags_vn WHERE uid = u.id) AS tagvncount', ) : (), $o{what} =~ /mymessages/ ? - '(SELECT COUNT(*) FROM threads_boards tb JOIN threads t ON t.id = tb.tid WHERE tb.type = \'u\' AND tb.iid = u.id AND t.hidden = FALSE) AS mymessages' : (), + q{COALESCE((SELECT SUM(tbi.count) FROM ( + SELECT t.count-COALESCE(tb.lastread,0) + FROM threads_boards tb + JOIN threads t ON t.id = tb.tid AND NOT t.hidden + WHERE tb.type = 'u' AND tb.iid = u.id) AS tbi (count) + ), 0) AS mymessages + } : (), ); my($r, $np) = $s->dbPage(\%o, q| diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm index 1d74ac6a..5fedaeed 100644 --- a/lib/VNDB/Handler/Discussions.pm +++ b/lib/VNDB/Handler/Discussions.pm @@ -29,6 +29,11 @@ sub thread { my $p = $self->dbPostGet(tid => $tid, results => 25, page => $page, what => 'user'); return 404 if !$p->[0]; + # mark as read when this thread is posted in the board of the currently logged in user + my $uid = $self->authInfo->{id}; + $self->dbPostRead($t->{id}, $uid, $p->[$#$p]{num}) + if $uid && grep $_->{type} eq 'u' && $_->{iid} == $uid, @{$t->{boards}}; + $self->htmlHeader(title => $t->{title}); div class => 'mainbox'; |