unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/3] view: include ghost messages in thread views
Date: Thu,  3 Sep 2015 01:57:10 +0000	[thread overview]
Message-ID: <1441245432-16378-2-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1441245432-16378-1-git-send-email-e@80x24.org>

We'll be expanding our ghost message lookup facilities, so
it makes sense to generate links to them even if they are
currently unknown.
---
 lib/PublicInbox/View.pm | 55 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 46 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index e18895f..8a02725 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -19,6 +19,7 @@ use constant MAX_INLINE_QUOTED => 12; # half an 80x24 terminal
 use constant MAX_TRUNC_LEN => 72;
 use constant PRE_WRAP => "<pre\nstyle=\"white-space:pre-wrap\">";
 use constant T_ANCHOR => '#u';
+use constant INDENT => '  ';
 
 *ascii_html = *PublicInbox::Hval::ascii_html;
 
@@ -101,7 +102,7 @@ sub index_entry {
 	my $ts = _msg_date($mime);
 	my $rv = "<table\nsummary=l$level><tr>";
 	if ($level) {
-		$rv .= '<td><pre>' . ('  ' x $level) . '</pre></td>';
+		$rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
 	}
 	$rv .= "<td\nid=s$midx>" . PRE_WRAP;
 	$rv .= "<b\nid=\"$id\">$subj</b>\n";
@@ -594,22 +595,50 @@ sub __thread_entry {
 	my ($cb, $git, $state, $mime, $level) = @_;
 
 	# lazy load the full message from mini_mime:
-	my $path = mid2path(mid_clean($mime->header('Message-ID')));
-	$mime = eval { Email::MIME->new($git->cat_file("HEAD:$path")) };
-	if ($mime) {
-		if ($state->{anchor_idx} == 0) {
-			thread_html_head($cb, $mime);
+	$mime = eval {
+		my $path = mid2path(mid_clean($mime->header('Message-ID')));
+		Email::MIME->new($git->cat_file('HEAD:'.$path));
+	} or return;
+
+	if ($state->{anchor_idx} == 0) {
+		thread_html_head($cb, $mime, $state);
+	}
+
+	if (my $ghost = delete $state->{ghost}) {
+		# n.b. ghost messages may only be parents, not children
+		foreach my $g (@$ghost) {
+			my $mid = PublicInbox::Hval->new_msgid($g->[0]);
+			my $pfx = INDENT x $g->[1];
+			my $href = $mid->as_href;
+			my $html = $mid->as_html;
+			$$cb->write("<table><tr><td>$pfx</td><td>" .
+					PRE_WRAP .
+					'[parent not found: &lt;' .
+					qq{<a\nhref="../../$href/">}.
+					"$html</a>&gt;]</pre></td></table>");
 		}
-		index_entry($$cb, $mime, $level, $state);
 	}
+	index_entry($$cb, $mime, $level, $state);
+	1;
+}
+
+sub __ghost_entry {
+	my ($state, $node, $level) = @_;
+	my $ghost = $state->{ghost} ||= [];
+	push @$ghost, [ $node->messageid, $level ];
 }
 
 sub thread_entry {
 	my ($cb, $git, $state, $node, $level) = @_;
 	return unless $node;
 	if (my $mime = $node->message) {
-		__thread_entry($cb, $git, $state, $mime, $level);
+		unless (__thread_entry($cb, $git, $state, $mime, $level)) {
+			__ghost_entry($state, $node, $level);
+		}
+	} else {
+		__ghost_entry($state, $node, $level);
 	}
+
 	thread_entry($cb, $git, $state, $node->child, $level + 1);
 	thread_entry($cb, $git, $state, $node->next, $level);
 }
@@ -651,7 +680,7 @@ sub _msg_date {
 
 sub _inline_header {
 	my ($dst, $state, $upfx, $mime, $level) = @_;
-	my $pfx = '  ' x $level;
+	my $pfx = INDENT x $level;
 
 	my $cur = $state->{cur};
 	my $mid = $mime->header('Message-ID');
@@ -705,6 +734,14 @@ sub inline_dump {
 			$state->{parent} = $mid;
 		}
 		_inline_header($dst, $state, $upfx, $mime, $level);
+	} else {
+		my $pfx = INDENT x $level;
+		my $v = PublicInbox::Hval->new_msgid($node->messageid, 1);
+		my $html = $v->as_html;
+		my $href = $v->as_href;
+		$$dst .= $pfx . '` [parent not found: &lt;' .
+				qq{<a\nhref="$upfx../$href/">}.
+				"$html</a>&gt];\n";
 	}
 	inline_dump($dst, $state, $upfx, $node->child, $level+1);
 	inline_dump($dst, $state, $upfx, $node->next, $level);
-- 
EW


  reply	other threads:[~2015-09-03  1:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-03  1:57 [PATCH 0/3] improve external Message-ID handling Eric Wong
2015-09-03  1:57 ` Eric Wong [this message]
2015-09-03  2:04   ` [PATCH 1/3] view: include ghost messages in thread views Eric Wong
2015-09-03  1:57 ` [PATCH 2/3] search: disable Message-ID compression in Xapian Eric Wong
2015-09-03  1:57 ` [PATCH 3/3] ExtMsg: 300 to external mailing list archives 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

  List information: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=1441245432-16378-2-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.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).