Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/interface/PhabricatorInlineComment.php
Show First 20 Lines • Show All 330 Lines • ▼ Show 20 Lines | abstract class PhabricatorInlineComment | ||||
protected function newContentState() { | protected function newContentState() { | ||||
return new PhabricatorDiffInlineCommentContentState(); | return new PhabricatorDiffInlineCommentContentState(); | ||||
} | } | ||||
public function newContentStateFromRequest(AphrontRequest $request) { | public function newContentStateFromRequest(AphrontRequest $request) { | ||||
return $this->newContentState()->readFromRequest($request); | return $this->newContentState()->readFromRequest($request); | ||||
} | } | ||||
public function getInitialContentState() { | |||||
return $this->getNamedContentState('inline.state.initial'); | |||||
} | |||||
public function setInitialContentState( | |||||
PhabricatorInlineCommentContentState $state) { | |||||
return $this->setNamedContentState('inline.state.initial', $state); | |||||
} | |||||
public function getCommittedContentState() { | |||||
return $this->getNamedContentState('inline.state.committed'); | |||||
} | |||||
public function setCommittedContentState( | |||||
PhabricatorInlineCommentContentState $state) { | |||||
return $this->setNamedContentState('inline.state.committed', $state); | |||||
} | |||||
public function getContentState() { | public function getContentState() { | ||||
$state = $this->newContentState(); | $state = $this->getNamedContentState('inline.state'); | ||||
$storage = $this->getStorageObject(); | if (!$state) { | ||||
$storage_map = $storage->getAttribute('inline.state'); | $state = $this->newContentState(); | ||||
if (is_array($storage_map)) { | |||||
$state->readStorageMap($storage_map); | |||||
} | } | ||||
$state->setContentText($this->getContent()); | $state->setContentText($this->getContent()); | ||||
return $state; | return $state; | ||||
} | } | ||||
public function setContentState(PhabricatorInlineCommentContentState $state) { | public function setContentState(PhabricatorInlineCommentContentState $state) { | ||||
$this->setContent($state->getContentText()); | |||||
return $this->setNamedContentState('inline.state', $state); | |||||
} | |||||
private function getNamedContentState($key) { | |||||
$storage = $this->getStorageObject(); | $storage = $this->getStorageObject(); | ||||
$storage_map = $state->newStorageMap(); | |||||
$storage->setAttribute('inline.state', $storage_map); | |||||
$this->setContent($state->getContentText()); | $storage_map = $storage->getAttribute($key); | ||||
if (!is_array($storage_map)) { | |||||
return null; | |||||
} | |||||
$state = $this->newContentState(); | |||||
$state->readStorageMap($storage_map); | |||||
return $state; | |||||
} | |||||
private function setNamedContentState( | |||||
$key, | |||||
PhabricatorInlineCommentContentState $state) { | |||||
$storage = $this->getStorageObject(); | |||||
$storage_map = $state->newStorageMap(); | |||||
$storage->setAttribute($key, $storage_map); | |||||
return $this; | return $this; | ||||
} | } | ||||
public function getInlineContext() { | public function getInlineContext() { | ||||
return $this->getStorageObject()->getInlineContext(); | return $this->getStorageObject()->getInlineContext(); | ||||
} | } | ||||
public function getContentStateMapForEdit(PhabricatorUser $viewer) { | |||||
return $this->getWireContentStateMap(true, $viewer); | |||||
} | |||||
public function getContentStateMap() { | |||||
return $this->getWireContentStateMap(false, null); | |||||
} | |||||
private function getWireContentStateMap( | |||||
$is_edit, | |||||
PhabricatorUser $viewer = null) { | |||||
$initial_state = $this->getInitialContentState(); | |||||
$committed_state = $this->getCommittedContentState(); | |||||
if ($is_edit) { | |||||
$active_state = $this->getContentStateForEdit($viewer); | |||||
} else { | |||||
$active_state = $this->getContentState(); | |||||
} | |||||
return array( | |||||
'initial' => $this->getWireContentState($initial_state), | |||||
'committed' => $this->getWireContentState($committed_state), | |||||
'active' => $this->getWireContentState($active_state), | |||||
); | |||||
} | |||||
private function getWireContentState($content_state) { | |||||
if ($content_state === null) { | |||||
return null; | |||||
} | |||||
return $content_state->newStorageMap(); | |||||
} | |||||
public function getDefaultSuggestionText() { | public function getDefaultSuggestionText() { | ||||
$context = $this->getInlineContext(); | $context = $this->getInlineContext(); | ||||
if (!$context) { | if (!$context) { | ||||
return null; | return null; | ||||
} | } | ||||
$default = $context->getBodyLines(); | $default = $context->getBodyLines(); | ||||
Show All 31 Lines |