dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] wip
Date: Sun, 26 Jun 2016 03:46:25 +0000	[thread overview]
Message-ID: <20160626034625.10938-1-e@80x24.org> (raw)

From: Eric Wong <normalperson@yhbt.net>

---
 lib/PublicInbox/View.pm | 164 +++++++++++++-----------------------------------
 1 file changed, 44 insertions(+), 120 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 38e35bf..58361db 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -92,7 +92,7 @@ sub _hdr_names ($$) {
 # this is already inside a <pre>
 sub index_entry {
 	my ($mime, $level, $state) = @_;
-	my $midx = $state->{anchor_idx}++;
+	$state->{anchor_idx}++;
 	my $ctx = $state->{ctx};
 	my $srch = $ctx->{srch};
 	my $hdr = $mime->header_obj;
@@ -100,28 +100,25 @@ sub index_entry {
 
 	my $mid_raw = mid_clean(mid_mime($mime));
 	my $id = anchor_for($mid_raw);
-	my $seen = $state->{seen};
-	$seen->{$id} = "#$id"; # save the anchor for children, later
-
 	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);
-	my $parent_anchor = $seen->{anchor_for($irt)} if defined $irt;
 
-	$subj = ascii_html($subj);
-	$subj = "<a\nhref=\"${path}$href/\">$subj</a>";
+	$subj = '<b>'.ascii_html($subj).'</b>';
 	$subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id;
 
 	my $ts = _msg_date($hdr);
-	my $rv = "<pre\nid=s$midx>";
+	my $rv = "<pre\nid=$id>";
 	$rv .= "<b\nid=$id>$subj</b>\n";
-	my $txt = "${path}$href/raw";
+	my $mhref = $path.$href.'/';
 	my $fh = $state->{fh};
 	my $from = _hdr_names($hdr, 'From');
-	$rv .= "- $from @ $ts UTC (<a\nhref=\"$txt\">raw</a>)\n";
+	$rv .= "- $from @ $ts UTC (";
+	$rv .= "<a\nhref=\"${mhref}\">permalink</a> ";
+	$rv .= "/ <a\nhref=\"${mhref}raw\">raw</a>)\n";
 	my @tocc;
 	foreach my $f (qw(To Cc)) {
 		my $dst = _hdr_names($hdr, $f);
@@ -130,36 +127,19 @@ sub index_entry {
 	$rv .= '  '.join('; +', @tocc) . "\n" if @tocc;
 	$fh->write($rv .= "\n");
 
-	my $mhref = "${path}$href/";
 
 	# scan through all parts, looking for displayable text
 	msg_iter($mime, sub { index_walk($fh, $mhref, $_[0]) });
-	$rv = "\n" . html_footer($hdr, 0, $ctx, "$path$href/#R");
+	$rv = "\n" . html_footer($hdr, 0, $ctx, $mhref.'#R');
 
 	if (defined $irt) {
-		unless (defined $parent_anchor) {
-			my $v = PublicInbox::Hval->new_msgid($irt, 1);
-			$v = $v->as_href;
-			$parent_anchor = "${path}$v/";
-		}
-		$rv .= " <a\nhref=\"$parent_anchor\">parent</a>";
+		$irt = anchor_for($irt);
+		$rv .= " <a\nhref=#$irt>parent</a>";
 	}
 	if (my $pct = $state->{pct}) { # used by SearchView.pm
 		$rv .= " [relevance $pct->{$mid_raw}%]";
-	} elsif ($srch) {
-		my $threaded = 'threaded';
-		my $flat = 'flat';
-		my $end = '';
-		if ($ctx->{flat}) {
-			$flat = "<b>$flat</b>";
-			$end = "\n"; # for lynx
-		} else {
-			$threaded = "<b>$threaded</b>";
-		}
-		$rv .= " [<a\nhref=\"${path}$href/t/#u\">$threaded</a>";
-		$rv .= "|<a\nhref=\"${path}$href/T/#u\">$flat</a>]$end";
 	}
-	$fh->write($rv .= '</pre>');
+	$fh->write($rv .= "\n</pre>"); # '\n' for lynx
 }
 
 sub thread_html {
@@ -180,48 +160,47 @@ sub walk_thread {
 }
 
 # only private functions below.
+#
+sub pre_thread  {
+	my ($state, $level, $node) = @_;
+	$state->{mapping}->{$node->messageid} = $node;
+	skel_dump($state, $level, $node);
+}
 
 sub emit_thread_html {
 	my ($res, $ctx, $foot, $srch) = @_;
 	my $mid = $ctx->{mid};
-	my $flat = $ctx->{flat};
-	my $msgs = load_results($srch->get_thread($mid, { asc => $flat }));
+	my $msgs = load_results($srch->get_thread($mid, {asc => 1}));
 	my $nr = scalar @$msgs;
 	return missing_thread($res, $ctx) if $nr == 0;
-	my $seen = {};
+	my $skel = '';
 	my $state = {
+		seen => {},
 		res => $res,
 		ctx => $ctx,
-		seen => $seen,
+		srch => $ctx->{srch},
 		root_anchor => anchor_for($mid),
 		anchor_idx => 0,
 		cur_level => 0,
+		mapping => {}, # mid -> node
+		dst => \$skel,
 	};
 
-	require PublicInbox::Git;
-	$ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
-	if ($flat) {
-		pre_anchor_entry($seen, $_) for (@$msgs);
-		__thread_entry($state, $_, 0) for (@$msgs);
-	} else {
-		walk_thread(thread_results($msgs), $state, *thread_entry);
-		if (my $max = $state->{cur_level}) {
-			$state->{fh}->write(
-				('</ul></li>' x ($max - 1)) . '</ul>');
-		}
-	}
+	walk_thread(thread_results($msgs), $state, *pre_thread);
+
+	__thread_entry($state, $_, 0) for @$msgs;
 
 	# there could be a race due to a message being deleted in git
 	# but still being in the Xapian index:
 	my $fh = delete $state->{fh} or return missing_thread($res, $ctx);
 
-	my $final_anchor = $state->{anchor_idx};
-	my $next = "<a\nid=s$final_anchor>";
-	$next .= $final_anchor == 1 ? 'only message in' : 'end of';
-	$next .= " thread</a>, back to <a\nhref=\"../../\">index</a>";
+	my $next = @$msgs == 1 ? 'only message in thread' : 'end of thread';
+	$next .= ", back to <a\nhref=\"../../\">index</a>";
 	$next .= "\ndownload thread: ";
 	$next .= "<a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
 	$next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
+	$next .= "\n";
+	$next .= $skel;
 	$fh->write('<hr /><pre>' . $next . "\n\n".
 			$foot .  '</pre></body></html>');
 	$fh->close;
@@ -563,12 +542,6 @@ sub thread_html_head {
 		"</head><body>");
 }
 
-sub pre_anchor_entry {
-	my ($seen, $mime) = @_;
-	my $id = anchor_for(mid_mime($mime));
-	$seen->{$id} = "#$id"; # save the anchor for children, later
-}
-
 sub ghost_parent {
 	my ($upfx, $mid) = @_;
 	# 'subject dummy' is used internally by Mail::Thread
@@ -580,36 +553,9 @@ sub ghost_parent {
 	qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub thread_adj_level {
-	my ($state, $level) = @_;
-
-	my $max = $state->{cur_level};
-	if ($level <= 0) {
-		return '' if $max == 0; # flat output
-
-		# reset existing lists
-		my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
-		$state->{fh}->write($x . '</ul>');
-		$state->{cur_level} = 0;
-		return '';
-	}
-	if ($level == $max) { # continue existing list
-		$state->{fh}->write('<li>');
-	} elsif ($level < $max) {
-		my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
-		$state->{fh}->write($x .= '<li>');
-		$state->{cur_level} = $level;
-	} else { # ($level > $max) # start a new level
-		$state->{cur_level} = $level;
-		$state->{fh}->write(($max ? '<li>' : '') . '<ul><li>');
-	}
-	'</li>';
-}
-
 sub ghost_flush {
-	my ($state, $upfx, $mid, $level) = @_;
-	my $end = '<pre>'. ghost_parent($upfx, $mid) . '</pre>';
-	$state->{fh}->write($end .= thread_adj_level($state, $level));
+	my ($state, $upfx, $mid) = @_;
+	$state->{fh}->write('<pre>'. ghost_parent($upfx, $mid) . '</pre>');
 }
 
 sub __thread_entry {
@@ -623,16 +569,7 @@ sub __thread_entry {
 	$mime = Email::MIME->new($mime);
 
 	thread_html_head($mime, $state) if $state->{anchor_idx} == 0;
-	if (my $ghost = delete $state->{ghost}) {
-		# n.b. ghost messages may only be parents, not children
-		foreach my $g (@$ghost) {
-			ghost_flush($state, '../../', @$g);
-		}
-	}
-	my $end = thread_adj_level($state, $level);
 	index_entry($mime, $level, $state);
-	$state->{fh}->write($end) if $end;
-
 	1;
 }
 
@@ -641,23 +578,6 @@ sub indent_for {
 	INDENT x ($level - 1);
 }
 
-sub __ghost_prepare {
-	my ($state, $node, $level) = @_;
-	my $ghost = $state->{ghost} ||= [];
-	push @$ghost, [ $node->messageid, $level ];
-}
-
-sub thread_entry {
-	my ($state, $level, $node) = @_;
-	if (my $mime = $node->message) {
-		unless (__thread_entry($state, $mime, $level)) {
-			__ghost_prepare($state, $node, $level);
-		}
-	} else {
-		__ghost_prepare($state, $node, $level);
-	}
-}
-
 sub load_results {
 	my ($sres) = @_;
 
@@ -738,7 +658,8 @@ sub _skel_header {
 		$s = $s->as_html;
 	}
 	my $m = PublicInbox::Hval->new_msgid($mid);
-	$m = $state->{upfx} . $m->as_href . '/';
+	my $upfx = $state->{upfx};
+	$m = defined $upfx ? $upfx.$m->as_href.'/' : '#'.anchor_for($m->raw);
 	$$dst .= "$pfx<a\nhref=\"$m\">";
 	$$dst .= defined($s) ? "$s</a> $f\n" : "$f</a>\n";
 }
@@ -754,14 +675,17 @@ sub skel_dump {
 		my $dst = $state->{dst};
 		if ($mid eq 'subject dummy') {
 			$$dst .= "\t[no common parent]\n";
-		} else {
-			$$dst .= '     [not found] ';
-			$$dst .= indent_for($level) . th_pfx($level);
-			$mid = PublicInbox::Hval->new_msgid($mid);
-			my $href = $state->{upfx} . $mid->as_href . '/';
-			my $html = $mid->as_html;
-			$$dst .= qq{&lt;<a\nhref="$href">$html</a>&gt;\n};
+			return;
 		}
+		$$dst .= '     [not found] ';
+		$$dst .= indent_for($level) . th_pfx($level);
+		$mid = PublicInbox::Hval->new_msgid($mid);
+		my $href;
+		my $upfx = $state->{upfx};
+		$upfx = '../../' unless defined $upfx; # thread index view
+		my $href = $upfx . $mid->as_href . '/';
+		my $html = $mid->as_html;
+		$$dst .= qq{&lt;<a\nhref="$href">$html</a>&gt;\n};
 	}
 }
 
-- 
EW


             reply	other threads:[~2016-06-26  3:46 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-26  3:46 Eric Wong [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-10-27 20:16 [PATCH] wip Eric Wong
2021-06-05 19:58 Eric Wong
2021-04-05  7:42 Eric Wong
2021-03-08  7:11 Eric Wong
2021-01-21  4:24 [PATCH] WIP Eric Wong
2021-01-03 22:57 [PATCH] wip Eric Wong
2020-12-27 11:36 [PATCH] WIP Eric Wong
2020-11-15  7:35 [PATCH] wip Eric Wong
2020-04-23  4:27 Eric Wong
2020-04-20  7:14 Eric Wong
2020-01-13  9:24 [PATCH] WIP Eric Wong
2019-05-11 22:55 Eric Wong
2019-01-02  9:21 [PATCH] wip Eric Wong
2018-07-06 21:31 Eric Wong
2018-06-24 11:55 Eric Wong
2018-06-24  8:39 Eric Wong
2017-07-15  1:42 [PATCH] WIP Eric Wong
2017-04-12 20:17 [PATCH] wip Eric Wong
2017-04-05 18:40 Eric Wong
2016-08-23 20:07 Eric Wong
2016-08-18  2:16 Eric Wong
2015-12-22  0:15 Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160626034625.10938-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).