]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / View.pm
index 071a20930827654fc0af9c0b0f1108d4bb5a4aa4..77b92653b739d6b51262aa3716149c32c8678d42 100644 (file)
@@ -86,6 +86,7 @@ sub msg_page {
 
 # /$INBOX/$MESSAGE_ID/#R
 sub msg_reply ($$) {
+       return "";
        my ($ctx, $hdr) = @_;
        my $se_url =
         'https://kernel.org/pub/software/scm/git/docs/git-send-email.html';
@@ -623,7 +624,8 @@ sub _msg_page_prepare {
                        return;
                }
                $ctx->{-html_tip} =
-"<pre>WARNING: multiple messages have this Message-ID\n</pre><pre>";
+qq[<pre>WARNING: multiple messages have this Message-ID (<a
+href="d/">diff</a>)</pre><pre>];
        } else {
                $ctx->{first_hdr} = $eml->header_obj;
                $ctx->{chash} = content_hash($eml) if $ctx->{smsg}; # reused MID
@@ -1018,6 +1020,8 @@ sub _skel_ghost {
        1;
 }
 
+# note: we favor Date: here because git-send-email increments it
+# to preserve [PATCH $N/$M] ordering in series (it can't control Received:)
 sub sort_ds {
        @{$_[0]} = sort {
                (eval { $a->topmost->{ds} } || 0) <=>
@@ -1039,9 +1043,10 @@ sub acc_topic { # walk_thread callback
        if ($has_blob) {
                my $subj = subject_normalized($smsg->{subject});
                $subj = '(no subject)' if $subj eq '';
+               my $ts = $smsg->{ts};
                my $ds = $smsg->{ds};
                if ($level == 0) { # new, top-level topic
-                       my $topic = [ $ds, 1, { $subj => $mid }, $subj ];
+                       my $topic = [ $ts, $ds, 1, { $subj => $mid }, $subj ];
                        $ctx->{-cur_topic} = $topic;
                        push @{$ctx->{order}}, $topic;
                        return 1;
@@ -1049,10 +1054,11 @@ sub acc_topic { # walk_thread callback
 
                # continue existing topic
                my $topic = $ctx->{-cur_topic}; # should never be undef
-               $topic->[0] = $ds if $ds > $topic->[0];
-               $topic->[1]++; # bump N+ message counter
-               my $seen = $topic->[2];
-               if (scalar(@$topic) == 3) { # parent was a ghost
+               $topic->[0] = $ts if $ts > $topic->[0];
+               $topic->[1] = $ds if $ds > $topic->[1];
+               $topic->[2]++; # bump N+ message counter
+               my $seen = $topic->[3];
+               if (scalar(@$topic) == 4) { # parent was a ghost
                        push @$topic, $subj;
                } elsif (!defined($seen->{$subj})) {
                        push @$topic, $level, $subj; # @extra messages
@@ -1060,7 +1066,7 @@ sub acc_topic { # walk_thread callback
                $seen->{$subj} = $mid; # latest for subject
        } else { # ghost message
                return 1 if $level != 0; # ignore child ghosts
-               my $topic = $ctx->{-cur_topic} = [ -666, 0, {} ];
+               my $topic = $ctx->{-cur_topic} = [ -666, -666, 0, {} ];
                push @{$ctx->{order}}, $topic;
        }
        1;
@@ -1081,7 +1087,7 @@ sub dump_topics {
        }
        # sort by recency, this allows new posts to "bump" old topics...
        foreach my $topic (sort { $b->[0] <=> $a->[0] } @$order) {
-               my ($ds, $n, $seen, $top_subj, @extra) = @$topic;
+               my ($ts, $ds, $n, $seen, $top_subj, @extra) = @$topic;
                @$topic = ();
                next unless defined $top_subj;  # ghost topic
                my $mid = delete $seen->{$top_subj};
@@ -1225,4 +1231,30 @@ sub ghost_index_entry {
                . '</pre>' . $end;
 }
 
+# /$INBOX/$MSGID/d/ endpoint
+sub diff_msg {
+       my ($ctx) = @_;
+       require PublicInbox::MailDiff;
+       my $ibx = $ctx->{ibx};
+       my $over = $ibx->over or return no_over_html($ctx);
+       my ($id, $prev);
+       my $md = bless { ctx => $ctx }, 'PublicInbox::MailDiff';
+       my $next_arg = $md->{next_arg} = [ $ctx->{mid}, \$id, \$prev ];
+       my $smsg = $md->{smsg} = $over->next_by_mid(@$next_arg) or
+               return; # undef == 404
+       $ctx->{-t_max} = $smsg->{ts};
+       $ctx->{-upfx} = '../../';
+       $ctx->{-apfx} = '//'; # fail on to_attr()
+       $ctx->{-linkify} = PublicInbox::Linkify->new;
+       my $mid = ascii_html($smsg->{mid});
+       $ctx->{-title_html} = "diff for duplicates of &lt;$mid&gt;";
+       PublicInbox::WwwStream::html_init($ctx);
+       print { $ctx->{zfh} } '<pre>diff for duplicates of &lt;<a href="../">',
+                               $mid, "</a>&gt;\n\n";
+       sub {
+               $ctx->attach($_[0]->([200, delete $ctx->{-res_hdr}]));
+               $md->begin_mail_diff;
+       };
+}
+
 1;