user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [REJECT 4/3] searchview: implement flat view for full message
Date: Sun, 13 Sep 2015 23:19:40 +0000	[thread overview]
Message-ID: <20150913231940.GA2161@dcvr.yhbt.net> (raw)
In-Reply-To: <20150913223751.GA22152@dcvr.yhbt.net>

Rejecting this, as it's too much clutter and options.
People who really want a flat view should use the Atom feed.
---
 lib/PublicInbox/SearchView.pm | 109 ++++++++++++++++++++++++++++--------------
 1 file changed, 72 insertions(+), 37 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index b65351a..f0c6670 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -44,7 +44,10 @@ sub sres_top_html {
 		$res .= search_nav_top($mset, $q);
 		if ($x eq 't') {
 			return sub { tdump($_[0], $res, $mset, $q, $ctx) };
+		} elsif ($x eq 'f') {
+			return sub { fdump($_[0], $res, $mset, $q, $ctx) };
 		}
+
 		$res .= "\n\n";
 		dump_mset(\$res, $mset);
 		$res .= search_nav_bot($mset, $q) . "\n\n" . foot($ctx);
@@ -96,17 +99,24 @@ sub search_nav_top {
 		$rv .= qq{<b>date</b>|<a\nhref="?$d">relevance</a>};
 	}
 
-	$rv .= ']  view[';
+	$rv .= ']  view: [';
 
 	my $x = $q->{x};
+	my $t = $q->qs_html(x => 't');
+	my $s = $q->qs_html(x => '');
+	my $f = $q->qs_html(x => 'f');
 	if ($x eq '') {
-		my $t = $q->qs_html(x => 't');
-		$rv .= qq{<b>summary</b>|};
-		$rv .= qq{<a\nhref="?$t">threaded</a>}
-	} elsif ($q->{x} eq 't') {
-		my $s = $q->qs_html(x => '');
-		$rv .= qq{<a\nhref="?$s">summary</a>|};
-		$rv .= qq{<b>threaded</b>};
+		$rv .= qq{<b>short</b>|} .
+			qq{<a\nhref="?$t">threaded</a>|} .
+			qq{<a\nhref="?$f">flat</a>};
+	} elsif ($x eq 't') {
+		$rv .= qq{<a\nhref="?$s">short</a>|} .
+			qq{<b>threaded</b>|} .
+			qq{<a\nhref="?$f">flat</a>};
+	} elsif ($x eq 'f') {
+		$rv .= qq{<a\nhref="?$s">short</a>|} .
+			qq{<a\nhref="?$t">threaded</a>|} .
+			qq{<b>flat</b>};
 	}
 	my $A = $q->qs_html(x => 'A');
 	$rv .= qq{|<a\nhref="?$A">Atom</a>};
@@ -136,8 +146,8 @@ sub search_nav_bot {
 	$rv;
 }
 
-sub tdump {
-	my ($cb, $res, $mset, $q, $ctx) = @_;
+sub dump_prepare {
+	my ($cb, $res, $mset, $ctx) = @_;
 	my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
 	$fh->write($res);
 	my %pct;
@@ -148,56 +158,81 @@ sub tdump {
 		$m = $m->mini_mime;
 		$m;
 	} ($mset->items);
+	my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
+	$ctx->{searchview} = 1;
+	require PublicInbox::GitCatFile;
+	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+	$state->{git} = $git;
+
+	($fh, \@m, $git, $state);
+}
+
+sub dump_end {
+	my ($fh, $mset, $q, $ctx) = @_;
+	Email::Address->purge_cache;
+
+	$fh->write(search_nav_bot($mset, $q). "\n\n" .
+			foot($ctx). '</pre></body></html>');
+	$fh->close;
+}
+
+sub fdump {
+	my ($cb, $res, $mset, $q, $ctx) = @_;
+	my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx);
+	mime_dump($fh, $git, $_, 0, $state) for (@$m);
+	dump_end($fh, $mset, $q, $ctx);
+}
+
+sub do_thread {
+	my ($m, $pct, $q) = @_;
 
 	require PublicInbox::Thread;
-	my $th = PublicInbox::Thread->new(@m);
+	my $th = PublicInbox::Thread->new(@$m);
 	{
 		no warnings 'once';
 		$Mail::Thread::nosubject = 0;
+		$th->thread;
 	}
-	$th->thread;
 	if ($q->{r}) {
 		$th->order(sub {
-			sort { (eval { $pct{$b->topmost->messageid} } || 0)
+			sort { (eval { $pct->{$b->topmost->messageid} } || 0)
 					<=>
-				(eval { $pct{$a->topmost->messageid} } || 0)
+				(eval { $pct->{$a->topmost->messageid} } || 0)
 			} @_;
 		});
 	} else {
 		no warnings 'once';
 		$th->order(*PublicInbox::View::rsort_ts);
 	}
+	$th;
+}
 
-	require PublicInbox::GitCatFile;
-	my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
-	my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
-	$ctx->{searchview} = 1;
+sub tdump {
+	my ($cb, $res, $mset, $q, $ctx) = @_;
+	my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx);
+	my $th = do_thread($m, $state->{pct}, $q);
 	tdump_ent($fh, $git, $state, $_, 0) for $th->rootset;
-	$git = undef;
-	Email::Address->purge_cache;
+	dump_end($fh, $mset, $q, $ctx);
+}
 
-	$fh->write(search_nav_bot($mset, $q). "\n\n" .
-			foot($ctx). '</pre></body></html>');
+sub mime_dump {
+	my ($fh, $git, $mime, $level, $state) = @_;
 
-	$fh->close;
+	# lazy load the full message from mini_mime:
+	my $mid = $mime->header('Message-ID');
+	$mime = eval {
+		my $path = mid2path(mid_clean($mid));
+		Email::MIME->new($git->cat_file('HEAD:'.$path));
+	};
+	PublicInbox::View::index_entry($fh, $mime, $level, $state) if $mime;
+	$mime;
 }
 
 sub tdump_ent {
 	my ($fh, $git, $state, $node, $level) = @_;
 	return unless $node;
-	my $mime = $node->message;
-
-	if ($mime) {
-		# lazy load the full message from mini_mime:
-		my $mid = $mime->header('Message-ID');
-		$mime = eval {
-			my $path = mid2path(mid_clean($mid));
-			Email::MIME->new($git->cat_file('HEAD:'.$path));
-		};
-	}
-	if ($mime) {
-		PublicInbox::View::index_entry($fh, $mime, $level, $state);
-	} else {
+
+	unless (mime_dump($fh, $git, $node->message, $level, $state)) {
 		my $mid = $node->messageid;
 		$fh->write(PublicInbox::View::ghost_table('', $mid, $level));
 	}
@@ -295,7 +330,7 @@ sub qs_html {
 		$qs .= "&amp;r";
 	}
 	if (my $x = $self->{x}) {
-		$qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A');
+		$qs .= "&amp;x=$x" if ($x =~ /\A(?:A|t|f)\z/);
 	}
 	$qs;
 }
-- 
EW


      reply	other threads:[~2015-09-13 23:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-13 22:35 [PATCH 1/3] feed: consolidate updated tag generation Eric Wong
2015-09-13 22:35 ` [PATCH 2/3] searchview: implement Atom feed for search results Eric Wong
2015-09-13 22:35 ` [PATCH 3/3] view: add Atom links in headers for per-message links Eric Wong
2015-09-13 22:37 ` [PATCH 0/3] expand Atom feeds to search results Eric Wong
2015-09-13 23:19   ` Eric Wong [this message]

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=20150913231940.GA2161@dcvr.yhbt.net \
    --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.
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).