@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Adding a proper story feed for moving a Phriction Document

Summary: Display a proper feed title when moving Phriction Documents.

Test Plan:
{F36112, size=full}

Descriptions for the feeds you see in the image.

# New and cool story feed
# Fallback for the boring old ones
# Normal story feed, unchanged

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2686

Differential Revision: https://secure.phabricator.com/D5352

authored by

Anh Nhan Nguyen and committed by
epriestley
3b801fa5 e3a9ddfc

+65 -16
+46 -6
src/applications/feed/story/PhabricatorFeedStoryPhriction.php
··· 6 6 return $this->getValue('phid'); 7 7 } 8 8 9 + public function getRequiredHandlePHIDs() { 10 + $required_phids = parent::getRequiredHandlePHIDs(); 11 + $from_phid = $this->getStoryData()->getValue('movedFromPHID'); 12 + if ($from_phid) { 13 + $required_phids[] = $from_phid; 14 + } 15 + return $required_phids; 16 + } 17 + 9 18 public function renderView() { 10 19 $data = $this->getStoryData(); 11 20 ··· 17 26 $action = $data->getValue('action'); 18 27 $verb = PhrictionActionConstants::getActionPastTenseVerb($action); 19 28 20 - $view->setTitle(hsprintf( 21 - '%s %s the document %s.', 22 - $this->linkTo($author_phid), 23 - $verb, 24 - $this->linkTo($document_phid))); 29 + switch ($action) { 30 + case PhrictionActionConstants::ACTION_MOVE_HERE: 31 + $from_phid = $data->getValue('movedFromPHID'); 32 + 33 + // Older feed stories may not have 'moved_from_phid', in that case 34 + // we fall back to the default behaviour (hence the fallthrough) 35 + if ($from_phid) { 36 + $document_handle = $this->getHandle($document_phid); 37 + $from_handle = $this->getHandle($from_phid); 38 + $view->setTitle(pht( 39 + '%s moved the document %s from %s to %s.', 40 + $this->linkTo($author_phid), 41 + $document_handle->renderLink(), 42 + phutil_tag( 43 + 'a', 44 + array( 45 + 'href' => $from_handle->getURI(), 46 + ), 47 + $from_handle->getURI()), 48 + phutil_tag( 49 + 'a', 50 + array( 51 + 'href' => $document_handle->getURI(), 52 + ), 53 + $document_handle->getURI()))); 54 + break; 55 + } 56 + /* Fallthrough */ 57 + default: 58 + $view->setTitle(pht( 59 + '%s %s the document %s.', 60 + $this->linkTo($author_phid), 61 + $verb, 62 + $this->linkTo($document_phid))); 63 + break; 64 + } 65 + 25 66 $view->setEpoch($data->getEpoch()); 26 67 27 - $action = $data->getValue('action'); 28 68 switch ($action) { 29 69 case PhrictionActionConstants::ACTION_CREATE: 30 70 $full_size = true;
+2 -2
src/applications/phriction/constants/PhrictionActionConstants.php
··· 16 16 self::ACTION_CREATE => 'created', 17 17 self::ACTION_EDIT => 'edited', 18 18 self::ACTION_DELETE => 'deleted', 19 - self::ACTION_MOVE_AWAY => 'moved a document to', 20 - self::ACTION_MOVE_HERE => 'moved a document from', 19 + self::ACTION_MOVE_AWAY => 'moved', 20 + self::ACTION_MOVE_HERE => 'moved', 21 21 ); 22 22 23 23 return idx($map, $action, "brazenly {$action}'d");
+1 -1
src/applications/phriction/controller/PhrictionMoveController.php
··· 102 102 ->setDescription($content->getDescription()); 103 103 104 104 // Move it! 105 - $target_editor->moveHere($document->getID()); 105 + $target_editor->moveHere($document->getID(), $document->getPHID()); 106 106 107 107 // Retrieve the target doc directly from the editor 108 108 // No need to load it per Sql again
+16 -7
src/applications/phriction/editor/PhrictionDocumentEditor.php
··· 14 14 private $newContent; 15 15 private $description; 16 16 17 + // For the Feed Story when moving documents 18 + private $fromDocumentPHID; 19 + 17 20 private function __construct() { 18 21 // <restricted> 19 22 } ··· 71 74 PhrictionChangeType::CHANGE_MOVE_AWAY, true, $new_doc_id); 72 75 } 73 76 74 - public function moveHere($old_doc_id) { 77 + public function moveHere($old_doc_id, $old_doc_phid) { 78 + $this->fromDocumentPHID = $old_doc_phid; 75 79 return $this->execute( 76 80 PhrictionChangeType::CHANGE_MOVE_HERE, false, $old_doc_id); 77 81 } ··· 181 185 break; 182 186 case PhrictionChangeType::CHANGE_MOVE_AWAY: 183 187 $doc_status = PhrictionDocumentStatus::STATUS_MOVED; 184 - $feed_action = PhrictionActionConstants::ACTION_MOVE_AWAY; 188 + $feed_action = null; 185 189 break; 186 190 case PhrictionChangeType::CHANGE_MOVE_HERE: 187 191 $doc_status = PhrictionDocumentStatus::STATUS_EXISTS; 188 - $feed_action = null; 192 + $feed_action = PhrictionActionConstants::ACTION_MOVE_HERE; 189 193 break; 190 194 default: 191 195 throw new Exception( ··· 253 257 $related_phids[] = $project_phid; 254 258 } 255 259 260 + if ($this->fromDocumentPHID) { 261 + $related_phids[] = $this->fromDocumentPHID; 262 + } 263 + 256 264 if ($feed_action) { 257 265 id(new PhabricatorFeedStoryPublisher()) 258 266 ->setRelatedPHIDs($related_phids) ··· 261 269 ->setStoryType(PhabricatorFeedStoryTypeConstants::STORY_PHRICTION) 262 270 ->setStoryData( 263 271 array( 264 - 'phid' => $document->getPHID(), 265 - 'action' => $feed_action, 266 - 'content' => phutil_utf8_shorten($new_content->getContent(), 140), 267 - 'project' => $project_phid, 272 + 'phid' => $document->getPHID(), 273 + 'action' => $feed_action, 274 + 'content' => phutil_utf8_shorten($new_content->getContent(), 140), 275 + 'project' => $project_phid, 276 + 'movedFromPHID' => $this->fromDocumentPHID, 268 277 )) 269 278 ->publish(); 270 279 }