forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorDiffInlineCommentQuery.php
73 lines (61 loc) · 1.82 KB
/
PhabricatorDiffInlineCommentQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
abstract class PhabricatorDiffInlineCommentQuery
extends PhabricatorApplicationTransactionCommentQuery {
private $fixedStates;
private $needReplyToComments;
public function withFixedStates(array $states) {
$this->fixedStates = $states;
return $this;
}
public function needReplyToComments($need_reply_to) {
$this->needReplyToComments = $need_reply_to;
return $this;
}
protected function buildWhereClauseComponents(
AphrontDatabaseConnection $conn_r) {
$where = parent::buildWhereClauseComponents($conn_r);
if ($this->fixedStates !== null) {
$where[] = qsprintf(
$conn_r,
'fixedState IN (%Ls)',
$this->fixedStates);
}
return $where;
}
protected function willFilterPage(array $comments) {
if ($this->needReplyToComments) {
$reply_phids = array();
foreach ($comments as $comment) {
$reply_phid = $comment->getReplyToCommentPHID();
if ($reply_phid) {
$reply_phids[] = $reply_phid;
}
}
if ($reply_phids) {
$reply_comments = newv(get_class($this), array())
->setViewer($this->getViewer())
->setParentQuery($this)
->withPHIDs($reply_phids)
->execute();
$reply_comments = mpull($reply_comments, null, 'getPHID');
} else {
$reply_comments = array();
}
foreach ($comments as $key => $comment) {
$reply_phid = $comment->getReplyToCommentPHID();
if (!$reply_phid) {
$comment->attachReplyToComment(null);
continue;
}
$reply = idx($reply_comments, $reply_phid);
if (!$reply) {
$this->didRejectResult($comment);
unset($comments[$key]);
continue;
}
$comment->attachReplyToComment($reply);
}
}
return $comments;
}
}