From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS16276 167.114.0.0/16 X-Spam-Status: No, score=-2.2 required=3.0 tests=AWL,BAYES_00,RCVD_IN_XBL shortcircuit=no autolearn=no version=3.3.2 X-Original-To: meta@public-inbox.org Received: from 80x24.org (mars.m3l.io [167.114.185.125]) by dcvr.yhbt.net (Postfix) with ESMTP id EBFB0200EB for ; Thu, 3 Sep 2015 01:57:20 +0000 (UTC) From: Eric Wong 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 Message-Id: <1441245432-16378-2-git-send-email-e@80x24.org> In-Reply-To: <1441245432-16378-1-git-send-email-e@80x24.org> References: <1441245432-16378-1-git-send-email-e@80x24.org> List-Id: 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 => ""; 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 = ""; if ($level) { - $rv .= '
' . ('  ' x $level) . '
'; + $rv .= '
' . (INDENT x $level) . '
'; } $rv .= "" . PRE_WRAP; $rv .= "$subj\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("
$pfx" . + PRE_WRAP . + '[parent not found: <' . + qq{}. + "$html>]
"); } - 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: <' . + qq{}. + "$html>];\n"; } inline_dump($dst, $state, $upfx, $node->child, $level+1); inline_dump($dst, $state, $upfx, $node->next, $level); -- EW