Differential D19373 Diff 46338 src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Show First 20 Lines • Show All 2,963 Lines • ▼ Show 20 Lines | /* -( Sending Mail )------------------------------------------------------- */ | ||||
* @task mail | * @task mail | ||||
*/ | */ | ||||
protected function addHeadersAndCommentsToMailBody( | protected function addHeadersAndCommentsToMailBody( | ||||
PhabricatorMetaMTAMailBody $body, | PhabricatorMetaMTAMailBody $body, | ||||
array $xactions, | array $xactions, | ||||
$object_label = null, | $object_label = null, | ||||
$object_href = null) { | $object_href = null) { | ||||
// First, remove transactions which shouldn't be rendered in mail. | |||||
foreach ($xactions as $key => $xaction) { | |||||
if ($xaction->shouldHideForMail($xactions)) { | |||||
unset($xactions[$key]); | |||||
} | |||||
} | |||||
$headers = array(); | $headers = array(); | ||||
$headers_html = array(); | $headers_html = array(); | ||||
$comments = array(); | $comments = array(); | ||||
$details = array(); | $details = array(); | ||||
$seen_comment = false; | |||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
if ($xaction->shouldHideForMail($xactions)) { | |||||
continue; | // Most mail has zero or one comments. In these cases, we render the | ||||
// "alice added a comment." transaction in the header, like a normal | |||||
// transaction. | |||||
// Some mail, like Differential undraft mail or "!history" mail, may | |||||
// have two or more comments. In these cases, we'll put the first | |||||
// "alice added a comment." transaction in the header normally, but | |||||
// move the other transactions down so they provide context above the | |||||
// actual comment. | |||||
$comment = $xaction->getBodyForMail(); | |||||
if ($comment !== null) { | |||||
$is_comment = true; | |||||
$comments[] = array( | |||||
'xaction' => $xaction, | |||||
'comment' => $comment, | |||||
'initial' => !$seen_comment, | |||||
); | |||||
} else { | |||||
$is_comment = false; | |||||
} | } | ||||
if (!$is_comment || !$seen_comment) { | |||||
$header = $xaction->getTitleForMail(); | $header = $xaction->getTitleForMail(); | ||||
if ($header !== null) { | if ($header !== null) { | ||||
$headers[] = $header; | $headers[] = $header; | ||||
} | } | ||||
$header_html = $xaction->getTitleForHTMLMail(); | $header_html = $xaction->getTitleForHTMLMail(); | ||||
if ($header_html !== null) { | if ($header_html !== null) { | ||||
$headers_html[] = $header_html; | $headers_html[] = $header_html; | ||||
} | } | ||||
$comment = $xaction->getBodyForMail(); | |||||
if ($comment !== null) { | |||||
$comments[] = $comment; | |||||
} | } | ||||
if ($xaction->hasChangeDetailsForMail()) { | if ($xaction->hasChangeDetailsForMail()) { | ||||
$details[] = $xaction; | $details[] = $xaction; | ||||
} | } | ||||
if ($is_comment) { | |||||
$seen_comment = true; | |||||
} | |||||
} | } | ||||
$headers_text = implode("\n", $headers); | $headers_text = implode("\n", $headers); | ||||
$body->addRawPlaintextSection($headers_text); | $body->addRawPlaintextSection($headers_text); | ||||
$headers_html = phutil_implode_html(phutil_tag('br'), $headers_html); | $headers_html = phutil_implode_html(phutil_tag('br'), $headers_html); | ||||
$header_button = null; | $header_button = null; | ||||
Show All 16 Lines | if ($object_label !== null) { | ||||
'a', | 'a', | ||||
array( | array( | ||||
'style' => implode(' ', $button_style), | 'style' => implode(' ', $button_style), | ||||
'href' => $object_href, | 'href' => $object_href, | ||||
), | ), | ||||
$object_label); | $object_label); | ||||
} | } | ||||
$xactions_style = array( | $xactions_style = array(); | ||||
); | |||||
$header_action = phutil_tag( | $header_action = phutil_tag( | ||||
'td', | 'td', | ||||
array(), | array(), | ||||
$header_button); | $header_button); | ||||
$header_action = phutil_tag( | $header_action = phutil_tag( | ||||
'td', | 'td', | ||||
Show All 10 Lines | protected function addHeadersAndCommentsToMailBody( | ||||
$headers_html = phutil_tag( | $headers_html = phutil_tag( | ||||
'table', | 'table', | ||||
array(), | array(), | ||||
phutil_tag('tr', array(), array($header_action, $header_button))); | phutil_tag('tr', array(), array($header_action, $header_button))); | ||||
$body->addRawHTMLSection($headers_html); | $body->addRawHTMLSection($headers_html); | ||||
foreach ($comments as $comment) { | foreach ($comments as $spec) { | ||||
$xaction = $spec['xaction']; | |||||
$comment = $spec['comment']; | |||||
$is_initial = $spec['initial']; | |||||
// If this is not the first comment in the mail, add the header showing | |||||
// who wrote the comment immediately above the comment. | |||||
if (!$is_initial) { | |||||
$header = $xaction->getTitleForMail(); | |||||
if ($header !== null) { | |||||
$body->addRawPlaintextSection($header); | |||||
} | |||||
$header_html = $xaction->getTitleForHTMLMail(); | |||||
if ($header_html !== null) { | |||||
$body->addRawHTMLSection($header_html); | |||||
} | |||||
} | |||||
$body->addRemarkupSection(null, $comment); | $body->addRemarkupSection(null, $comment); | ||||
} | } | ||||
foreach ($details as $xaction) { | foreach ($details as $xaction) { | ||||
$details = $xaction->renderChangeDetailsForMail($body->getViewer()); | $details = $xaction->renderChangeDetailsForMail($body->getViewer()); | ||||
if ($details !== null) { | if ($details !== null) { | ||||
$label = $this->getMailDiffSectionHeader($xaction); | $label = $this->getMailDiffSectionHeader($xaction); | ||||
$body->addHTMLSection($label, $details); | $body->addHTMLSection($label, $details); | ||||
▲ Show 20 Lines • Show All 1,326 Lines • Show Last 20 Lines |