user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 03/13] view: show thread context in the thread-aware flat view
  2016-06-30  9:21  7% [PATCH 0/13] www: hybrid flat+thread conversation view Eric Wong
@ 2016-06-30  9:21  4% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-06-30  9:21 UTC (permalink / raw)
  To: meta

This lets user have a small window of the context of
the current message relative to other threads.
---
 lib/PublicInbox/Feed.pm       |   3 +-
 lib/PublicInbox/SearchView.pm |   2 +-
 lib/PublicInbox/View.pm       | 160 +++++++++++++++++++++++++-----------------
 3 files changed, 100 insertions(+), 65 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 36802fa..73986e8 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -138,6 +138,7 @@ sub emit_html_index {
 	my $fh = $res->([200,['Content-Type'=>'text/html; charset=UTF-8']]);
 
 	my $max = $ctx->{max} || MAX_PER_PAGE;
+	$ctx->{-upfx} = '';
 
 	my ($footer, $param, $last);
 	my $state = { ctx => $ctx, seen => {}, anchor_idx => 0, fh => $fh };
@@ -174,7 +175,7 @@ sub emit_index_nosrch {
 		$state->{first} ||= $commit;
 
 		my $mime = do_cat_mail($ibx, $path) or return 0;
-		$fh->write(PublicInbox::View::index_entry($mime, $state));
+		$fh->write(PublicInbox::View::index_entry($mime, $state, 1));
 		1;
 	});
 	$last;
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 488822e..8771d5d 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -169,6 +169,7 @@ sub mset_thread {
 	}
 	my $skel = search_nav_bot($mset, $q). "<pre>";
 	my $inbox = $ctx->{-inbox};
+	$ctx->{-upfx} = '';
 	my $state = {
 		-inbox => $inbox,
 		anchor_idx => 1,
@@ -181,7 +182,6 @@ sub mset_thread {
 		prev_level => 0,
 		seen => {},
 		srch => $ctx->{srch},
-		upfx => './',
 	};
 
 	PublicInbox::View::walk_thread($th, $state,
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index a774feb..eac541d 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -97,7 +97,7 @@ sub nr_to_s ($$$) {
 
 # this is already inside a <pre>
 sub index_entry {
-	my ($mime, $state) = @_;
+	my ($mime, $state, $more) = @_;
 	my $ctx = $state->{ctx};
 	my $srch = $ctx->{srch};
 	my $hdr = $mime->header_obj;
@@ -109,51 +109,76 @@ sub index_entry {
 	my $mid = PublicInbox::Hval->new_msgid($mid_raw);
 
 	my $root_anchor = $state->{root_anchor} || '';
-	my $path = $root_anchor ? '../../' : '';
-	my $href = $mid->as_href;
 	my $irt = in_reply_to($hdr);
 
-	$subj = '<b>'.ascii_html($subj).'</b>';
-	$subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id_m;
-
-	my $ts = _msg_date($hdr);
-	my $rv = "<a\nhref=#e$id\nid=$id_m>#</a> ";
-	$rv .= $subj;
-	my $mhref = $path.$href.'/';
-	my $from = _hdr_names($hdr, 'From');
-	$rv .= "\n- $from @ $ts UTC\n";
+	my $rv = '<b>'.ascii_html($subj).'</b>';
+	$rv = "<u\nid=u>$rv</u>" if $root_anchor eq $id_m;
+	$rv .= "\n";
+	$rv .= _th_index_lite($mid_raw, $irt, $id, $state);
 	my @tocc;
 	foreach my $f (qw(To Cc)) {
 		my $dst = _hdr_names($hdr, $f);
 		push @tocc, "$f: $dst" if $dst ne '';
 	}
+	$rv .= "From: "._hdr_names($hdr, 'From').' @ '._msg_date($hdr)." UTC\n";
 	$rv .= '  '.join('; +', @tocc) . "\n" if @tocc;
 	$rv .= "\n";
 
 	# scan through all parts, looking for displayable text
+	my $href = $mid->as_href;
+	my $mhref = $ctx->{-upfx}.$href.'/';
 	msg_iter($mime, sub { $rv .= add_text_body($mhref, $_[0]) });
-	$rv .= "\n<a\nhref=\"$mhref\"\n>permalink</a>" .
-		" / <a\nhref=\"${mhref}raw\">raw</a> / ";
-	my $mapping = $state->{mapping};
-	my $nr_c = $mapping->{$mid_raw} || 0;
+
+	# add the footer
+	$rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
+		"<a\nhref=\"$mhref\">permalink</a>" .
+		" / <a\nhref=\"${mhref}raw\">raw</a>" .
+		" / <a\nhref=\"${mhref}#R\">reply</a>";
+	if (my $pct = $state->{pct}) { # used by SearchView.pm
+		$rv .= " [relevance $pct->{$mid_raw}%]";
+	}
+	$rv .= $more ? "\n\n" : "\n";
+}
+
+sub _th_index_lite {
+	my ($mid_raw, $irt, $id, $state) = @_;
+	my $rv = '';
+	my $mapping = $state->{mapping} or return $rv;
+	my $pad = '  ';
+	# map = [children, attr, node, idx, level]
+	my $map = $mapping->{$mid_raw};
+	my $nr_c = scalar @{$map->[0]};
 	my $nr_s = 0;
 	if (defined $irt) {
-		$nr_s = ($mapping->{$irt} || 0) - 1;
+		my $irt_map = $mapping->{$irt};
+		my $siblings = $irt_map->[0];
+		$nr_s = scalar(@$siblings) - 1;
 		$nr_s = 0 if $nr_s < 0;
-		$irt = anchor_for($irt);
-		$rv .= "<a\nhref=#$irt>#parent</a>,";
-	} else {
-		$rv .= 'root message:';
+		$rv .= $pad . $irt_map->[1];
+		my $idx = $map->[3];
+		if ($idx > 0) {
+			my $prev = $siblings->[$idx - 1];
+			$rv .= $pad . $mapping->{$prev->messageid}->[1];
+		}
 	}
-	$nr_s = nr_to_s($nr_s, 'sibling', 'siblings');
-	$nr_c = nr_to_s($nr_c, 'reply', 'replies');
-	$rv .= " <a\nhref=#r$id\nid=e$id>$nr_s, $nr_c</a>";
-	$rv .= " / <a\nhref=\"${mhref}#R\">reply</a>";
-
-	if (my $pct = $state->{pct}) { # used by SearchView.pm
-		$rv .= " [relevance $pct->{$mid_raw}%]";
+	my $s_s = nr_to_s($nr_s, 'sibling', 'siblings');
+	my $s_c = nr_to_s($nr_c, 'reply', 'replies');
+	my $this = $map->[1];
+	$this =~ s!\n\z!</b>\n!s;
+	$this =~ s!<a\nhref.*a> !!s; # no point in duplicating subject
+	$rv .= "<b>@ $this";
+	my $node = $map->[2];
+	if (my $child = $node->child) {
+		$rv .= $pad . $mapping->{$child->messageid}->[1];
+	}
+	if (my $next = $node->next) {
+		$rv .= $pad .  $mapping->{$next->messageid}->[1];
 	}
-	$rv .= "\n\n";
+	$rv .= "<a\nhref=#e$id\nid=m$id>.<a>\t\t\t";
+	$rv .= "(<a\nhref=#r$id\n>$s_s, $s_c</a> / ";
+	my $upfx = $state->{ctx}->{-upfx};
+	$rv .= qq{<a\nhref="$upfx$mid_raw/">permalink</a> / };
+	$rv .= qq{<a\nhref="$upfx$mid_raw/raw">raw</a>)\n};
 }
 
 sub walk_thread {
@@ -169,13 +194,14 @@ sub walk_thread {
 
 sub pre_thread  {
 	my ($state, $level, $node) = @_;
-	my $parent = $node->parent;
-	if ($parent) {
-		my $mid = $parent->messageid;
-		my $m = $state->{mapping};
-		$m->{$mid} ||= 0;
-		$m->{$mid}++;
+	my $mapping = $state->{mapping};
+	my $idx = -1;
+	if (my $parent = $node->parent) {
+		my $m = $mapping->{$parent->messageid}->[0];
+		$idx = scalar @$m;
+		push @$m, $node;
 	}
+	$mapping->{$node->messageid} = [ [], '', $node, $idx ];
 	skel_dump($state, $level, $node);
 }
 
@@ -196,13 +222,12 @@ sub thread_html {
 		ctx => $ctx,
 		cur_level => 0,
 		dst => \$skel,
-		mapping => {}, # mid -> reply count
+		mapping => {}, # mid -> [ reply count, from@date, node ];
 		prev_attr => '',
 		prev_level => 0,
 		root_anchor => anchor_for($mid),
 		seen => {},
 		srch => $ctx->{srch},
-		upfx => '../../',
 	};
 
 	walk_thread(thread_results($msgs), $state, *pre_thread);
@@ -216,7 +241,7 @@ sub thread_html {
 	$mime = Email::MIME->new($mime);
 	$ctx->{-upfx} = '../../';
 	$ctx->{-title_html} = ascii_html($mime->header('Subject'));
-	$ctx->{-html_tip} = '<pre>'.index_entry($mime, $state);
+	$ctx->{-html_tip} = '<pre>'.index_entry($mime, $state, scalar @$msgs);
 	$mime = undef;
 	my $body = PublicInbox::WwwStream->new($ctx, sub {
 		return unless $msgs;
@@ -224,9 +249,12 @@ sub thread_html {
 			$mid = mid_clean(mid_mime($mime));
 			$mime = $inbox->msg_by_mid($mid) and last;
 		}
-		return index_entry(Email::MIME->new($mime), $state) if $mime;
+		if ($mime) {
+			$mime = Email::MIME->new($mime);
+			return index_entry($mime, $state, scalar @$msgs);
+		}
 		$msgs = undef;
-		$skel .= "</pre>";
+		$skel .= '</pre>';
 	});
 	[ 200, ['Content-Type', 'text/html; charset=UTF-8'], $body ];
 }
@@ -405,7 +433,6 @@ sub thread_skel {
 		cur => $mid,
 		prev_attr => '',
 		prev_level => 0,
-		upfx => "$tpfx../",
 		dst => $dst,
 	};
 	walk_thread(thread_results(load_results($sres)), $state, *skel_dump);
@@ -598,8 +625,7 @@ sub _skel_header {
 	my $cur = $state->{cur};
 	my $mid = mid_clean($hdr->header_raw('Message-ID'));
 	my $f = ascii_html($hdr->header('X-PI-From'));
-	my $d = _msg_date($hdr);
-	my $pfx = "$d " . indent_for($level) . th_pfx($level);
+	my $d = _msg_date($hdr) . ' ' . indent_for($level) . th_pfx($level);
 	my $attr = $f;
 	$state->{first_level} ||= $level;
 
@@ -613,9 +639,9 @@ sub _skel_header {
 	if ($cur) {
 		if ($cur eq $mid) {
 			delete $state->{cur};
-			$$dst .= "$pfx<b><a\nid=r\nhref=\"#t\">".
+			$$dst .= $d;
+			$$dst .= "<b><a\nid=r\nhref=\"#t\">".
 				 "$attr [this message]</a></b>\n";
-
 			return;
 		}
 	} else {
@@ -636,15 +662,18 @@ sub _skel_header {
 	}
 	my $m = PublicInbox::Hval->new_msgid($mid);
 	my $id = '';
-	if ($state->{mapping}) {
+	my $mapping = $state->{mapping};
+	my $end = defined($s) ? "$s</a> $f\n" : "$f</a>\n";
+	if ($mapping) {
+		my $map = $mapping->{$mid};
 		$id = id_compress($mid, 1);
 		$m = '#m'.$id;
+		$map->[1] = "$d<a\nhref=\"$m\">$end";
 		$id = "\nid=r".$id;
 	} else {
-		$m = $state->{upfx}.$m->as_href.'/';
+		$m = $state->{ctx}->{-upfx}.$m->as_href.'/';
 	}
-	$$dst .= "$pfx<a\nhref=\"$m\"$id>";
-	$$dst .= defined($s) ? "$s</a> $f\n" : "$f</a>\n";
+	$$dst .=  $d . "<a\nhref=\"$m\"$id>" . $end;
 }
 
 sub skel_dump {
@@ -654,25 +683,30 @@ sub skel_dump {
 	} else {
 		my $mid = $node->messageid;
 		my $dst = $state->{dst};
+		my $mapping = $state->{mapping};
+		my $map = $mapping->{$mid} if $mapping;
 		if ($mid eq 'subject dummy') {
-			$$dst .= "\t[no common parent]\n";
+			my $ncp = "\t[no common parent]\n";
+			$map->[1] = $ncp if $map;
+			$$dst .= $ncp;
 			return;
 		}
-		if ($state->{pct}) { # search result
-			$$dst .= '    [irrelevant] ';
+		my $d = $state->{pct} ? '    [irrelevant] ' # search result
+				      : '     [not found] ';
+		$d .= indent_for($level) . th_pfx($level);
+		my $upfx = $state->{ctx}->{-upfx};
+		my $m = PublicInbox::Hval->new_msgid($mid);
+		my $href = $upfx . $m->as_href . '/';
+		my $html = $m->as_html;
+
+		if ($map) {
+			my $id = id_compress($mid, 1);
+			$map->[1] = $d . qq{&lt;<a\nhref=#r$id>$html</a>&gt;\n};
+			$d .= qq{&lt;<a\nhref="$href"\nid=r$id>$html</a>&gt;\n};
 		} else {
-			$$dst .= '     [not found] ';
-		}
-		$$dst .= indent_for($level) . th_pfx($level);
-		my $upfx = $state->{upfx};
-		my $id = '';
-		if ($state->{mapping}) { # thread index view
-			$id = "\nid=".anchor_for($mid);
+			$d .= qq{&lt;<a\nhref="$href">$html</a>&gt;\n};
 		}
-		$mid = PublicInbox::Hval->new_msgid($mid);
-		my $href = $upfx . $mid->as_href . '/';
-		my $html = $mid->as_html;
-		$$dst .= qq{&lt;<a\nhref="$href"$id>$html</a>&gt;\n};
+		$$dst .= $d;
 	}
 }
 
-- 
EW


^ permalink raw reply related	[relevance 4%]

* [PATCH 0/13] www: hybrid flat+thread conversation view
@ 2016-06-30  9:21  7% Eric Wong
  2016-06-30  9:21  4% ` [PATCH 03/13] view: show thread context in the thread-aware flat view Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-06-30  9:21 UTC (permalink / raw)
  To: meta

I've been long-dreaming of this and finally it's at least
publishable (I hope :x).  This flat view with thread skeletons
is 100% more usable than the dumb old one, but a little slower
(naturally :<)

I was originally hoping to remove the threaded /t/ endpoint
conversation view entirely to reduce server/caching overheads
but I still find it more usable in some situations.

What I still enjoy is being able to toggle between
[flat|threaded] views.

Eric Wong (13):
      www: implement hybrid flat+thread conversation view
      www: use WwwStream for dumping thread and search views
      view: show thread context in the thread-aware flat view
      view: merge $state hash with existing $ctx
      feed: add $INBOX/new.html endpoint
      view: tweak thread/index header slightly
      view: show more nearby messages in flat thread view
      www: reinstate old thread view as an option
      view: fix up some HTML injection via Message-ID vectors
      view: default to flat/hybrid thread display
      view: show thread size when linking to summary
      view: fixup bad reference to new_msgid
      www_stream: add response wrapper sub

 TODO                          |   2 -
 lib/PublicInbox/Feed.pm       |  51 +++-
 lib/PublicInbox/SearchView.pm | 141 +++++-----
 lib/PublicInbox/View.pm       | 590 +++++++++++++++++++++++-------------------
 lib/PublicInbox/WWW.pm        |  22 +-
 lib/PublicInbox/WwwStream.pm  |  20 +-
 t/view.t                      |   3 +-
 7 files changed, 464 insertions(+), 365 deletions(-)


^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-30  9:21  7% [PATCH 0/13] www: hybrid flat+thread conversation view Eric Wong
2016-06-30  9:21  4% ` [PATCH 03/13] view: show thread context in the thread-aware flat view Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).