summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-12-01 13:59:06 +0100
committerYorhel <git@yorhel.nl>2019-12-01 13:59:09 +0100
commite69504ae68f4d37bae69919aaee484aee3c0aa84 (patch)
tree3fb33117916cb7c97d376e70662c1a371cd4ac9f
parent165b62acc991cbf30cb721af27b04a066dbc9413 (diff)
Discussions: Do not highlight post when nagivating to the "last post"
That behavior was more distracting, especially when the intention of the link isn't to link to that post in particular, but just to the more recent part of the thread. As an additional advantage, this doesn't rely on the t#.# redirect anymore, this making browsing the forums slightly faster.
-rw-r--r--lib/VNDB/Handler/Discussions.pm2
-rw-r--r--lib/VNDB/Handler/Misc.pm2
-rw-r--r--lib/VNWeb/Discussions/Lib.pm11
-rw-r--r--lib/VNWeb/Discussions/Thread.pm4
4 files changed, 13 insertions, 6 deletions
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index aa15f360..b10e7aaf 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -159,7 +159,7 @@ sub edit {
$self->dbPostEdit($tid, $num, %post) if $num;
$nnum = $self->dbPostAdd($ntid, %post) if !$num;
- return $self->resRedirect("/t$ntid".($nnum > 25 ? '/'.ceil($nnum/25) : '').'#'.$nnum, 'post');
+ return $self->resRedirect(VNWeb::Discussions::Lib::post_url($ntid, $nnum, 'last'), 'post');
}
}
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 76663601..25d10c39 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -122,7 +122,7 @@ sub homepage {
my $boards = join ', ', map $BOARD_TYPE{$_->{type}}{txt}.($_->{iid}?' > '.$_->{title}:''), @{$_->{boards}};
li;
txt fmtage($_->{lastpost_date}).' ';
- a href => "/t$_->{id}.$_->{count}", title => "Posted in $boards", shorten $_->{title}, 25;
+ a href => VNWeb::Discussions::Lib::post_url($_->{id}, $_->{count}, 'last'), title => "Posted in $boards", shorten $_->{title}, 25;
lit ' by ';
VNWeb::HTML::user_($_, 'lastpost_');
end;
diff --git a/lib/VNWeb/Discussions/Lib.pm b/lib/VNWeb/Discussions/Lib.pm
index 88f6cac6..4ab1900c 100644
--- a/lib/VNWeb/Discussions/Lib.pm
+++ b/lib/VNWeb/Discussions/Lib.pm
@@ -3,7 +3,14 @@ package VNWeb::Discussions::Lib;
use VNWeb::Prelude;
use Exporter 'import';
-our @EXPORT = qw/sql_visible_threads enrich_boards threadlist_ boardsearch_ boardtypes_/;
+our @EXPORT = qw/post_url sql_visible_threads enrich_boards threadlist_ boardsearch_ boardtypes_/;
+
+
+# Returns the URL to the thread page holding the given post (with optional location.hash)
+sub post_url {
+ my($id, $num, $hash) = @_;
+ "/t$id".($num > 25 ? '/'.ceil($num/25) : '').($hash ? "#$hash" : '');
+}
# Returns a WHERE condition to filter threads that the current user is allowed to see.
@@ -94,7 +101,7 @@ sub threadlist_ {
td_ class => 'tc4', sub {
user_ $l, 'lastpost_';
txt_ ' @ ';
- a_ href => "/t$l->{id}.$l->{count}", fmtdate $l->{lastpost_date}, 'full';
+ a_ href => post_url($l->{id}, $l->{count}, 'last'), fmtdate $l->{lastpost_date}, 'full';
};
} for @$lst;
}
diff --git a/lib/VNWeb/Discussions/Thread.pm b/lib/VNWeb/Discussions/Thread.pm
index 01cb5359..30827aaa 100644
--- a/lib/VNWeb/Discussions/Thread.pm
+++ b/lib/VNWeb/Discussions/Thread.pm
@@ -63,7 +63,7 @@ sub posts_ {
div_ class => 'mainbox thread', sub {
table_ class => 'stripe', sub {
tr_ mkclass(deleted => $_->{hidden}), id => $_->{num}, sub {
- td_ class => 'tc1', sub {
+ td_ class => 'tc1', $t->{count} == $_->{num} ? (id => 'last') : (), sub {
a_ href => "/t$t->{id}.$_->{num}", "#$_->{num}";
if(!$_->{hidden}) {
txt_ ' by ';
@@ -175,7 +175,7 @@ TUWF::get qr{/$RE{tid}(?:/$RE{num})?}, sub {
TUWF::get qr{/$RE{postid}}, sub {
my($id, $num) = (tuwf->capture('id'), tuwf->capture('num'));
- tuwf->resRedirect("/t$id".($num > 25 ? '/'.ceil($num/25) : '').'#'.$num, 'perm')
+ tuwf->resRedirect(post_url($id, $num, $num), 'perm')
};