Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/interface/PhabricatorInlineComment.php
| Show All 9 Lines | abstract class PhabricatorInlineComment | ||||
| const STATE_UNDONE = 'undone'; | const STATE_UNDONE = 'undone'; | ||||
| const STATE_DRAFT = 'draft'; | const STATE_DRAFT = 'draft'; | ||||
| const STATE_UNDRAFT = 'undraft'; | const STATE_UNDRAFT = 'undraft'; | ||||
| const STATE_DONE = 'done'; | const STATE_DONE = 'done'; | ||||
| private $storageObject; | private $storageObject; | ||||
| private $syntheticAuthor; | private $syntheticAuthor; | ||||
| private $isGhost; | private $isGhost; | ||||
| private $versionedDrafts = array(); | |||||
| public function __clone() { | public function __clone() { | ||||
| $this->storageObject = clone $this->storageObject; | $this->storageObject = clone $this->storageObject; | ||||
| } | } | ||||
| final public static function loadAndAttachVersionedDrafts( | |||||
| PhabricatorUser $viewer, | |||||
| array $inlines) { | |||||
| $viewer_phid = $viewer->getPHID(); | |||||
| if (!$viewer_phid) { | |||||
| return; | |||||
| } | |||||
| $inlines = mpull($inlines, null, 'getPHID'); | |||||
| $load = array(); | |||||
| foreach ($inlines as $key => $inline) { | |||||
| if (!$inline->getIsEditing()) { | |||||
| continue; | |||||
| } | |||||
| if ($inline->getAuthorPHID() !== $viewer_phid) { | |||||
| continue; | |||||
| } | |||||
| $load[$key] = $inline; | |||||
| } | |||||
| if (!$load) { | |||||
| return; | |||||
| } | |||||
| $drafts = PhabricatorVersionedDraft::loadDrafts( | |||||
| array_keys($load), | |||||
| $viewer_phid); | |||||
| $drafts = mpull($drafts, null, 'getObjectPHID'); | |||||
| foreach ($inlines as $inline) { | |||||
| $draft = idx($drafts, $inline->getPHID()); | |||||
| $inline->attachVersionedDraftForViewer($viewer, $draft); | |||||
| } | |||||
| } | |||||
| public function setSyntheticAuthor($synthetic_author) { | public function setSyntheticAuthor($synthetic_author) { | ||||
| $this->syntheticAuthor = $synthetic_author; | $this->syntheticAuthor = $synthetic_author; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getSyntheticAuthor() { | public function getSyntheticAuthor() { | ||||
| return $this->syntheticAuthor; | return $this->syntheticAuthor; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | public function delete() { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function makeEphemeral() { | public function makeEphemeral() { | ||||
| $this->getStorageObject()->makeEphemeral(); | $this->getStorageObject()->makeEphemeral(); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function attachVersionedDraftForViewer( | |||||
| PhabricatorUser $viewer, | |||||
| PhabricatorVersionedDraft $draft = null) { | |||||
| $key = $viewer->getCacheFragment(); | |||||
| $this->versionedDrafts[$key] = $draft; | |||||
| return $this; | |||||
| } | |||||
| public function hasVersionedDraftForViewer(PhabricatorUser $viewer) { | |||||
| $key = $viewer->getCacheFragment(); | |||||
| return array_key_exists($key, $this->versionedDrafts); | |||||
| } | |||||
| public function getVersionedDraftForViewer(PhabricatorUser $viewer) { | |||||
| $key = $viewer->getCacheFragment(); | |||||
| if (!array_key_exists($key, $this->versionedDrafts)) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Versioned draft is not attached for user with fragment "%s".', | |||||
| $key)); | |||||
| } | |||||
| return $this->versionedDrafts[$key]; | |||||
| } | |||||
| public function isVoidComment(PhabricatorUser $viewer) { | |||||
| return !strlen($this->getContentForEdit($viewer)); | |||||
| } | |||||
| public function getContentForEdit(PhabricatorUser $viewer) { | |||||
| $content = $this->getContent(); | |||||
| if (!$this->hasVersionedDraftForViewer($viewer)) { | |||||
| return $content; | |||||
| } | |||||
| $versioned_draft = $this->getVersionedDraftForViewer($viewer); | |||||
| if (!$versioned_draft) { | |||||
| return $content; | |||||
| } | |||||
| $draft_text = $versioned_draft->getProperty('inline.text'); | |||||
| if ($draft_text === null) { | |||||
| return $content; | |||||
| } | |||||
| return $draft_text; | |||||
| } | |||||
| /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ | /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ | ||||
| public function getMarkupFieldKey($field) { | public function getMarkupFieldKey($field) { | ||||
| $content = $this->getMarkupText($field); | $content = $this->getMarkupText($field); | ||||
| return PhabricatorMarkupEngine::digestRemarkupContent($this, $content); | return PhabricatorMarkupEngine::digestRemarkupContent($this, $content); | ||||
| } | } | ||||
| Show All 18 Lines | |||||