Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 87bc305

Browse files
author
epriestley
committed
Make inline content "state-oriented", not "string-oriented"
Summary: Ref T13513. Currently, all the inline code passes around strings to describe content. I plan to add background music, animation effects, etc., soon. To prepare for this change, make content a state object. This does not change any user-visible behavior, it just prepares for content to become more complicated than a single string. Test Plan: Created, edited, submitted, cancelled, etc., comments. Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21273
1 parent 9d5b8bd commit 87bc305

File tree

8 files changed

+176
-149
lines changed

8 files changed

+176
-149
lines changed

resources/celerity/map.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'core.pkg.js' => '845355f4',
1414
'dark-console.pkg.js' => '187792c2',
1515
'differential.pkg.css' => '42a2334f',
16-
'differential.pkg.js' => '8f59bce2',
16+
'differential.pkg.js' => 'ff8ca085',
1717
'diffusion.pkg.css' => '42c75c37',
1818
'diffusion.pkg.js' => 'a98c0bf7',
1919
'maniphest.pkg.css' => '35995d6d',
@@ -379,9 +379,9 @@
379379
'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => 'a2ab19be',
380380
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9',
381381
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
382-
'rsrc/js/application/diff/DiffChangeset.js' => '0c083409',
383-
'rsrc/js/application/diff/DiffChangesetList.js' => 'db615898',
384-
'rsrc/js/application/diff/DiffInline.js' => 'b00168c1',
382+
'rsrc/js/application/diff/DiffChangeset.js' => '6e5e03d2',
383+
'rsrc/js/application/diff/DiffChangesetList.js' => 'b51ba93a',
384+
'rsrc/js/application/diff/DiffInline.js' => '28e53a2c',
385385
'rsrc/js/application/diff/DiffPathView.js' => '8207abf9',
386386
'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b',
387387
'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd',
@@ -774,9 +774,9 @@
774774
'phabricator-darklog' => '3b869402',
775775
'phabricator-darkmessage' => '26cd4b73',
776776
'phabricator-dashboard-css' => '5a205b9d',
777-
'phabricator-diff-changeset' => '0c083409',
778-
'phabricator-diff-changeset-list' => 'db615898',
779-
'phabricator-diff-inline' => 'b00168c1',
777+
'phabricator-diff-changeset' => '6e5e03d2',
778+
'phabricator-diff-changeset-list' => 'b51ba93a',
779+
'phabricator-diff-inline' => '28e53a2c',
780780
'phabricator-diff-path-view' => '8207abf9',
781781
'phabricator-diff-tree-view' => '5d83623b',
782782
'phabricator-drag-and-drop-file-upload' => '4370900d',
@@ -1000,19 +1000,6 @@
10001000
'javelin-dom',
10011001
'phabricator-draggable-list',
10021002
),
1003-
'0c083409' => array(
1004-
'javelin-dom',
1005-
'javelin-util',
1006-
'javelin-stratcom',
1007-
'javelin-install',
1008-
'javelin-workflow',
1009-
'javelin-router',
1010-
'javelin-behavior-device',
1011-
'javelin-vector',
1012-
'phabricator-diff-inline',
1013-
'phabricator-diff-path-view',
1014-
'phuix-button-view',
1015-
),
10161003
'0cf79f45' => array(
10171004
'javelin-behavior',
10181005
'javelin-stratcom',
@@ -1150,6 +1137,9 @@
11501137
'javelin-install',
11511138
'javelin-util',
11521139
),
1140+
'28e53a2c' => array(
1141+
'javelin-dom',
1142+
),
11531143
'29819b75' => array(
11541144
'phabricator-notification',
11551145
'javelin-stratcom',
@@ -1561,6 +1551,19 @@
15611551
'javelin-install',
15621552
'javelin-util',
15631553
),
1554+
'6e5e03d2' => array(
1555+
'javelin-dom',
1556+
'javelin-util',
1557+
'javelin-stratcom',
1558+
'javelin-install',
1559+
'javelin-workflow',
1560+
'javelin-router',
1561+
'javelin-behavior-device',
1562+
'javelin-vector',
1563+
'phabricator-diff-inline',
1564+
'phabricator-diff-path-view',
1565+
'phuix-button-view',
1566+
),
15641567
70245195 => array(
15651568
'javelin-behavior',
15661569
'javelin-stratcom',
@@ -1935,9 +1938,6 @@
19351938
'javelin-behavior-device',
19361939
'javelin-vector',
19371940
),
1938-
'b00168c1' => array(
1939-
'javelin-dom',
1940-
),
19411941
'b105a3a6' => array(
19421942
'javelin-behavior',
19431943
'javelin-stratcom',
@@ -1970,6 +1970,11 @@
19701970
'b517bfa0' => array(
19711971
'phui-oi-list-view-css',
19721972
),
1973+
'b51ba93a' => array(
1974+
'javelin-install',
1975+
'phuix-button-view',
1976+
'phabricator-diff-tree-view',
1977+
),
19731978
'b557770a' => array(
19741979
'javelin-install',
19751980
'javelin-util',
@@ -2119,11 +2124,6 @@
21192124
'javelin-uri',
21202125
'phabricator-notification',
21212126
),
2122-
'db615898' => array(
2123-
'javelin-install',
2124-
'phuix-button-view',
2125-
'phabricator-diff-tree-view',
2126-
),
21272127
'e150bd50' => array(
21282128
'javelin-behavior',
21292129
'javelin-stratcom',

src/infrastructure/diff/PhabricatorInlineCommentController.php

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ protected function showComments(array $ids) {
3939
private $isOnRight;
4040
private $lineNumber;
4141
private $lineLength;
42-
private $commentText;
4342
private $operation;
4443
private $commentID;
4544
private $renderer;
@@ -99,16 +98,16 @@ public function processRequest() {
9998
$request = $this->getRequest();
10099
$viewer = $this->getViewer();
101100

101+
if (!$request->validateCSRF()) {
102+
return new Aphront404Response();
103+
}
104+
102105
$this->readRequestParameters();
103106

104107
$op = $this->getOperation();
105108
switch ($op) {
106109
case 'hide':
107110
case 'show':
108-
if (!$request->validateCSRF()) {
109-
return new Aphront404Response();
110-
}
111-
112111
$ids = $request->getStrList('ids');
113112
if ($ids) {
114113
if ($op == 'hide') {
@@ -120,9 +119,6 @@ public function processRequest() {
120119

121120
return id(new AphrontAjaxResponse())->setContent(array());
122121
case 'done':
123-
if (!$request->validateCSRF()) {
124-
return new Aphront404Response();
125-
}
126122
$inline = $this->loadCommentForDone($this->getCommentID());
127123

128124
$is_draft_state = false;
@@ -158,10 +154,6 @@ public function processRequest() {
158154
case 'delete':
159155
case 'undelete':
160156
case 'refdelete':
161-
if (!$request->validateCSRF()) {
162-
return new Aphront404Response();
163-
}
164-
165157
// NOTE: For normal deletes, we just process the delete immediately
166158
// and show an "Undo" action. For deletes by reference from the
167159
// preview ("refdelete"), we prompt first (because the "Undo" may
@@ -193,15 +185,14 @@ public function processRequest() {
193185

194186
return $this->buildEmptyResponse();
195187
case 'edit':
188+
case 'save':
196189
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
197-
$text = $this->getCommentText();
190+
if ($op === 'save') {
191+
$this->updateCommentContentState($inline);
198192

199-
if ($request->isFormPost()) {
200-
if (strlen($text)) {
201-
$inline
202-
->setContent($text)
203-
->setIsEditing(false);
193+
$inline->setIsEditing(false);
204194

195+
if (!$inline->isVoidComment($viewer)) {
205196
$this->saveComment($inline);
206197

207198
return $this->buildRenderedCommentResponse(
@@ -216,7 +207,7 @@ public function processRequest() {
216207
}
217208
} else {
218209
// NOTE: At time of writing, the "editing" state of inlines is
219-
// preserved by simluating a click on "Edit" when the inline loads.
210+
// preserved by simulating a click on "Edit" when the inline loads.
220211

221212
// In this case, we don't want to "saveComment()", because it
222213
// recalculates object drafts and purges versioned drafts.
@@ -234,8 +225,8 @@ public function processRequest() {
234225
$is_dirty = true;
235226
}
236227

237-
if (strlen($text)) {
238-
$inline->setContent($text);
228+
if ($this->hasContentState()) {
229+
$this->updateCommentContentState($inline);
239230
$is_dirty = true;
240231
} else {
241232
PhabricatorInlineComment::loadAndAttachVersionedDrafts(
@@ -262,13 +253,9 @@ public function processRequest() {
262253
// If the user uses "Undo" to get into an edited state ("AB"), then
263254
// clicks cancel to return to the previous state ("A"), we also want
264255
// to set the stored state back to "A".
265-
$text = $this->getCommentText();
266-
if (strlen($text)) {
267-
$inline->setContent($text);
268-
}
256+
$this->updateCommentContentState($inline);
269257

270-
$content = $inline->getContent();
271-
if (!strlen($content)) {
258+
if ($inline->isVoidComment($viewer)) {
272259
$inline->setIsDeleted(1);
273260
}
274261

@@ -283,11 +270,11 @@ public function processRequest() {
283270
$viewer->getPHID(),
284271
$inline->getID());
285272

286-
$text = $this->getCommentText();
287-
288-
$versioned_draft
289-
->setProperty('inline.text', $text)
290-
->save();
273+
$map = $this->getContentState();
274+
foreach ($map as $key => $value) {
275+
$versioned_draft->setProperty($key, $value);
276+
}
277+
$versioned_draft->save();
291278

292279
// We have to synchronize the draft engine after saving a versioned
293280
// draft, because taking an inline comment from "no text, no draft"
@@ -318,11 +305,11 @@ public function processRequest() {
318305
->setIsNewFile($is_new)
319306
->setLineNumber($number)
320307
->setLineLength($length)
321-
->setContent((string)$this->getCommentText())
322308
->setReplyToCommentPHID($this->getReplyToCommentPHID())
323309
->setIsEditing(true)
324310
->setStartOffset($request->getInt('startOffset'))
325-
->setEndOffset($request->getInt('endOffset'));
311+
->setEndOffset($request->getInt('endOffset'))
312+
->setContent('');
326313

327314
$document_engine_key = $request->getStr('documentEngineKey');
328315
if ($document_engine_key !== null) {
@@ -338,6 +325,10 @@ public function processRequest() {
338325
}
339326
}
340327

328+
if ($this->hasContentState()) {
329+
$this->updateCommentContentState($inline);
330+
}
331+
341332
$this->saveComment($inline);
342333

343334
$edit_dialog = $this->buildEditDialog($inline);
@@ -365,7 +356,6 @@ private function readRequestParameters() {
365356
$this->isOnRight = $request->getBool('on_right');
366357
$this->lineNumber = $request->getInt('number');
367358
$this->lineLength = $request->getInt('length');
368-
$this->commentText = $request->getStr('text');
369359
$this->commentID = $request->getInt('id');
370360
$this->operation = $request->getStr('op');
371361
$this->renderer = $request->getStr('renderer');
@@ -529,6 +519,36 @@ private function loadCommentByQuery(
529519
return $inline;
530520
}
531521

522+
private function hasContentState() {
523+
$request = $this->getRequest();
524+
return (bool)$request->getBool('hasContentState');
525+
}
526+
527+
private function getContentState() {
528+
$request = $this->getRequest();
529+
530+
$comment_text = $request->getStr('text');
531+
532+
return array(
533+
'inline.text' => (string)$comment_text,
534+
);
535+
}
536+
537+
private function updateCommentContentState(PhabricatorInlineComment $inline) {
538+
if (!$this->hasContentState()) {
539+
throw new Exception(
540+
pht(
541+
'Attempting to update comment content state, but request has no '.
542+
'content state.'));
543+
}
544+
545+
$state = $this->getContentState();
546+
547+
$text = $state['inline.text'];
548+
549+
$inline->setContent($text);
550+
}
551+
532552
private function saveComment(PhabricatorInlineComment $inline) {
533553
$viewer = $this->getViewer();
534554
$draft_engine = $this->newDraftEngine();

src/infrastructure/diff/interface/PhabricatorInlineComment.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ public function getContentForEdit(PhabricatorUser $viewer) {
322322
return $draft_text;
323323
}
324324

325+
public function getContentState() {
326+
return array(
327+
'text' => $this->getContent(),
328+
);
329+
}
325330

326331
/* -( PhabricatorMarkupInterface Implementation )-------------------------- */
327332

src/infrastructure/diff/view/PHUIDiffInlineCommentEditView.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,12 @@ public function render() {
2222
'sigil' => 'inline-edit-form',
2323
),
2424
array(
25-
$this->renderInputs(),
2625
$this->renderBody(),
2726
));
2827

2928
return $content;
3029
}
3130

32-
private function renderInputs() {
33-
$inputs = array();
34-
$inline = $this->getInlineComment();
35-
36-
$inputs[] = array('op', 'edit');
37-
$inputs[] = array('id', $inline->getID());
38-
39-
$inputs[] = array('on_right', $this->getIsOnRight());
40-
$inputs[] = array('renderer', $this->getRenderer());
41-
42-
$out = array();
43-
44-
foreach ($inputs as $input) {
45-
list($name, $value) = $input;
46-
$out[] = phutil_tag(
47-
'input',
48-
array(
49-
'type' => 'hidden',
50-
'name' => $name,
51-
'value' => $value,
52-
));
53-
}
54-
55-
return $out;
56-
}
57-
5831
private function renderBody() {
5932
$buttons = array();
6033

src/infrastructure/diff/view/PHUIDiffInlineCommentView.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ protected function getInlineCommentMetadata() {
8282
'number' => $inline->getLineNumber(),
8383
'length' => $inline->getLineLength(),
8484
'isNewFile' => (bool)$inline->getIsNewFile(),
85-
'original' => $inline->getContent(),
8685
'replyToCommentPHID' => $inline->getReplyToCommentPHID(),
8786
'isDraft' => $inline->isDraft(),
8887
'isFixed' => $is_fixed,
@@ -93,8 +92,8 @@ protected function getInlineCommentMetadata() {
9392
'documentEngineKey' => $inline->getDocumentEngineKey(),
9493
'startOffset' => $inline->getStartOffset(),
9594
'endOffset' => $inline->getEndOffset(),
96-
9795
'on_right' => $this->getIsOnRight(),
96+
'contentState' => $inline->getContentState(),
9897
);
9998
}
10099

webroot/rsrc/js/application/diff/DiffChangeset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,14 @@ JX.install('DiffChangeset', {
761761
return inline;
762762
},
763763

764-
newInlineReply: function(original, text) {
764+
newInlineReply: function(original, state) {
765765
var inline = new JX.DiffInline()
766766
.setChangeset(this)
767767
.bindToReply(original);
768768

769769
this._inlines.push(inline);
770770

771-
inline.create(text);
771+
inline.create(state);
772772

773773
return inline;
774774
},

0 commit comments

Comments
 (0)