From bc067a7562a586bed92401fe1084bbe423b9451a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 25 Dec 2015 09:35:38 +0000 Subject: view: move thread info near top of single view Most framed mail viewing software has message ancestry information near the top instead of bottom (mutt, gmane, sylpheed, thunderbird) as it can help improve context. Traditional netiquette also favors writing replies below quoted (older) text for this reason; so move the thread summary to the top of the message for context. Since threads may be long, add a "skip" anchor link to jump to the message body quickly, and align the date to the left column so it's easier to tell the relative age of messages. While we're at it, remove quotes from "id" attributes to improve ease-of-grep-ability. --- lib/PublicInbox/View.pm | 70 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 1bf44dea..98d0219d 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -99,7 +99,7 @@ sub index_entry { $subj = "$subj"; } if ($root_anchor eq $id) { - $subj = "$subj"; + $subj = "$subj"; } my $ts = _msg_date($mime); @@ -108,7 +108,7 @@ sub index_entry { $rv .= '
' . (INDENT x $level) . '
'; } $rv .= "" . PublicInbox::Hval::PRE; - $rv .= "$subj\n"; + $rv .= "$subj\n"; $rv .= "- $from @ $ts UTC - "; $rv .= "next"; if ($prev >= 0) { @@ -200,7 +200,7 @@ sub emit_thread_html { return missing_thread($cb, $ctx) if ($orig_cb eq $cb); my $final_anchor = $state->{anchor_idx}; - my $next = ""; + my $next = ""; $next .= $final_anchor == 1 ? 'only message in' : 'end of'; $next .= " thread, back to index"; $next .= "\ndownload thread: "; @@ -428,9 +428,8 @@ sub headers_to_html_header { } elsif ($h eq 'Subject') { $title[0] = $v->as_html; if ($srch) { - my $p = $full_pfx ? '' : '../'; - $rv .= "$h: "; - $rv .= $v->as_html . "\n"; + $rv .= "$h: "; + $rv .= $v->as_html . "\n"; next; } } @@ -442,11 +441,7 @@ sub headers_to_html_header { $rv .= "(raw)\n"; my $atom; if ($srch) { - if ($header_obj->header('In-Reply-To') || - $header_obj->header('References')) { - $rv .= "" . - "References: [expand]\n"; - } + thread_inline(\$rv, $ctx, $mime, $upfx); $atom = qq{!; @@ -461,24 +456,27 @@ sub headers_to_html_header { } sub thread_inline { - my ($dst, $ctx, $cur, $full_pfx) = @_; + my ($dst, $ctx, $cur, $upfx) = @_; my $srch = $ctx->{srch}; my $mid = mid_clean($cur->header('Message-ID')); my $res = $srch->get_thread($mid); my $nr = $res->{total}; - my $upfx = $full_pfx ? '' : '../'; - my $expand = "(expand " . - "/ mbox.gz)"; + my $expand = "expand " . + "/ mbox.gz"; + $$dst .= 'Thread: '; + my $parent = in_reply_to($cur); if ($nr <= 1) { - $$dst .= "\n[no followups, yet] $expand\n"; - return (undef, in_reply_to($cur)); + $$dst .= "[no followups, yet] ($expand)\n"; + $ctx->{next_msg} = undef; + $ctx->{parent_msg} = $parent; + return; } - $$dst .= "\n\n~$nr messages in thread: $expand\n"; + $$dst .= "~$nr messages (skip / " . + $expand . ")\n"; my $subj = $srch->subject_path($cur->header('Subject')); - my $parent = in_reply_to($cur); my $state = { seen => { $subj => 1 }, srch => $srch, @@ -491,7 +489,9 @@ sub thread_inline { for (thread_results(load_results($res))->rootset) { inline_dump($dst, $state, $upfx, $_, 0); } - ($state->{next_msg}, $state->{parent}); + $$dst .= ""; # anchor for body start + $ctx->{next_msg} = $state->{next_msg}; + $ctx->{parent_msg} = $state->{parent}; } sub _parent_headers_nosrch { @@ -562,11 +562,12 @@ sub html_footer { my $idx = $standalone ? " index" : ''; if ($srch && $standalone) { - $idx .= qq{ / follow: Atom feed}; + $idx .= qq{ / follow: Atom feed\n}; } if ($idx && $srch) { - my ($next, $p) = thread_inline(\$idx, $ctx, $mime, $full_pfx); - if (defined $p) { + my $p = $ctx->{parent_msg}; + my $next = $ctx->{next_msg}; + if ($p) { $p = PublicInbox::Hval->new_oneline($p); $p = $p->as_href; $irt = "parent "; @@ -576,7 +577,12 @@ sub html_footer { if ($next) { $irt .= "next "; } else { - $irt .= ' '; + $irt .= ' ' x length('next '); + } + if ($p || $next) { + $irt .= "thread "; + } else { + $irt .= ' ' x length('thread '); } } else { $irt = ''; @@ -722,7 +728,6 @@ sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) } sub _inline_header { my ($dst, $state, $upfx, $mime, $level) = @_; - my $pfx = INDENT x ($level - 1); my $dot = $level == 0 ? '' : '` '; my $cur = $state->{cur}; @@ -731,12 +736,12 @@ sub _inline_header { my $d = _msg_date($mime); $f = PublicInbox::Hval->new($f)->as_html; $d = PublicInbox::Hval->new($d)->as_html; - my $attr = "$f @ $d"; + my $pfx = ' ' . $d . ' ' . (INDENT x $level); + my $attr = $f; $state->{first_level} ||= $level; + if ($attr ne $state->{prev_attr} || $state->{prev_level} > $level) { $state->{prev_attr} = $attr; - $attr = ' - ' . $attr; - $attr .= ' UTC' if $level >= $state->{first_level}; } else { $attr = ''; } @@ -745,8 +750,8 @@ sub _inline_header { if ($cur) { if ($cur eq $mid) { delete $state->{cur}; - $$dst .= "$pfx$dot". - "[this message]$attr\n"; + $$dst .= "$pfx$dot". + "$attr [this message]\n"; return; } @@ -771,7 +776,7 @@ sub _inline_header { if (defined $s) { $$dst .= "$pfx$dot$s$attr\n"; } else { - $$dst .= "$pfx$dot$f @ $d\n"; + $$dst .= "$pfx$dot$f\n"; } } @@ -786,7 +791,8 @@ sub inline_dump { _inline_header($dst, $state, $upfx, $mime, $level); } else { my $dot = $level == 0 ? '' : '` '; - my $pfx = (INDENT x $level) . $dot; + my $pfx = length(' 1970-01-01 13:37 ') . + (INDENT x $level) . $dot; $$dst .= $pfx; $$dst .= ghost_parent("$upfx../", $node->messageid) . "\n"; } -- cgit v1.2.3-24-ge0c7