Skip to content

Commit 94a95ef

Browse files
author
epriestley
committed
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
1 parent 7910757 commit 94a95ef

File tree

6 files changed

+105
-118
lines changed

6 files changed

+105
-118
lines changed

src/applications/differential/editor/DifferentialRevisionEditEngine.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,14 @@ private function isCustomFieldEnabled(DifferentialRevision $revision, $key) {
302302

303303
protected function newAutomaticCommentTransactions($object) {
304304
$viewer = $this->getViewer();
305-
$xactions = array();
306-
307-
$inlines = DifferentialTransactionQuery::loadUnsubmittedInlineComments(
308-
$viewer,
309-
$object);
310-
$inlines = msort($inlines, 'getID');
311305

312306
$editor = $object->getApplicationTransactionEditor()
313307
->setActor($viewer);
314308

315-
$query_template = id(new DifferentialDiffInlineCommentQuery())
316-
->withRevisionPHIDs(array($object->getPHID()));
317-
318309
$xactions = $editor->newAutomaticInlineTransactions(
319310
$object,
320-
$inlines,
321311
DifferentialTransaction::TYPE_INLINE,
322-
$query_template);
312+
new DifferentialDiffInlineCommentQuery());
323313

324314
return $xactions;
325315
}

src/applications/differential/engine/DifferentialRevisionDraftEngine.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ protected function hasCustomDraftContent() {
77
$viewer = $this->getViewer();
88
$revision = $this->getObject();
99

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();
1315

1416
return (bool)$inlines;
1517
}

src/applications/differential/query/DifferentialTransactionQuery.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,4 @@ public function getTemplateApplicationTransaction() {
77
return new DifferentialTransaction();
88
}
99

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-
5510
}

src/applications/diffusion/editor/DiffusionCommitEditEngine.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,27 +126,14 @@ protected function buildCustomEditFields($object) {
126126

127127
protected function newAutomaticCommentTransactions($object) {
128128
$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');
138129

139130
$editor = $object->getApplicationTransactionEditor()
140131
->setActor($viewer);
141132

142-
$query_template = id(new DiffusionDiffInlineCommentQuery())
143-
->withCommitPHIDs(array($object->getPHID()));
144-
145133
$xactions = $editor->newAutomaticInlineTransactions(
146134
$object,
147-
$inlines,
148135
PhabricatorAuditActionConstants::INLINE,
149-
$query_template);
136+
new DiffusionDiffInlineCommentQuery());
150137

151138
return $xactions;
152139
}

src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5027,18 +5027,23 @@ private function buildHistoryMail(PhabricatorLiskDAO $object) {
50275027

50285028
public function newAutomaticInlineTransactions(
50295029
PhabricatorLiskDAO $object,
5030-
array $inlines,
50315030
$transaction_type,
50325031
PhabricatorCursorPagedPolicyAwareQuery $query_template) {
50335032

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+
50345044
$xactions = array();
50355045

50365046
foreach ($inlines as $key => $inline) {
5037-
if ($inline->isEmptyInlineComment()) {
5038-
unset($inlines[$key]);
5039-
continue;
5040-
}
5041-
50425047
$xactions[] = $object->getApplicationTransactionTemplate()
50435048
->setTransactionType($transaction_type)
50445049
->attachComment($inline);
@@ -5065,31 +5070,17 @@ protected function newInlineStateTransaction(
50655070

50665071
$state_map = PhabricatorTransactions::getInlineStateMap();
50675072

5068-
$query = id(clone $query_template)
5073+
$inline_query = id(clone $query_template)
50695074
->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);
50785078

50795079
if ($actor_is_author) {
5080-
$inlines[] = id(clone $query)
5081-
->withHasTransaction(true)
5082-
->execute();
5080+
$inline_query->withPublishedComments(true);
50835081
}
50845082

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();
50935084

50945085
if (!$inlines) {
50955086
return null;

src/infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ abstract class PhabricatorDiffInlineCommentQuery
88
private $publishedComments;
99
private $publishableComments;
1010
private $needHidden;
11+
private $needAppliedDrafts;
1112

1213
abstract protected function buildInlineCommentWhereClauseParts(
1314
AphrontDatabaseConnection $conn);
@@ -41,6 +42,11 @@ final public function needHidden($need_hidden) {
4142
return $this;
4243
}
4344

45+
final public function needAppliedDrafts($need_applied) {
46+
$this->needAppliedDrafts = $need_applied;
47+
return $this;
48+
}
49+
4450
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
4551
$where = parent::buildWhereClauseParts($conn);
4652
$alias = $this->getPrimaryTableAlias();
@@ -124,65 +130,121 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
124130
return $where;
125131
}
126132

127-
protected function willFilterPage(array $comments) {
133+
protected function willFilterPage(array $inlines) {
134+
$viewer = $this->getViewer();
135+
128136
if ($this->needReplyToComments) {
129137
$reply_phids = array();
130-
foreach ($comments as $comment) {
131-
$reply_phid = $comment->getReplyToCommentPHID();
138+
foreach ($inlines as $inline) {
139+
$reply_phid = $inline->getReplyToCommentPHID();
132140
if ($reply_phid) {
133141
$reply_phids[] = $reply_phid;
134142
}
135143
}
136144

137145
if ($reply_phids) {
138-
$reply_comments = newv(get_class($this), array())
146+
$reply_inlines = newv(get_class($this), array())
139147
->setViewer($this->getViewer())
140148
->setParentQuery($this)
141149
->withPHIDs($reply_phids)
142150
->execute();
143-
$reply_comments = mpull($reply_comments, null, 'getPHID');
151+
$reply_inlines = mpull($reply_inlines, null, 'getPHID');
144152
} else {
145-
$reply_comments = array();
153+
$reply_inlines = array();
146154
}
147155

148-
foreach ($comments as $key => $comment) {
149-
$reply_phid = $comment->getReplyToCommentPHID();
156+
foreach ($inlines as $key => $inline) {
157+
$reply_phid = $inline->getReplyToCommentPHID();
150158
if (!$reply_phid) {
151-
$comment->attachReplyToComment(null);
159+
$inline->attachReplyToComment(null);
152160
continue;
153161
}
154-
$reply = idx($reply_comments, $reply_phid);
162+
$reply = idx($reply_inlines, $reply_phid);
155163
if (!$reply) {
156-
$this->didRejectResult($comment);
157-
unset($comments[$key]);
164+
$this->didRejectResult($inline);
165+
unset($inlines[$key]);
158166
continue;
159167
}
160-
$comment->attachReplyToComment($reply);
168+
$inline->attachReplyToComment($reply);
161169
}
162170
}
163171

164-
if (!$comments) {
165-
return $comments;
172+
if (!$inlines) {
173+
return $inlines;
166174
}
167175

168176
if ($this->needHidden) {
169-
$viewer = $this->getViewer();
170177
$viewer_phid = $viewer->getPHID();
171178

172179
if ($viewer_phid) {
173180
$hidden = $this->loadHiddenCommentIDs(
174181
$viewer_phid,
175-
$comments);
182+
$inlines);
176183
} else {
177184
$hidden = array();
178185
}
179186

180-
foreach ($comments as $inline) {
187+
foreach ($inlines as $inline) {
181188
$inline->attachIsHidden(isset($hidden[$inline->getID()]));
182189
}
183190
}
184191

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;
186248
}
187249

188250
}

0 commit comments

Comments
 (0)