-# accumulate recent topics if search is supported
-sub add_topic {
- my ($git, $srch, $topics, $path, $ts, $u, $subj) = @_;
- my ($order, $subjs) = @$topics;
- my $header_obj;
-
- # legacy ssoma did not set commit titles based on Subject
- $subj = $enc_utf8->decode($subj);
- if ($subj eq 'mda') {
- my $mime = do_cat_mail($git, $path) or return 0;
- $header_obj = $mime->header_obj;
- $subj = mime_header($header_obj, 'Subject');
- }
-
- $subj = $srch->subject_normalized($subj);
- if (++$subjs->{$subj} == 1) {
- unless ($header_obj) {
- my $mime = do_cat_mail($git, $path) or return 0;
- $header_obj = $mime->header_obj;
- }
- my $mid = $header_obj->header_raw('Message-ID');
- $mid = mid_compressed(mid_clean($mid));
- $u = $enc_utf8->decode($u);
- push @$order, [ $mid, $ts, $u, $subj ];
- return 1;
- }
- 0; # old topic, continue going
-}
-
-sub dump_topics {
- my ($dst, $topics) = @_;
- my ($order, $subjs) = @$topics;
- $$dst .= "\n[No recent topics]" unless (scalar @$order);
- while (defined(my $info = shift @$order)) {
- my ($mid, $ts, $u, $subj) = @$info;
- my $n = delete $subjs->{$subj};
- $mid = PublicInbox::Hval->new($mid)->as_href;
- $subj = PublicInbox::Hval->new($subj)->as_html;
- $u = PublicInbox::Hval->new($u)->as_html;
- $$dst .= "\n<a\nhref=\"t/$mid.html#u\"><b>$subj</b></a>\n- ";
- $ts = POSIX::strftime('%Y-%m-%d %H:%M', gmtime($ts));
- if ($n == 1) {
- $$dst .= "created by $u @ $ts UTC\n"
- } else {
- # $n isn't the total number of posts on the topic,
- # just the number of posts in the current "git log"
- # window, so leave it unlabeled
- $$dst .= "updated by $u @ $ts UTC ($n)\n"
- }
- }
- $$dst .= '</pre>'
-}
-