@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.

Add inline comment support to "Pro" comment save controller

Summary: Ref T2222. Makes the "pro" controller work with inlines.

Test Plan: Added a bunch of inlines and saved them with the "pro" controller.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

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

+91 -14
+49 -4
src/applications/differential/controller/DifferentialCommentSaveControllerPro.php
··· 86 86 ->setNewValue(array('+' => $reviewer_edges)); 87 87 } 88 88 89 + $inline_phids = $this->loadUnsubmittedInlinePHIDs($revision); 90 + if ($inline_phids) { 91 + $inlines = id(new PhabricatorApplicationTransactionCommentQuery()) 92 + ->setTemplate(new DifferentialTransactionComment()) 93 + ->setViewer($viewer) 94 + ->withPHIDs($inline_phids) 95 + ->execute(); 96 + } else { 97 + $inlines = null; 98 + } 99 + 100 + foreach ($inlines as $inline) { 101 + $xactions[] = id(new DifferentialTransaction()) 102 + ->setTransactionType($type_inline) 103 + ->attachComment($inline); 104 + } 105 + 106 + // NOTE: If there are no other transactions, add an empty comment 107 + // transaction so that we'll raise a more user-friendly error message, 108 + // to the effect of "you can not post an empty comment". 109 + $no_xactions = !$xactions; 110 + 89 111 $comment = $request->getStr('comment'); 90 - if (strlen($comment)) { 112 + if (strlen($comment) || $no_xactions) { 91 113 $xactions[] = id(new DifferentialTransaction()) 92 114 ->setTransactionType($type_comment) 93 115 ->attachComment( ··· 96 118 ->setContent($comment)); 97 119 } 98 120 99 - // TODO: Inlines! 100 121 101 122 $editor = id(new DifferentialTransactionEditor()) 102 123 ->setActor($viewer) ··· 113 134 ->setCancelURI($revision_uri) 114 135 ->setException($ex); 115 136 } 116 - 117 - // TODO: Diff change detection? 118 137 119 138 $user = $request->getUser(); 120 139 $draft = id(new PhabricatorDraft())->loadOneWhere( ··· 128 147 129 148 return id(new AphrontRedirectResponse()) 130 149 ->setURI('/D'.$revision->getID()); 150 + } 151 + 152 + 153 + private function loadUnsubmittedInlinePHIDs(DifferentialRevision $revision) { 154 + $viewer = $this->getRequest()->getUser(); 155 + 156 + // TODO: This probably needs to move somewhere more central as we move 157 + // away from DifferentialInlineCommentQuery, but 158 + // PhabricatorApplicationTransactionCommentQuery is currently `final` and 159 + // I'm not yet decided on how to approach that. For now, just get the PHIDs 160 + // and then execute a PHID-based query through the standard stack. 161 + 162 + $table = new DifferentialTransactionComment(); 163 + $conn_r = $table->establishConnection('r'); 164 + 165 + $phids = queryfx_all( 166 + $conn_r, 167 + 'SELECT phid FROM %T 168 + WHERE revisionPHID = %s 169 + AND authorPHID = %s 170 + AND transactionPHID IS NULL', 171 + $table->getTableName(), 172 + $revision->getPHID(), 173 + $viewer->getPHID()); 174 + 175 + return ipull($phids, 'phid'); 131 176 } 132 177 133 178 }
+27 -1
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 12 12 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; 13 13 14 14 $types[] = DifferentialTransaction::TYPE_ACTION; 15 + $types[] = DifferentialTransaction::TYPE_INLINE; 15 16 16 17 /* 17 18 18 - $types[] = DifferentialTransaction::TYPE_INLINE; 19 19 $types[] = DifferentialTransaction::TYPE_UPDATE; 20 20 */ 21 21 ··· 32 32 case PhabricatorTransactions::TYPE_EDIT_POLICY: 33 33 return $object->getEditPolicy(); 34 34 case DifferentialTransaction::TYPE_ACTION: 35 + return null; 36 + case DifferentialTransaction::TYPE_INLINE: 35 37 return null; 36 38 } 37 39 ··· 47 49 case PhabricatorTransactions::TYPE_EDIT_POLICY: 48 50 case DifferentialTransaction::TYPE_ACTION: 49 51 return $xaction->getNewValue(); 52 + case DifferentialTransaction::TYPE_INLINE: 53 + return null; 50 54 } 51 55 52 56 return parent::getCustomTransactionNewValue($object, $xaction); ··· 57 61 PhabricatorApplicationTransaction $xaction) { 58 62 59 63 switch ($xaction->getTransactionType()) { 64 + case DifferentialTransaction::TYPE_INLINE: 65 + return $xaction->hasComment(); 60 66 } 61 67 62 68 return parent::transactionHasEffect($object, $xaction); ··· 76 82 return; 77 83 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 78 84 case PhabricatorTransactions::TYPE_COMMENT: 85 + case DifferentialTransaction::TYPE_INLINE: 86 + return; 79 87 case PhabricatorTransactions::TYPE_EDGE: 80 88 // TODO: When removing reviewers, we may be able to move the revision 81 89 // to "Accepted". ··· 101 109 case PhabricatorTransactions::TYPE_EDGE: 102 110 case PhabricatorTransactions::TYPE_COMMENT: 103 111 case DifferentialTransaction::TYPE_ACTION: 112 + case DifferentialTransaction::TYPE_INLINE: 104 113 return; 105 114 } 106 115 ··· 118 127 } 119 128 120 129 return $errors; 130 + } 131 + 132 + protected function sortTransactions(array $xactions) { 133 + $head = array(); 134 + $tail = array(); 135 + 136 + // Move bare comments to the end, so the actions precede them. 137 + foreach ($xactions as $xaction) { 138 + $type = $xaction->getTransactionType(); 139 + if ($type == DifferentialTransaction::TYPE_INLINE) { 140 + $tail[] = $xaction; 141 + } else { 142 + $head[] = $xaction; 143 + } 144 + } 145 + 146 + return array_values(array_merge($head, $tail)); 121 147 } 122 148 123 149 protected function requireCapabilities(
+1 -6
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 1335 1335 PhabricatorLiskDAO $object, 1336 1336 PhabricatorApplicationTransaction $xaction) { 1337 1337 1338 - switch ($xaction->getTransactionType()) { 1339 - case PhabricatorTransactions::TYPE_COMMENT: 1340 - return true; 1341 - default: 1342 - return false; 1343 - } 1338 + return $xaction->isCommentTransaction(); 1344 1339 } 1345 1340 1346 1341
+14 -3
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 528 528 return 1.0; 529 529 } 530 530 531 + public function isCommentTransaction() { 532 + if ($this->hasComment()) { 533 + return true; 534 + } 535 + 536 + switch ($this->getTransactionType()) { 537 + case PhabricatorTransactions::TYPE_COMMENT: 538 + return true; 539 + } 540 + 541 + return false; 542 + } 543 + 531 544 public function getActionName() { 532 545 switch ($this->getTransactionType()) { 533 546 case PhabricatorTransactions::TYPE_COMMENT: ··· 605 618 * @return bool True to display in a group with the other transactions. 606 619 */ 607 620 public function shouldDisplayGroupWith(array $group) { 608 - $type_comment = PhabricatorTransactions::TYPE_COMMENT; 609 - 610 621 $this_source = null; 611 622 if ($this->getContentSource()) { 612 623 $this_source = $this->getContentSource()->getSource(); ··· 624 635 } 625 636 626 637 // Don't group anything into a group which already has a comment. 627 - if ($xaction->getTransactionType() == $type_comment) { 638 + if ($xaction->isCommentTransaction()) { 628 639 return false; 629 640 } 630 641