summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VNDB/DB/Users.pm26
-rw-r--r--lib/VNDB/Util/Auth.pm4
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm3
3 files changed, 20 insertions, 13 deletions
diff --git a/lib/VNDB/DB/Users.pm b/lib/VNDB/DB/Users.pm
index cb25b9fe..ee4f2b14 100644
--- a/lib/VNDB/DB/Users.pm
+++ b/lib/VNDB/DB/Users.pm
@@ -5,11 +5,11 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbSessionAdd dbSessionDel dbSessionCheck|;
+our @EXPORT = qw|dbUserGet dbUserEdit dbUserAdd dbUserDel dbUserMessageCount dbSessionAdd dbSessionDel dbSessionCheck|;
# %options->{ username passwd mail order uid ip registered search results page what }
-# what: stats mymessages
+# what: stats
sub dbUserGet {
my $s = shift;
my %o = (
@@ -53,14 +53,6 @@ sub dbUserGet {
'(SELECT COUNT(DISTINCT tag) FROM tags_vn WHERE uid = u.id) AS tagcount',
'(SELECT COUNT(DISTINCT vid) FROM tags_vn WHERE uid = u.id) AS tagvncount',
) : (),
- $o{what} =~ /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|
@@ -116,6 +108,20 @@ sub dbUserDel {
}
+# Returns number of unread messages
+sub dbUserMessageCount { # uid
+ my($s, $uid) = @_;
+ return $s->dbRow(q{
+ SELECT SUM(tbi.count) AS cnt 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 = ?
+ ) AS tbi (count)
+ }, $uid)->{cnt}||0;
+}
+
+
# Adds a session to the database
# If no expiration is supplied the database default is used
# uid, 40 character session token, expiration time (timestamp)
diff --git a/lib/VNDB/Util/Auth.pm b/lib/VNDB/Util/Auth.pm
index c4daffd9..2595ce5b 100644
--- a/lib/VNDB/Util/Auth.pm
+++ b/lib/VNDB/Util/Auth.pm
@@ -26,7 +26,7 @@ sub authInit {
my $token = substr($cookie, 0, 40);
my $uid = substr($cookie, 40);
return _rmcookie($self) if $uid !~ /^\d+$/ || !$self->dbSessionCheck($uid, $token);
- $self->{_auth} = $self->dbUserGet(uid => $uid, what => 'mymessages')->[0];
+ $self->{_auth} = $self->dbUserGet(uid => $uid)->[0];
}
@@ -95,7 +95,7 @@ sub _authCheck {
return 0 if !$user || length($user) > 15 || length($user) < 2 || !$pass;
- my $d = $self->dbUserGet(username => $user, what => 'mymessages')->[0];
+ my $d = $self->dbUserGet(username => $user)->[0];
return 0 if !defined $d->{id} || !$d->{rank};
if(_authEncryptPass($self, $pass, $d->{salt}) eq $d->{passwd}) {
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 34cbd30d..084b9a4e 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -79,6 +79,7 @@ sub _menu {
div class => 'menubox';
if($self->authInfo->{id}) {
+ my $msg = $self->dbUserMessageCount($self->authInfo->{id});
my $uid = sprintf '/u%d', $self->authInfo->{id};
h2;
a href => $uid, ucfirst $self->authInfo->{username};
@@ -89,7 +90,7 @@ sub _menu {
a href => "$uid/edit", mt '_menu_myprofile'; br;
a href => "$uid/list", mt '_menu_myvnlist'; br;
a href => "$uid/wish", mt '_menu_mywishlist'; br;
- a href => "/t$uid", $self->authInfo->{mymessages} ? (class => 'standout') : (), mt '_menu_mymessages', $self->authInfo->{mymessages}; br;
+ a href => "/t$uid", $msg ? (class => 'standout') : (), mt '_menu_mymessages', $msg; br;
a href => "$uid/hist", mt '_menu_mychanges'; br;
a href => "$uid/tags", mt '_menu_mytags'; br;
br;