forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDifferentialTransactionView.php
175 lines (141 loc) · 4.84 KB
/
DifferentialTransactionView.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
final class DifferentialTransactionView
extends PhabricatorApplicationTransactionView {
private $changesets = array();
private $revision;
private $rightDiff;
private $leftDiff;
public function setLeftDiff(DifferentialDiff $left_diff) {
$this->leftDiff = $left_diff;
return $this;
}
public function getLeftDiff() {
return $this->leftDiff;
}
public function setRightDiff(DifferentialDiff $right_diff) {
$this->rightDiff = $right_diff;
return $this;
}
public function getRightDiff() {
return $this->rightDiff;
}
public function setRevision(DifferentialRevision $revision) {
$this->revision = $revision;
return $this;
}
public function getRevision() {
return $this->revision;
}
public function setChangesets(array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
$this->changesets = $changesets;
return $this;
}
public function getChangesets() {
return $this->changesets;
}
// TODO: There's a whole lot of code duplication between this and
// PholioTransactionView to handle inlines. Merge this into the core? Some of
// it can probably be shared, while other parts are trickier.
protected function shouldGroupTransactions(
PhabricatorApplicationTransaction $u,
PhabricatorApplicationTransaction $v) {
if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
// Don't group transactions by different authors.
return false;
}
if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
// Don't group if transactions that happened more than 60s apart.
return false;
}
switch ($u->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
case DifferentialTransaction::TYPE_INLINE:
break;
default:
return false;
}
switch ($v->getTransactionType()) {
case DifferentialTransaction::TYPE_INLINE:
return true;
}
return parent::shouldGroupTransactions($u, $v);
}
protected function renderTransactionContent(
PhabricatorApplicationTransaction $xaction) {
$out = array();
$type_inline = DifferentialTransaction::TYPE_INLINE;
$group = $xaction->getTransactionGroup();
if ($xaction->getTransactionType() == $type_inline) {
array_unshift($group, $xaction);
} else {
$out[] = parent::renderTransactionContent($xaction);
}
// If we're rendering a preview, we show the inline comments in a separate
// section underneath the main transaction preview, so we skip rendering
// them in the preview body.
if ($this->getIsPreview()) {
return $out;
}
if (!$group) {
return $out;
}
$inlines = array();
foreach ($group as $xaction) {
switch ($xaction->getTransactionType()) {
case DifferentialTransaction::TYPE_INLINE:
$inlines[] = $xaction;
break;
default:
throw new Exception(pht('Unknown grouped transaction type!'));
}
}
if ($inlines) {
$inline_view = new PhabricatorInlineSummaryView();
$changesets = $this->getChangesets();
$inline_groups = DifferentialTransactionComment::sortAndGroupInlines(
$inlines,
$changesets);
foreach ($inline_groups as $changeset_id => $group) {
$changeset = $changesets[$changeset_id];
$items = array();
foreach ($group as $inline) {
$comment = $inline->getComment();
$item = array(
'id' => $comment->getID(),
'line' => $comment->getLineNumber(),
'length' => $comment->getLineLength(),
'content' => parent::renderTransactionContent($inline),
);
$changeset_diff_id = $changeset->getDiffID();
if ($comment->getIsNewFile()) {
$visible_diff_id = $this->getRightDiff()->getID();
} else {
$visible_diff_id = $this->getLeftDiff()->getID();
}
// TODO: We still get one edge case wrong here, when we have a
// versus diff and the file didn't exist in the old version. The
// comment is visible because we show the left side of the target
// diff when there's no corresponding file in the versus diff, but
// we incorrectly link it off-page.
$is_visible = ($changeset_diff_id == $visible_diff_id);
if (!$is_visible) {
$revision_id = $this->getRevision()->getID();
$comment_id = $comment->getID();
$item['href'] =
'/D'.$revision_id.
'?id='.$changeset_diff_id.
'#inline-'.$comment_id;
$item['where'] = pht('(On Diff #%d)', $changeset_diff_id);
}
$items[] = $item;
}
$inline_view->addCommentGroup(
$changeset->getFilename(),
$items);
}
$out[] = $inline_view;
}
return $out;
}
}