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

Replace "loadUnsubmittedInlineComments()" with a modern "DiffQuery"

Summary: Ref T13513. All queries now go through a reasonably minimal set of pathways and should have consistent behavior.

Test Plan:
- Loaded a revision with inlines.
- Created a new empty inline, reloaded page, saw it vanish.
- Created a new empty inline, typed draft text, did not save, reloaded page, saw draft present.
- Created a new empty inline, typed draft text. Submitted feedback, got prompt, answered "Y", saw draft text submit.
- Created a new empty inline, typed draft text, scrolled down to bottom of page, typed non-draft text, saw preview include draft text.
- Marked and submitted "Done".
- Used hide/show on inlines, verified state persisted.
- Did much of the same stuff in Diffusion, where it all works the same way (except: there's no prompt when submitting draft is-editing inlines).

Maniphest Tasks: T13513

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

+105 -118
+1 -11
src/applications/differential/editor/DifferentialRevisionEditEngine.php
··· 302 302 303 303 protected function newAutomaticCommentTransactions($object) { 304 304 $viewer = $this->getViewer(); 305 - $xactions = array(); 306 - 307 - $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments( 308 - $viewer, 309 - $object); 310 - $inlines = msort($inlines, 'getID'); 311 305 312 306 $editor = $object->getApplicationTransactionEditor() 313 307 ->setActor($viewer); 314 308 315 - $query_template = id(new DifferentialDiffInlineCommentQuery()) 316 - ->withRevisionPHIDs(array($object->getPHID())); 317 - 318 309 $xactions = $editor->newAutomaticInlineTransactions( 319 310 $object, 320 - $inlines, 321 311 DifferentialTransaction::TYPE_INLINE, 322 - $query_template); 312 + new DifferentialDiffInlineCommentQuery()); 323 313 324 314 return $xactions; 325 315 }
+5 -3
src/applications/differential/engine/DifferentialRevisionDraftEngine.php
··· 7 7 $viewer = $this->getViewer(); 8 8 $revision = $this->getObject(); 9 9 10 - $inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments( 11 - $viewer, 12 - $revision); 10 + $inlines = id(new DifferentialDiffInlineCommentQuery()) 11 + ->setViewer($viewer) 12 + ->withRevisionPHIDs(array($revision->getPHID())) 13 + ->withPublishableComments(true) 14 + ->execute(); 13 15 14 16 return (bool)$inlines; 15 17 }
-45
src/applications/differential/query/DifferentialTransactionQuery.php
··· 7 7 return new DifferentialTransaction(); 8 8 } 9 9 10 - public static function loadUnsubmittedInlineComments( 11 - PhabricatorUser $viewer, 12 - DifferentialRevision $revision) { 13 - 14 - $inlines = id(new DifferentialDiffInlineCommentQuery()) 15 - ->setViewer($viewer) 16 - ->withRevisionPHIDs(array($revision->getPHID())) 17 - ->withAuthorPHIDs(array($viewer->getPHID())) 18 - ->withHasTransaction(false) 19 - ->withIsDeleted(false) 20 - ->needReplyToComments(true) 21 - ->execute(); 22 - 23 - foreach ($inlines as $key => $inline) { 24 - $inlines[$key] = DifferentialInlineComment::newFromModernComment( 25 - $inline); 26 - } 27 - 28 - PhabricatorInlineComment::loadAndAttachVersionedDrafts( 29 - $viewer, 30 - $inlines); 31 - 32 - // Don't count void inlines when considering draft state. 33 - foreach ($inlines as $key => $inline) { 34 - if ($inline->isVoidComment($viewer)) { 35 - unset($inlines[$key]); 36 - continue; 37 - } 38 - 39 - // For other inlines: if they have a nonempty draft state, set their 40 - // content to the draft state content. We want to submit the comment 41 - // as it is currently shown to the user, not as it was stored the last 42 - // time they clicked "Save". 43 - 44 - $draft_content = $inline->getContentForEdit($viewer); 45 - if (strlen($draft_content)) { 46 - $inline->setContent($draft_content); 47 - } 48 - } 49 - 50 - $inlines = mpull($inlines, 'getStorageObject'); 51 - 52 - return $inlines; 53 - } 54 - 55 10 }
+1 -14
src/applications/diffusion/editor/DiffusionCommitEditEngine.php
··· 126 126 127 127 protected function newAutomaticCommentTransactions($object) { 128 128 $viewer = $this->getViewer(); 129 - $xactions = array(); 130 - 131 - $inlines = id(new DiffusionDiffInlineCommentQuery()) 132 - ->setViewer($viewer) 133 - ->withObjectPHIDs(array($object->getPHID())) 134 - ->withPublishableComments(true) 135 - ->needReplyToComments(true) 136 - ->execute(); 137 - $inlines = msort($inlines, 'getID'); 138 129 139 130 $editor = $object->getApplicationTransactionEditor() 140 131 ->setActor($viewer); 141 - 142 - $query_template = id(new DiffusionDiffInlineCommentQuery()) 143 - ->withCommitPHIDs(array($object->getPHID())); 144 132 145 133 $xactions = $editor->newAutomaticInlineTransactions( 146 134 $object, 147 - $inlines, 148 135 PhabricatorAuditActionConstants::INLINE, 149 - $query_template); 136 + new DiffusionDiffInlineCommentQuery()); 150 137 151 138 return $xactions; 152 139 }
+17 -26
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 5027 5027 5028 5028 public function newAutomaticInlineTransactions( 5029 5029 PhabricatorLiskDAO $object, 5030 - array $inlines, 5031 5030 $transaction_type, 5032 5031 PhabricatorCursorPagedPolicyAwareQuery $query_template) { 5033 5032 5033 + $actor = $this->getActor(); 5034 + 5035 + $inlines = id(clone $query_template) 5036 + ->setViewer($actor) 5037 + ->withObjectPHIDs(array($object->getPHID())) 5038 + ->withPublishableComments(true) 5039 + ->needAppliedDrafts(true) 5040 + ->needReplyToComments(true) 5041 + ->execute(); 5042 + $inlines = msort($inlines, 'getID'); 5043 + 5034 5044 $xactions = array(); 5035 5045 5036 5046 foreach ($inlines as $key => $inline) { 5037 - if ($inline->isEmptyInlineComment()) { 5038 - unset($inlines[$key]); 5039 - continue; 5040 - } 5041 - 5042 5047 $xactions[] = $object->getApplicationTransactionTemplate() 5043 5048 ->setTransactionType($transaction_type) 5044 5049 ->attachComment($inline); ··· 5065 5070 5066 5071 $state_map = PhabricatorTransactions::getInlineStateMap(); 5067 5072 5068 - $query = id(clone $query_template) 5073 + $inline_query = id(clone $query_template) 5069 5074 ->setViewer($this->getActor()) 5070 - ->withFixedStates(array_keys($state_map)); 5071 - 5072 - $inlines = array(); 5073 - 5074 - $inlines[] = id(clone $query) 5075 - ->withAuthorPHIDs(array($actor_phid)) 5076 - ->withHasTransaction(false) 5077 - ->execute(); 5075 + ->withObjectPHIDs(array($object->getPHID())) 5076 + ->withFixedStates(array_keys($state_map)) 5077 + ->withPublishableComments(true); 5078 5078 5079 5079 if ($actor_is_author) { 5080 - $inlines[] = id(clone $query) 5081 - ->withHasTransaction(true) 5082 - ->execute(); 5080 + $inline_query->withPublishedComments(true); 5083 5081 } 5084 5082 5085 - $inlines = array_mergev($inlines); 5086 - 5087 - foreach ($inlines as $key => $inline) { 5088 - if ($inline->isEmptyInlineComment()) { 5089 - unset($inlines[$key]); 5090 - continue; 5091 - } 5092 - } 5083 + $inlines = $inline_query->execute(); 5093 5084 5094 5085 if (!$inlines) { 5095 5086 return null;
+81 -19
src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php
··· 8 8 private $publishedComments; 9 9 private $publishableComments; 10 10 private $needHidden; 11 + private $needAppliedDrafts; 11 12 12 13 abstract protected function buildInlineCommentWhereClauseParts( 13 14 AphrontDatabaseConnection $conn); ··· 38 39 39 40 final public function needHidden($need_hidden) { 40 41 $this->needHidden = $need_hidden; 42 + return $this; 43 + } 44 + 45 + final public function needAppliedDrafts($need_applied) { 46 + $this->needAppliedDrafts = $need_applied; 41 47 return $this; 42 48 } 43 49 ··· 124 130 return $where; 125 131 } 126 132 127 - protected function willFilterPage(array $comments) { 133 + protected function willFilterPage(array $inlines) { 134 + $viewer = $this->getViewer(); 135 + 128 136 if ($this->needReplyToComments) { 129 137 $reply_phids = array(); 130 - foreach ($comments as $comment) { 131 - $reply_phid = $comment->getReplyToCommentPHID(); 138 + foreach ($inlines as $inline) { 139 + $reply_phid = $inline->getReplyToCommentPHID(); 132 140 if ($reply_phid) { 133 141 $reply_phids[] = $reply_phid; 134 142 } 135 143 } 136 144 137 145 if ($reply_phids) { 138 - $reply_comments = newv(get_class($this), array()) 146 + $reply_inlines = newv(get_class($this), array()) 139 147 ->setViewer($this->getViewer()) 140 148 ->setParentQuery($this) 141 149 ->withPHIDs($reply_phids) 142 150 ->execute(); 143 - $reply_comments = mpull($reply_comments, null, 'getPHID'); 151 + $reply_inlines = mpull($reply_inlines, null, 'getPHID'); 144 152 } else { 145 - $reply_comments = array(); 153 + $reply_inlines = array(); 146 154 } 147 155 148 - foreach ($comments as $key => $comment) { 149 - $reply_phid = $comment->getReplyToCommentPHID(); 156 + foreach ($inlines as $key => $inline) { 157 + $reply_phid = $inline->getReplyToCommentPHID(); 150 158 if (!$reply_phid) { 151 - $comment->attachReplyToComment(null); 159 + $inline->attachReplyToComment(null); 152 160 continue; 153 161 } 154 - $reply = idx($reply_comments, $reply_phid); 162 + $reply = idx($reply_inlines, $reply_phid); 155 163 if (!$reply) { 156 - $this->didRejectResult($comment); 157 - unset($comments[$key]); 164 + $this->didRejectResult($inline); 165 + unset($inlines[$key]); 158 166 continue; 159 167 } 160 - $comment->attachReplyToComment($reply); 168 + $inline->attachReplyToComment($reply); 161 169 } 162 170 } 163 171 164 - if (!$comments) { 165 - return $comments; 172 + if (!$inlines) { 173 + return $inlines; 166 174 } 167 175 168 176 if ($this->needHidden) { 169 - $viewer = $this->getViewer(); 170 177 $viewer_phid = $viewer->getPHID(); 171 178 172 179 if ($viewer_phid) { 173 180 $hidden = $this->loadHiddenCommentIDs( 174 181 $viewer_phid, 175 - $comments); 182 + $inlines); 176 183 } else { 177 184 $hidden = array(); 178 185 } 179 186 180 - foreach ($comments as $inline) { 187 + foreach ($inlines as $inline) { 181 188 $inline->attachIsHidden(isset($hidden[$inline->getID()])); 182 189 } 183 190 } 184 191 185 - return $comments; 192 + if (!$inlines) { 193 + return $inlines; 194 + } 195 + 196 + $need_drafts = $this->needAppliedDrafts; 197 + $drop_void = $this->publishableComments; 198 + $convert_objects = ($need_drafts || $drop_void); 199 + 200 + if ($convert_objects) { 201 + $inlines = mpull($inlines, 'newInlineCommentObject'); 202 + 203 + PhabricatorInlineComment::loadAndAttachVersionedDrafts( 204 + $viewer, 205 + $inlines); 206 + 207 + if ($need_drafts) { 208 + // Don't count void inlines when considering draft state. 209 + foreach ($inlines as $key => $inline) { 210 + if ($inline->isVoidComment($viewer)) { 211 + $this->didRejectResult($inline->getStorageObject()); 212 + unset($inlines[$key]); 213 + continue; 214 + } 215 + 216 + // For other inlines: if they have a nonempty draft state, set their 217 + // content to the draft state content. We want to submit the comment 218 + // as it is currently shown to the user, not as it was stored the last 219 + // time they clicked "Save". 220 + 221 + $draft_content = $inline->getContentForEdit($viewer); 222 + if (strlen($draft_content)) { 223 + $inline->setContent($draft_content); 224 + } 225 + } 226 + } 227 + 228 + // If we're loading publishable comments, discard any comments that are 229 + // empty. 230 + if ($drop_void) { 231 + foreach ($inlines as $key => $inline) { 232 + if ($inline->getTransactionPHID()) { 233 + continue; 234 + } 235 + 236 + if ($inline->isVoidComment($viewer)) { 237 + $this->didRejectResult($inline->getStorageObject()); 238 + unset($inlines[$key]); 239 + continue; 240 + } 241 + } 242 + } 243 + 244 + $inlines = mpull($inlines, 'getStorageObject'); 245 + } 246 + 247 + return $inlines; 186 248 } 187 249 188 250 }