Skip to content

Commit 1cf16d8

Browse files
authoredJan 24, 2024
Bug 1873965 - Revert changes that made the attach_inlines parameter to differential.createcomment a no-op
This reverts commit 3976488. * Use DifferentialDiffInlineCommentQuery to retrieve inline comments * Query publishable inline comments * Restore the `loadUnsubmittedInlineComments` function * Avoid using `getContentForEdit` since it is removed
1 parent 4b41edd commit 1cf16d8

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed
 

‎src/applications/differential/conduit/DifferentialCreateCommentConduitAPIMethod.php

+56-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,17 @@ protected function execute(ConduitAPIRequest $request) {
9494
->setContent($content));
9595
}
9696

97-
// NOTE: The legacy "attach_inlines" flag is now ignored and has no
98-
// effect. See T13513.
97+
if ($request->getValue('attach_inlines')) {
98+
$type_inline = DifferentialTransaction::TYPE_INLINE;
99+
$inlines = $this->loadUnsubmittedInlineComments(
100+
$viewer,
101+
$revision);
102+
foreach ($inlines as $inline) {
103+
$xactions[] = id(new DifferentialTransaction())
104+
->setTransactionType($type_inline)
105+
->attachComment($inline);
106+
}
107+
}
99108

100109
// NOTE: The legacy "silent" flag is now ignored and has no effect. See
101110
// T13042.
@@ -114,4 +123,49 @@ protected function execute(ConduitAPIRequest $request) {
114123
);
115124
}
116125

126+
public static function loadUnsubmittedInlineComments(
127+
PhabricatorUser $viewer,
128+
DifferentialRevision $revision) {
129+
130+
$inlines = id(new DifferentialDiffInlineCommentQuery())
131+
->setViewer($viewer)
132+
->withRevisionPHIDs(array($revision->getPHID()))
133+
->withAuthorPHIDs(array($viewer->getPHID()))
134+
->withHasTransaction(false)
135+
->withIsDeleted(false)
136+
->needReplyToComments(true)
137+
->execute();
138+
139+
foreach ($inlines as $key => $inline) {
140+
$inlines[$key] = DifferentialInlineComment::newFromModernComment(
141+
$inline);
142+
}
143+
144+
PhabricatorInlineComment::loadAndAttachVersionedDrafts(
145+
$viewer,
146+
$inlines);
147+
148+
// Don't count void inlines when considering draft state.
149+
foreach ($inlines as $key => $inline) {
150+
if ($inline->isVoidComment($viewer)) {
151+
unset($inlines[$key]);
152+
continue;
153+
}
154+
155+
// For other inlines: if they have a nonempty draft state, set their
156+
// content to the draft state content. We want to submit the comment
157+
// as it is currently shown to the user, not as it was stored the last
158+
// time they clicked "Save".
159+
160+
// $draft_content = $inline->getContentForEdit($viewer);
161+
// if (strlen($draft_content)) {
162+
// $inline->setContent($draft_content);
163+
// }
164+
}
165+
166+
$inlines = mpull($inlines, 'getStorageObject');
167+
168+
return $inlines;
169+
}
170+
117171
}

0 commit comments

Comments
 (0)
Failed to load comments.