-# only private functions below.
-
-sub emit_thread_html {
- my ($cb, $ctx, $foot, $srch) = @_;
- my $mid = $ctx->{mid};
- my $res = $srch->get_thread($mid);
- my $msgs = load_results($res);
- my $nr = scalar @$msgs;
- return missing_thread($cb, $ctx) if $nr == 0;
- my $flat = $ctx->{flat};
- my $orig_cb = $cb;
- my $seen = {};
- my $state = {
- ctx => $ctx,
- seen => $seen,
- root_anchor => anchor_for($mid),
- anchor_idx => 0,
- };
-
- require PublicInbox::GitCatFile;
- my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
- if ($flat) {
- pre_anchor_entry($seen, $_) for (@$msgs);
- __thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs);
- } else {
- my $th = thread_results($msgs);
- thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
+sub _th_index_lite {
+ my ($mid_raw, $irt, $id, $ctx) = @_;
+ my $rv = '';
+ my $mapping = $ctx->{mapping} or return $rv;
+ my $pad = ' ';
+ my $mid_map = $mapping->{$mid_raw};
+ defined $mid_map or
+ return 'public-inbox BUG: '.ascii_html($mid_raw).' not mapped';
+ my ($attr, $node, $idx, $level) = @$mid_map;
+ my $children = $node->{children};
+ my $nr_c = scalar @$children;
+ my $nr_s = 0;
+ my $siblings;
+ if (my $smsg = $node->{smsg}) {
+ ($$irt) = (($smsg->{references} || '') =~ m/<([^>]+)>\z/);
+ }
+ my $irt_map = $mapping->{$$irt} if defined $$irt;
+ if (defined $irt_map) {
+ $siblings = $irt_map->[1]->{children};
+ $nr_s = scalar(@$siblings) - 1;
+ $rv .= $pad . $irt_map->[0];
+ if ($idx > 0) {
+ my $prev = $siblings->[$idx - 1];
+ my $pmid = $prev->{id};
+ if ($idx > 2) {
+ my $s = ($idx - 1). ' preceding siblings ...';
+ $rv .= pad_link($pmid, $level, $s);
+ } elsif ($idx == 2) {
+ my $ppmid = $siblings->[0]->{id};
+ $rv .= $pad . $mapping->{$ppmid}->[0];
+ }
+ $rv .= $pad . $mapping->{$pmid}->[0];
+ }
+ }
+ my $s_s = nr_to_s($nr_s, 'sibling', 'siblings');
+ my $s_c = nr_to_s($nr_c, 'reply', 'replies');
+ $attr =~ s!\n\z!</b>\n!s;
+ $attr =~ s!<a\nhref.*</a> !!s; # no point in duplicating subject
+ $attr =~ s!<a\nhref=[^>]+>([^<]+)</a>!$1!s; # no point linking to self
+ $rv .= "<b>@ $attr";
+ if ($nr_c) {
+ my $cmid = $children->[0]->{id};
+ $rv .= $pad . $mapping->{$cmid}->[0];
+ if ($nr_c > 2) {
+ my $s = ($nr_c - 1). ' more replies';
+ $rv .= pad_link($cmid, $level + 1, $s);
+ } elsif (my $cn = $children->[1]) {
+ $rv .= $pad . $mapping->{$cn->{id}}->[0];
+ }