summaryrefslogtreecommitdiff
path: root/lib/VNDB/DB/Users.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-10-10 16:05:30 +0200
committerYorhel <git@yorhel.nl>2009-10-10 16:05:30 +0200
commitecf82cabc44dcd333f0e46c037c7d9c1c4046a0d (patch)
treef76c4d3b8de834104410ad20088866a94e8d7c77 /lib/VNDB/DB/Users.pm
parent5453223bf93a17d49d2717f8e0fbc70ed8477a94 (diff)
Get unread posts count in htmlHeader() instead of Util::Auth
This way the counter resets itself immediately when opening the unread thread page, which is more intuitive.
Diffstat (limited to 'lib/VNDB/DB/Users.pm')
-rw-r--r--lib/VNDB/DB/Users.pm26
1 files changed, 16 insertions, 10 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)