@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

When mail (like "!history" mail) has multiple comments, label them separately

Summary:
Depends on D19372. Ref T13124. See PHI505. Currently, if you `!history` a task with a lot of comments, you get output like this:

> alice added a comment.
> bailey added a comment.
> alice added a comment.
> alice added a comment.
>
> AAAA
>
> BBBB
>
> AAAA
>
> AAAA

This is impossible to read. Put the "alice added a comment." headers above the actual comments for comments after the first.

These types of mail messages are unusual, but occur in several cases:

- The new `!history` command.
- Multiple comments on a draft revision before it promotes out of draft.
- (Probably?) Conduit API updates which submit multiple comment transactions for some reason.

Test Plan: Used `bin/mail receive-test` to send a `!history` command to a task, saw a much more readable rendering of the transaction log in the resulting email.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13124

Differential Revision: https://secure.phabricator.com/D19373

+60 -15
+60 -15
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 2969 2969 $object_label = null, 2970 2970 $object_href = null) { 2971 2971 2972 + // First, remove transactions which shouldn't be rendered in mail. 2973 + foreach ($xactions as $key => $xaction) { 2974 + if ($xaction->shouldHideForMail($xactions)) { 2975 + unset($xactions[$key]); 2976 + } 2977 + } 2978 + 2972 2979 $headers = array(); 2973 2980 $headers_html = array(); 2974 2981 $comments = array(); 2975 2982 $details = array(); 2976 2983 2984 + $seen_comment = false; 2977 2985 foreach ($xactions as $xaction) { 2978 - if ($xaction->shouldHideForMail($xactions)) { 2979 - continue; 2980 - } 2981 2986 2982 - $header = $xaction->getTitleForMail(); 2983 - if ($header !== null) { 2984 - $headers[] = $header; 2985 - } 2987 + // Most mail has zero or one comments. In these cases, we render the 2988 + // "alice added a comment." transaction in the header, like a normal 2989 + // transaction. 2986 2990 2987 - $header_html = $xaction->getTitleForHTMLMail(); 2988 - if ($header_html !== null) { 2989 - $headers_html[] = $header_html; 2990 - } 2991 + // Some mail, like Differential undraft mail or "!history" mail, may 2992 + // have two or more comments. In these cases, we'll put the first 2993 + // "alice added a comment." transaction in the header normally, but 2994 + // move the other transactions down so they provide context above the 2995 + // actual comment. 2991 2996 2992 2997 $comment = $xaction->getBodyForMail(); 2993 2998 if ($comment !== null) { 2994 - $comments[] = $comment; 2999 + $is_comment = true; 3000 + $comments[] = array( 3001 + 'xaction' => $xaction, 3002 + 'comment' => $comment, 3003 + 'initial' => !$seen_comment, 3004 + ); 3005 + } else { 3006 + $is_comment = false; 3007 + } 3008 + 3009 + if (!$is_comment || !$seen_comment) { 3010 + $header = $xaction->getTitleForMail(); 3011 + if ($header !== null) { 3012 + $headers[] = $header; 3013 + } 3014 + 3015 + $header_html = $xaction->getTitleForHTMLMail(); 3016 + if ($header_html !== null) { 3017 + $headers_html[] = $header_html; 3018 + } 2995 3019 } 2996 3020 2997 3021 if ($xaction->hasChangeDetailsForMail()) { 2998 3022 $details[] = $xaction; 2999 3023 } 3024 + 3025 + if ($is_comment) { 3026 + $seen_comment = true; 3027 + } 3000 3028 } 3001 3029 3002 3030 $headers_text = implode("\n", $headers); ··· 3029 3057 $object_label); 3030 3058 } 3031 3059 3032 - $xactions_style = array( 3033 - ); 3060 + $xactions_style = array(); 3034 3061 3035 3062 $header_action = phutil_tag( 3036 3063 'td', ··· 3057 3084 3058 3085 $body->addRawHTMLSection($headers_html); 3059 3086 3060 - foreach ($comments as $comment) { 3087 + foreach ($comments as $spec) { 3088 + $xaction = $spec['xaction']; 3089 + $comment = $spec['comment']; 3090 + $is_initial = $spec['initial']; 3091 + 3092 + // If this is not the first comment in the mail, add the header showing 3093 + // who wrote the comment immediately above the comment. 3094 + if (!$is_initial) { 3095 + $header = $xaction->getTitleForMail(); 3096 + if ($header !== null) { 3097 + $body->addRawPlaintextSection($header); 3098 + } 3099 + 3100 + $header_html = $xaction->getTitleForHTMLMail(); 3101 + if ($header_html !== null) { 3102 + $body->addRawHTMLSection($header_html); 3103 + } 3104 + } 3105 + 3061 3106 $body->addRemarkupSection(null, $comment); 3062 3107 } 3063 3108