summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Discussions.pm12
-rw-r--r--lib/VNDB/DB/Users.pm8
-rw-r--r--lib/VNDB/Handler/Discussions.pm5
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';