summaryrefslogtreecommitdiff
path: root/lib/VNWeb
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-11-19 11:37:38 +0100
committerYorhel <git@yorhel.nl>2019-11-19 11:37:44 +0100
commit0995b205d39236c23aaa984ddb2e39dec38d7dce (patch)
tree5e3c5426f3fb111896c600e26186bd1250923e02 /lib/VNWeb
parentbd2ff24a35ec70aad52ae5352ce349da53ee5248 (diff)
Fix consistency between discussion counter in the dbentry tabs and actual listing
i.e. private and hidden threads are now included in the counter if you can see those threads.
Diffstat (limited to 'lib/VNWeb')
-rw-r--r--lib/VNWeb/Discussions/Lib.pm14
-rw-r--r--lib/VNWeb/HTML.pm2
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/VNWeb/Discussions/Lib.pm b/lib/VNWeb/Discussions/Lib.pm
index f2439f97..a387c55e 100644
--- a/lib/VNWeb/Discussions/Lib.pm
+++ b/lib/VNWeb/Discussions/Lib.pm
@@ -6,6 +6,14 @@ use Exporter 'import';
our @EXPORT = qw/threadlist_ boardsearch_ boardtypes_/;
+# Returns a WHERE condition to filter threads that the current user is allowed to see.
+sub sql_visible_threads {
+ sql_and
+ auth->permBoardmod ? () : ('NOT t.hidden'),
+ sql('NOT t.private OR EXISTS(SELECT 1 FROM threads_boards WHERE tid = t.id AND type = \'u\' AND iid =', \auth->uid, ')');
+}
+
+
# Generate a thread list table, options:
# where => SQL for the WHERE clause ('t' is available as alias for 'threads').
# boards => SQL for the WHERE clause of the boards ('tb' as alias for 'threads_boards').
@@ -18,11 +26,7 @@ our @EXPORT = qw/threadlist_ boardsearch_ boardtypes_/;
sub threadlist_ {
my %opt = @_;
- my $where = sql_and
- # Make sure we can only see threads we're allowed to see.
- auth->permBoardmod ? () : ('NOT t.hidden'),
- sql('NOT t.private OR EXISTS(SELECT 1 FROM threads_boards WHERE tid = t.id AND type = \'u\' AND iid =', \auth->uid, ')'),
- $opt{where}||();
+ my $where = sql_and sql_visible_threads(), $opt{where}||();
my $count = $opt{paginate} && tuwf->dbVali('SELECT count(*) FROM threads t WHERE', $where);
return 0 if $opt{paginate} && !$count;
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 24989851..c35a2518 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -333,7 +333,7 @@ sub _maintabs_ {
SELECT COUNT(*)
FROM threads_boards tb
JOIN threads t ON t.id = tb.tid
- WHERE}, { 'tb.type' => $t, 'tb.iid' => $o->{id}, 't.hidden' => 0, 't.private' => 0 });
+ WHERE tb.type =}, \$t, 'AND tb.iid =', \$o->{id}, 'AND', VNWeb::Discussions::Lib::sql_visible_threads());
t disc => "/t/$id", "discussions ($cnt)";
};
t posts => "/$id/posts", 'posts' if $t eq 'u';