Skip to content

Commit 16ce63e

Browse files
committed
Conpherence - add back in custom images
Summary: Fixes T7254. This reverts the previous functionality, but makes pertinent updates like scaling the images to 35 x 35. Codebase had moved on quite a bit so far from a straight revert but nothing too tricky relative to the code that was here before. This does not allow for changing the images from the conpherence durable column view -- that would require some JS trickery, but also doesn't fit into the current notion of the column being "light". Can always modify this later. Test Plan: - from full conpherence, uploaded a square pic and things looked nice - from full conpherence, uploaded a rectangular pic and wasnt happy, so reinvoked edit dialog and used crop control to make it better - noted could not update picture from conpherence durable column - used different user and noted could see custom picture Reviewers: epriestley Reviewed By: epriestley Subscribers: CodeMouse92, Korvin, epriestley Maniphest Tasks: T7254 Differential Revision: https://secure.phabricator.com/D12648
1 parent 9c7d1b0 commit 16ce63e

19 files changed

+447
-8
lines changed

resources/celerity/map.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
'rsrc/js/application/auth/behavior-persona-login.js' => '9414ff18',
357357
'rsrc/js/application/config/behavior-reorder-fields.js' => '14a827de',
358358
'rsrc/js/application/conpherence/ConpherenceThreadManager.js' => '6709c934',
359+
'rsrc/js/application/conpherence/behavior-drag-and-drop-photo.js' => 'cf86d16a',
359360
'rsrc/js/application/conpherence/behavior-durable-column.js' => '657c2b50',
360361
'rsrc/js/application/conpherence/behavior-menu.js' => '804b0773',
361362
'rsrc/js/application/conpherence/behavior-pontificate.js' => '21ba5861',
@@ -561,6 +562,7 @@
561562
'javelin-behavior-audit-preview' => 'd835b03a',
562563
'javelin-behavior-choose-control' => '6153c708',
563564
'javelin-behavior-config-reorder-fields' => '14a827de',
565+
'javelin-behavior-conpherence-drag-and-drop-photo' => 'cf86d16a',
564566
'javelin-behavior-conpherence-menu' => '804b0773',
565567
'javelin-behavior-conpherence-pontificate' => '21ba5861',
566568
'javelin-behavior-conpherence-widget-pane' => '93568464',
@@ -1789,6 +1791,12 @@
17891791
'javelin-stratcom',
17901792
'phabricator-phtize',
17911793
),
1794+
'cf86d16a' => array(
1795+
'javelin-behavior',
1796+
'javelin-dom',
1797+
'javelin-workflow',
1798+
'phabricator-drag-and-drop-file-upload',
1799+
),
17921800
'd19198c8' => array(
17931801
'javelin-install',
17941802
'javelin-dom',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE {$NAMESPACE}_conpherence.conpherence_thread
2+
ADD imagePHIDs LONGTEXT COLLATE {$COLLATE_TEXT} NOT NULL AFTER title;
3+
4+
UPDATE {$NAMESPACE}_conpherence.conpherence_thread
5+
SET imagePHIDS = '[]';

src/__phutil_library_map__.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@
230230
'ConpherenceDurableColumnView' => 'applications/conpherence/view/ConpherenceDurableColumnView.php',
231231
'ConpherenceEditor' => 'applications/conpherence/editor/ConpherenceEditor.php',
232232
'ConpherenceFileWidgetView' => 'applications/conpherence/view/ConpherenceFileWidgetView.php',
233+
'ConpherenceFormDragAndDropUploadControl' => 'applications/conpherence/view/ConpherenceFormDragAndDropUploadControl.php',
233234
'ConpherenceFulltextQuery' => 'applications/conpherence/query/ConpherenceFulltextQuery.php',
234235
'ConpherenceHovercardEventListener' => 'applications/conpherence/events/ConpherenceHovercardEventListener.php',
236+
'ConpherenceImageData' => 'applications/conpherence/constants/ConpherenceImageData.php',
235237
'ConpherenceIndex' => 'applications/conpherence/storage/ConpherenceIndex.php',
236238
'ConpherenceLayoutView' => 'applications/conpherence/view/ConpherenceLayoutView.php',
237239
'ConpherenceListController' => 'applications/conpherence/controller/ConpherenceListController.php',
@@ -244,6 +246,7 @@
244246
'ConpherenceParticipantQuery' => 'applications/conpherence/query/ConpherenceParticipantQuery.php',
245247
'ConpherenceParticipationStatus' => 'applications/conpherence/constants/ConpherenceParticipationStatus.php',
246248
'ConpherencePeopleWidgetView' => 'applications/conpherence/view/ConpherencePeopleWidgetView.php',
249+
'ConpherencePicCropControl' => 'applications/conpherence/view/ConpherencePicCropControl.php',
247250
'ConpherenceQueryThreadConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceQueryThreadConduitAPIMethod.php',
248251
'ConpherenceQueryTransactionConduitAPIMethod' => 'applications/conpherence/conduit/ConpherenceQueryTransactionConduitAPIMethod.php',
249252
'ConpherenceReplyHandler' => 'applications/conpherence/mail/ConpherenceReplyHandler.php',
@@ -3467,8 +3470,10 @@
34673470
'ConpherenceDurableColumnView' => 'AphrontTagView',
34683471
'ConpherenceEditor' => 'PhabricatorApplicationTransactionEditor',
34693472
'ConpherenceFileWidgetView' => 'ConpherenceWidgetView',
3473+
'ConpherenceFormDragAndDropUploadControl' => 'AphrontFormControl',
34703474
'ConpherenceFulltextQuery' => 'PhabricatorOffsetPagedQuery',
34713475
'ConpherenceHovercardEventListener' => 'PhabricatorEventListener',
3476+
'ConpherenceImageData' => 'ConpherenceConstants',
34723477
'ConpherenceIndex' => 'ConpherenceDAO',
34733478
'ConpherenceLayoutView' => 'AphrontView',
34743479
'ConpherenceListController' => 'ConpherenceController',
@@ -3481,6 +3486,7 @@
34813486
'ConpherenceParticipantQuery' => 'PhabricatorOffsetPagedQuery',
34823487
'ConpherenceParticipationStatus' => 'ConpherenceConstants',
34833488
'ConpherencePeopleWidgetView' => 'ConpherenceWidgetView',
3489+
'ConpherencePicCropControl' => 'AphrontFormControl',
34843490
'ConpherenceQueryThreadConduitAPIMethod' => 'ConpherenceConduitAPIMethod',
34853491
'ConpherenceQueryTransactionConduitAPIMethod' => 'ConpherenceConduitAPIMethod',
34863492
'ConpherenceReplyHandler' => 'PhabricatorMailReplyHandler',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
final class ConpherenceImageData extends ConpherenceConstants {
4+
5+
const SIZE_ORIG = 'original';
6+
const SIZE_CROP = 'crop';
7+
8+
const CROP_WIDTH = 35;
9+
const CROP_HEIGHT = 35;
10+
11+
}

src/applications/conpherence/constants/ConpherenceTransactionType.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ final class ConpherenceTransactionType extends ConpherenceConstants {
66
const TYPE_TITLE = 'title';
77
const TYPE_PARTICIPANTS = 'participants';
88
const TYPE_DATE_MARKER = 'date-marker';
9-
10-
/* these two are deprecated but keep them around for legacy installs */
119
const TYPE_PICTURE = 'picture';
1210
const TYPE_PICTURE_CROP = 'picture-crop';
1311

src/applications/conpherence/controller/ConpherenceColumnViewController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function handleRequest(AphrontRequest $request) {
1616
$latest_conpherences = id(new ConpherenceThreadQuery())
1717
->setViewer($user)
1818
->withPHIDs($conpherence_phids)
19+
->needCropPics(true)
1920
->needParticipantCache(true)
2021
->execute();
2122
$latest_conpherences = mpull($latest_conpherences, null, 'getPHID');
@@ -30,6 +31,7 @@ public function handleRequest(AphrontRequest $request) {
3031
$conpherence = id(new ConpherenceThreadQuery())
3132
->setViewer($user)
3233
->withIDs(array($request->getInt('id')))
34+
->needCropPics(true)
3335
->needTransactions(true)
3436
->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
3537
->executeOne();
@@ -39,6 +41,7 @@ public function handleRequest(AphrontRequest $request) {
3941
$conpherence = id(new ConpherenceThreadQuery())
4042
->setViewer($user)
4143
->withPHIDs(array($participant->getConpherencePHID()))
44+
->needCropPics(true)
4245
->needTransactions(true)
4346
->setTransactionLimit(ConpherenceThreadQuery::TRANSACTION_LIMIT)
4447
->executeOne();

src/applications/conpherence/controller/ConpherenceListController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ private function loadConpherenceThreadData($participation) {
138138
$conpherences = id(new ConpherenceThreadQuery())
139139
->setViewer($user)
140140
->withPHIDs($conpherence_phids)
141+
->needCropPics(true)
141142
->needParticipantCache(true)
142143
->execute();
143144

src/applications/conpherence/controller/ConpherenceNotificationPanelController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function handleRequest(AphrontRequest $request) {
1717
$conpherences = id(new ConpherenceThreadQuery())
1818
->setViewer($user)
1919
->withPHIDs(array_keys($participant_data))
20+
->needCropPics(true)
2021
->needTransactions(true)
2122
->setTransactionLimit(3 * 5)
2223
->needParticipantCache(true)

src/applications/conpherence/controller/ConpherenceUpdateController.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function handleRequest(AphrontRequest $request) {
3737
->setViewer($user)
3838
->withIDs(array($conpherence_id))
3939
->needFilePHIDs(true)
40+
->needOrigPics(true)
41+
->needCropPics(true)
4042
->needParticipants($need_participants)
4143
->requireCapabilities($needed_capabilities)
4244
->executeOne();
@@ -132,11 +134,56 @@ public function handleRequest(AphrontRequest $request) {
132134
->setContent($result);
133135
break;
134136
case ConpherenceUpdateActions::METADATA:
135-
// all metadata updates are continue requests
137+
$top = $request->getInt('image_y');
138+
$left = $request->getInt('image_x');
139+
$file_id = $request->getInt('file_id');
140+
$title = $request->getStr('title');
141+
if ($file_id) {
142+
$orig_file = id(new PhabricatorFileQuery())
143+
->setViewer($user)
144+
->withIDs(array($file_id))
145+
->executeOne();
146+
$xactions[] = id(new ConpherenceTransaction())
147+
->setTransactionType(ConpherenceTransactionType::TYPE_PICTURE)
148+
->setNewValue($orig_file);
149+
$okay = $orig_file->isTransformableImage();
150+
if ($okay) {
151+
$xformer = new PhabricatorImageTransformer();
152+
$crop_file = $xformer->executeConpherenceTransform(
153+
$orig_file,
154+
0,
155+
0,
156+
ConpherenceImageData::CROP_WIDTH,
157+
ConpherenceImageData::CROP_HEIGHT);
158+
$xactions[] = id(new ConpherenceTransaction())
159+
->setTransactionType(
160+
ConpherenceTransactionType::TYPE_PICTURE_CROP)
161+
->setNewValue($crop_file->getPHID());
162+
}
163+
$response_mode = 'redirect';
164+
}
165+
166+
// all other metadata updates are continue requests
136167
if (!$request->isContinueRequest()) {
137168
break;
138169
}
139170

171+
if ($top !== null || $left !== null) {
172+
$file = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG);
173+
$xformer = new PhabricatorImageTransformer();
174+
$xformed = $xformer->executeConpherenceTransform(
175+
$file,
176+
$top,
177+
$left,
178+
ConpherenceImageData::CROP_WIDTH,
179+
ConpherenceImageData::CROP_HEIGHT);
180+
$image_phid = $xformed->getPHID();
181+
182+
$xactions[] = id(new ConpherenceTransaction())
183+
->setTransactionType(
184+
ConpherenceTransactionType::TYPE_PICTURE_CROP)
185+
->setNewValue($image_phid);
186+
}
140187
$title = $request->getStr('title');
141188
$xactions[] = id(new ConpherenceTransaction())
142189
->setTransactionType(ConpherenceTransactionType::TYPE_TITLE)
@@ -323,6 +370,35 @@ private function renderMetadataDialogue(
323370
->setName('title')
324371
->setValue($conpherence->getTitle()));
325372

373+
$nopic = $this->getRequest()->getExists('nopic');
374+
$image = $conpherence->getImage(ConpherenceImageData::SIZE_ORIG);
375+
if ($nopic) {
376+
// do not render any pic related controls
377+
} else if ($image) {
378+
$crop_uri = $conpherence->loadImageURI(ConpherenceImageData::SIZE_CROP);
379+
$form
380+
->appendChild(
381+
id(new AphrontFormMarkupControl())
382+
->setLabel(pht('Image'))
383+
->setValue(phutil_tag(
384+
'img',
385+
array(
386+
'src' => $crop_uri,
387+
))))
388+
->appendChild(
389+
id(new ConpherencePicCropControl())
390+
->setLabel(pht('Crop Image'))
391+
->setValue($image))
392+
->appendChild(
393+
id(new ConpherenceFormDragAndDropUploadControl())
394+
->setLabel(pht('Change Image')));
395+
} else {
396+
$form
397+
->appendChild(
398+
id(new ConpherenceFormDragAndDropUploadControl())
399+
->setLabel(pht('Image')));
400+
}
401+
326402
if ($conpherence->getIsRoom()) {
327403
$title = pht('Update Room');
328404
$policies = id(new PhabricatorPolicyQuery())
@@ -400,6 +476,7 @@ private function loadAndRenderUpdates(
400476
$conpherence = id(new ConpherenceThreadQuery())
401477
->setViewer($user)
402478
->setAfterTransactionID($latest_transaction_id)
479+
->needCropPics(true)
403480
->needParticipantCache($need_participant_cache)
404481
->needWidgetData($need_widget_data)
405482
->needTransactions($need_transactions)

src/applications/conpherence/controller/ConpherenceViewController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function handleRequest(AphrontRequest $request) {
1515
$query = id(new ConpherenceThreadQuery())
1616
->setViewer($user)
1717
->withIDs(array($conpherence_id))
18+
->needCropPics(true)
1819
->needParticipantCache(true)
1920
->needTransactions(true)
2021
->setTransactionLimit($this->getMainQueryLimit());

src/applications/conpherence/editor/ConpherenceEditor.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public function getTransactionTypes() {
120120
$types[] = ConpherenceTransactionType::TYPE_TITLE;
121121
$types[] = ConpherenceTransactionType::TYPE_PARTICIPANTS;
122122
$types[] = ConpherenceTransactionType::TYPE_FILES;
123+
$types[] = ConpherenceTransactionType::TYPE_PICTURE;
124+
$types[] = ConpherenceTransactionType::TYPE_PICTURE_CROP;
123125
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
124126
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
125127
$types[] = PhabricatorTransactions::TYPE_JOIN_POLICY;
@@ -134,6 +136,10 @@ protected function getCustomTransactionOldValue(
134136
switch ($xaction->getTransactionType()) {
135137
case ConpherenceTransactionType::TYPE_TITLE:
136138
return $object->getTitle();
139+
case ConpherenceTransactionType::TYPE_PICTURE:
140+
return $object->getImagePHID(ConpherenceImageData::SIZE_ORIG);
141+
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
142+
return $object->getImagePHID(ConpherenceImageData::SIZE_CROP);
137143
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
138144
if ($this->getIsNewObject()) {
139145
return array();
@@ -150,7 +156,11 @@ protected function getCustomTransactionNewValue(
150156

151157
switch ($xaction->getTransactionType()) {
152158
case ConpherenceTransactionType::TYPE_TITLE:
159+
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
153160
return $xaction->getNewValue();
161+
case ConpherenceTransactionType::TYPE_PICTURE:
162+
$file = $xaction->getNewValue();
163+
return $file->getPHID();
154164
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
155165
case ConpherenceTransactionType::TYPE_FILES:
156166
return $this->getPHIDTransactionNewValue($xaction);
@@ -243,6 +253,16 @@ protected function applyCustomInternalTransaction(
243253
case ConpherenceTransactionType::TYPE_TITLE:
244254
$object->setTitle($xaction->getNewValue());
245255
break;
256+
case ConpherenceTransactionType::TYPE_PICTURE:
257+
$object->setImagePHID(
258+
$xaction->getNewValue(),
259+
ConpherenceImageData::SIZE_ORIG);
260+
break;
261+
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
262+
$object->setImagePHID(
263+
$xaction->getNewValue(),
264+
ConpherenceImageData::SIZE_CROP);
265+
break;
246266
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
247267
if (!$this->getIsNewObject()) {
248268
$old_map = array_fuse($xaction->getOldValue());
@@ -576,6 +596,20 @@ protected function getSearchContextParameter(
576596
);
577597
}
578598

599+
protected function extractFilePHIDsFromCustomTransaction(
600+
PhabricatorLiskDAO $object,
601+
PhabricatorApplicationTransaction $xaction) {
602+
603+
switch ($xaction->getTransactionType()) {
604+
case ConpherenceTransactionType::TYPE_PICTURE:
605+
return array($xaction->getNewValue()->getPHID());
606+
case ConpherenceTransactionType::TYPE_PICTURE_CROP:
607+
return array($xaction->getNewValue());
608+
}
609+
610+
return parent::extractFilePHIDsFromCustomTransaction($object, $xaction);
611+
}
612+
579613
protected function validateTransaction(
580614
PhabricatorLiskDAO $object,
581615
$type,
@@ -608,6 +642,21 @@ protected function validateTransaction(
608642
$errors[] = $error;
609643
}
610644
break;
645+
case ConpherenceTransactionType::TYPE_PICTURE:
646+
foreach ($xactions as $xaction) {
647+
$file = $xaction->getNewValue();
648+
if (!$file->isTransformableImage()) {
649+
$detail = pht('This server only supports these image formats: %s.',
650+
implode(', ', PhabricatorFile::getTransformableImageFormats()));
651+
$error = new PhabricatorApplicationTransactionValidationError(
652+
$type,
653+
pht('Invalid'),
654+
$detail,
655+
last($xactions));
656+
$errors[] = $error;
657+
}
658+
}
659+
break;
611660
case ConpherenceTransactionType::TYPE_PARTICIPANTS:
612661
foreach ($xactions as $xaction) {
613662
$new_phids = $this->getPHIDTransactionNewValue($xaction, array());

0 commit comments

Comments
 (0)