user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [RFC 06/11] view: reply threading adjustment
Date: Sun, 16 Aug 2015 08:37:54 +0000	[thread overview]
Message-ID: <1439714279-21923-7-git-send-email-e@80x24.org> (raw)
In-Reply-To: <1439714279-21923-1-git-send-email-e@80x24.org>

Give changes in subject their own line to reduce line wrapping,
but avoid showing any redundant subjects by maintaining a hash
of subjects already displayed.
---
 lib/PublicInbox/View.pm | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index dcdb310..fe4f2df 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -9,6 +9,7 @@ use Encode::MIME::Header;
 use Email::MIME::ContentType qw/parse_content_type/;
 use PublicInbox::Hval;
 use PublicInbox::MID qw/mid_clean mid_compressed/;
+use Digest::SHA;
 require POSIX;
 
 # TODO: make these constants tunable
@@ -393,37 +394,45 @@ sub anchor_for {
 
 sub simple_dump {
 	my ($dst, $root, $node, $level) = @_;
-	$$dst .= '  ' x $level;
+	my $pfx = '  ' x $level;
+	$$dst .= $pfx;
 	if (my $x = $node->message) {
 		my $mid = $x->header('Message-ID');
 		if ($root->[0] ne $mid) {
-			my $s = clean_subj($x->header('Subject'));
-			if ($root->[1] eq $s) {
-				$s = '  ';
+			my $s = $x->header('Subject');
+			my $h = hash_subj($s);
+			if ($root->[1]->{$h}) {
+				$s = '';
 			} else {
+				$root->[1]->{$h} = 1;
 				$s = PublicInbox::Hval->new($s);
-				$s = $s->as_html . ' ';
+				$s = $s->as_html;
 			}
 			my $m = PublicInbox::Hval->new_msgid($mid);
 			my $f = PublicInbox::Hval->new($x->header('X-PI-From'));
 			my $d = PublicInbox::Hval->new($x->header('X-PI-Date'));
 			$m = $m->as_href . '.html';
 			$f = $f->as_html;
-			$d = $d->as_html;
-			$$dst .= "` <a\nhref=\"$m\">$s$f @ $d UTC</a>\n";
+			$d = $d->as_html . ' UTC';
+			if (length($s) == 0) {
+				$$dst .= "` <a\nhref=\"$m\">$f @ $d</a>\n";
+			} else {
+				$$dst .= "` <a\nhref=\"$m\">$s</a>\n" .
+				     "$pfx  by $f @ $d\n";
+			}
 		}
 	}
 	simple_dump($dst, $root, $node->child, $level + 1) if $node->child;
 	simple_dump($dst, $root, $node->next, $level) if $node->next;
 }
 
-sub clean_subj {
+sub hash_subj {
 	my ($subj) = @_;
 	$subj =~ s/\A\s+//;
 	$subj =~ s/\s+\z//;
 	$subj =~ s/^(?:re|aw):\s*//i; # remove reply prefix (aw: German)
 	$subj =~ s/\s+/ /;
-	$subj;
+	Digest::SHA::sha1($subj);
 }
 
 sub thread_replies {
@@ -435,7 +444,7 @@ sub thread_replies {
 	$th->thread;
 	$th->order(*PublicInbox::Thread::sort_ts);
 	$root = [ $root->header('Message-ID'),
-		  clean_subj($root->header('Subject')) ];
+		  { hash_subj($root->header('Subject')) => 1 } ];
 	simple_dump($dst, $root, $_, 0) for $th->rootset;
 }
 
-- 
EW


  parent reply	other threads:[~2015-08-16  8:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-16  8:37 [RFC 0/11] work-in-progress search branch updated Eric Wong
2015-08-16  8:37 ` [RFC 01/11] search: implement index_sync to fixup indexer Eric Wong
2015-08-16  8:37 ` [RFC 02/11] extract redundant Message-ID handling code Eric Wong
2015-08-16  8:37 ` [RFC 03/11] search: make search results more OO Eric Wong
2015-08-16  8:37 ` [RFC 04/11] view: display replies in per-message view Eric Wong
2015-08-16  8:37 ` [RFC 05/11] thread: common sorting code Eric Wong
2015-08-16  8:37 ` Eric Wong [this message]
2015-08-16  8:37 ` [RFC 07/11] view: hoist out index_walk function Eric Wong
2015-08-16  9:23   ` Eric Wong
2015-08-16  8:37 ` [RFC 08/11] www: /t/$MESSAGE_ID.html for threads Eric Wong
2015-08-16  8:37 ` [RFC 09/11] search: remove unnecessary xpfx export Eric Wong
2015-08-16  8:37 ` [RFC 10/11] implement /s/$SUBJECT_PATH.html lookups Eric Wong
2015-08-16  8:37 ` [RFC 11/11] SearchMsg: ensure metadata for ghost messages mid Eric Wong
2015-08-16  8:55 ` [RFC 12/11] view: deduplicate common code for loading search results 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=1439714279-21923-7-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.
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).