Differential D2844 Diff 5293 src/applications/conduit/method/differential/ConduitAPI_differential_getrevisioncomments_Method.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/method/differential/ConduitAPI_differential_getrevisioncomments_Method.php
Show All 23 Lines | final class ConduitAPI_differential_getrevisioncomments_Method | ||||
public function getMethodDescription() { | public function getMethodDescription() { | ||||
return "Retrieve Differential Revision Comments."; | return "Retrieve Differential Revision Comments."; | ||||
} | } | ||||
public function defineParamTypes() { | public function defineParamTypes() { | ||||
return array( | return array( | ||||
'ids' => 'required list<int>', | 'ids' => 'required list<int>', | ||||
'inlines' => 'optional bool', | |||||
); | ); | ||||
} | } | ||||
public function defineReturnType() { | public function defineReturnType() { | ||||
return 'nonempty list<dict<string, wild>>'; | return 'nonempty list<dict<string, wild>>'; | ||||
} | } | ||||
public function defineErrorTypes() { | public function defineErrorTypes() { | ||||
return array( | return array( | ||||
); | ); | ||||
} | } | ||||
protected function execute(ConduitAPIRequest $request) { | protected function execute(ConduitAPIRequest $request) { | ||||
$results = array(); | $results = array(); | ||||
$revision_ids = $request->getValue('ids'); | $revision_ids = $request->getValue('ids'); | ||||
if (!$revision_ids) { | if (!$revision_ids) { | ||||
return $results; | return $results; | ||||
} | } | ||||
$comments = id(new DifferentialComment())->loadAllWhere( | $comments = id(new DifferentialComment())->loadAllWhere( | ||||
'revisionID IN (%Ld)', | 'revisionID IN (%Ld)', | ||||
$revision_ids); | $revision_ids); | ||||
$with_inlines = $request->getValue('inlines'); | |||||
if ($with_inlines) { | |||||
$inlines = id(new DifferentialInlineComment())->loadAllWhere( | |||||
'revisionID IN (%Ld)', | |||||
$revision_ids); | |||||
$changesets = array(); | |||||
if ($inlines) { | |||||
$changesets = id(new DifferentialChangeset())->loadAllWhere( | |||||
'id IN (%Ld)', | |||||
array_unique(mpull($inlines, 'getChangesetID'))); | |||||
$inlines = mgroup($inlines, 'getCommentID'); | |||||
} | |||||
} | |||||
foreach ($comments as $comment) { | foreach ($comments as $comment) { | ||||
$revision_id = $comment->getRevisionID(); | $revision_id = $comment->getRevisionID(); | ||||
if (!array_key_exists($revision_id, $results)) { | $result = array( | ||||
$results[$revision_id] = array(); | |||||
} | |||||
$results[$revision_id][] = array( | |||||
'revisionID' => $revision_id, | 'revisionID' => $revision_id, | ||||
'action' => $comment->getAction(), | 'action' => $comment->getAction(), | ||||
'authorPHID' => $comment->getAuthorPHID(), | 'authorPHID' => $comment->getAuthorPHID(), | ||||
'dateCreated' => $comment->getDateCreated(), | 'dateCreated' => $comment->getDateCreated(), | ||||
'content' => $comment->getContent(), | 'content' => $comment->getContent(), | ||||
); | ); | ||||
if ($with_inlines) { | |||||
$result['inlines'] = array(); | |||||
foreach (idx($inlines, $comment->getID(), array()) as $inline) { | |||||
$file_path = null; | |||||
$changeset = idx($changesets, $inline->getChangesetID()); | |||||
if ($changeset) { | |||||
$file_path = ($inline->getIsNewFile() ? | |||||
$changeset->getFilename() : | |||||
$changeset->getOldFile()); | |||||
} | |||||
$result['inlines'][] = array( | |||||
'filePath' => $file_path, | |||||
'isNewFile' => $inline->getIsNewFile(), | |||||
'lineNumber' => $inline->getLineNumber(), | |||||
'lineLength' => $inline->getLineLength(), | |||||
'content' => $inline->getContent(), | |||||
epriestley: Maybe this should also show which diffID the comment is on? | |||||
); | |||||
} | |||||
// TODO: Put synthetic inlines without an attached comment somewhere. | |||||
} | |||||
$results[$revision_id][] = $result; | |||||
} | } | ||||
return $results; | return $results; | ||||
} | } | ||||
} | } |
Maybe this should also show which diffID the comment is on?