Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/storage/PhamePostTransaction.php
<?php | <?php | ||||
final class PhamePostTransaction | final class PhamePostTransaction | ||||
extends PhabricatorApplicationTransaction { | extends PhabricatorApplicationTransaction { | ||||
const TYPE_TITLE = 'phame.post.title'; | const TYPE_TITLE = 'phame.post.title'; | ||||
const TYPE_PHAME_TITLE = 'phame.post.phame.title'; | const TYPE_PHAME_TITLE = 'phame.post.phame.title'; | ||||
const TYPE_BODY = 'phame.post.body'; | const TYPE_BODY = 'phame.post.body'; | ||||
const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget'; | const TYPE_COMMENTS_WIDGET = 'phame.post.comments.widget'; | ||||
const MAILTAG_CONTENT = 'phame-post-content'; | |||||
const MAILTAG_COMMENT = 'phame-post-comment'; | |||||
const MAILTAG_OTHER = 'phame-post-other'; | |||||
public function getApplicationName() { | public function getApplicationName() { | ||||
return 'phame'; | return 'phame'; | ||||
} | } | ||||
public function getApplicationTransactionType() { | public function getApplicationTransactionType() { | ||||
return PhabricatorPhamePostPHIDType::TYPECONST; | return PhabricatorPhamePostPHIDType::TYPECONST; | ||||
} | } | ||||
Show All 33 Lines | switch ($this->getTransactionType()) { | ||||
case self::TYPE_BODY: | case self::TYPE_BODY: | ||||
case self::TYPE_COMMENTS_WIDGET: | case self::TYPE_COMMENTS_WIDGET: | ||||
return 'fa-pencil'; | return 'fa-pencil'; | ||||
break; | break; | ||||
} | } | ||||
return parent::getIcon(); | return parent::getIcon(); | ||||
} | } | ||||
public function getMailTags() { | |||||
$tags = parent::getMailTags(); | |||||
switch ($this->getTransactionType()) { | |||||
case self::TYPE_COMMENTS_WIDGET: | |||||
case PhabricatorTransactions::TYPE_COMMENT: | |||||
$tags[] = self::MAILTAG_COMMENT; | |||||
break; | |||||
case self::TYPE_TITLE: | |||||
case self::TYPE_PHAME_TITLE: | |||||
case self::TYPE_BODY: | |||||
$tags[] = self::MAILTAG_CONTENT; | |||||
break; | |||||
default: | |||||
$tags[] = self::MAILTAG_OTHER; | |||||
break; | |||||
} | |||||
return $tags; | |||||
} | |||||
public function getTitle() { | public function getTitle() { | ||||
$author_phid = $this->getAuthorPHID(); | $author_phid = $this->getAuthorPHID(); | ||||
$object_phid = $this->getObjectPHID(); | $object_phid = $this->getObjectPHID(); | ||||
$old = $this->getOldValue(); | $old = $this->getOldValue(); | ||||
$new = $this->getNewValue(); | $new = $this->getNewValue(); | ||||
$type = $this->getTransactionType(); | $type = $this->getTransactionType(); | ||||
switch ($type) { | switch ($type) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
if ($old === null) { | if ($old === null) { | ||||
return pht( | return pht( | ||||
'%s created this post.', | '%s authored this post.', | ||||
$this->renderHandleLink($author_phid)); | $this->renderHandleLink($author_phid)); | ||||
} else { | } else { | ||||
return pht( | return pht( | ||||
'%s updated the post\'s name to "%s".', | '%s updated the post\'s name to "%s".', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$new); | $new); | ||||
} | } | ||||
break; | break; | ||||
case self::TYPE_BODY: | case self::TYPE_BODY: | ||||
return pht( | return pht( | ||||
'%s updated the post\'s body.', | '%s updated the blog post.', | ||||
$this->renderHandleLink($author_phid)); | $this->renderHandleLink($author_phid)); | ||||
break; | break; | ||||
case self::TYPE_PHAME_TITLE: | case self::TYPE_PHAME_TITLE: | ||||
return pht( | return pht( | ||||
'%s updated the post\'s phame title to "%s".', | '%s updated the post\'s Phame title to "%s".', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
rtrim($new, '/')); | rtrim($new, '/')); | ||||
break; | break; | ||||
case self::TYPE_COMMENTS_WIDGET: | case self::TYPE_COMMENTS_WIDGET: | ||||
return pht( | return pht( | ||||
'%s updated the post\'s comment widget to "%s".', | '%s updated the post\'s comment widget to "%s".', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$new); | $new); | ||||
Show All 10 Lines | public function getTitleForFeed() { | ||||
$old = $this->getOldValue(); | $old = $this->getOldValue(); | ||||
$new = $this->getNewValue(); | $new = $this->getNewValue(); | ||||
$type = $this->getTransactionType(); | $type = $this->getTransactionType(); | ||||
switch ($type) { | switch ($type) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
if ($old === null) { | if ($old === null) { | ||||
return pht( | return pht( | ||||
'%s created %s.', | '%s authored %s.', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$this->renderHandleLink($object_phid)); | $this->renderHandleLink($object_phid)); | ||||
} else { | } else { | ||||
return pht( | return pht( | ||||
'%s updated the name for %s.', | '%s updated the name for %s.', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$this->renderHandleLink($object_phid)); | $this->renderHandleLink($object_phid)); | ||||
} | } | ||||
break; | break; | ||||
case self::TYPE_BODY: | case self::TYPE_BODY: | ||||
return pht( | return pht( | ||||
'%s updated the body for %s.', | '%s updated the blog post %s.', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$this->renderHandleLink($object_phid)); | $this->renderHandleLink($object_phid)); | ||||
break; | break; | ||||
case self::TYPE_PHAME_TITLE: | case self::TYPE_PHAME_TITLE: | ||||
return pht( | return pht( | ||||
'%s updated the phame title for %s.', | '%s updated the Phame title for %s.', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$this->renderHandleLink($object_phid)); | $this->renderHandleLink($object_phid)); | ||||
break; | break; | ||||
case self::TYPE_COMMENTS_WIDGET: | case self::TYPE_COMMENTS_WIDGET: | ||||
return pht( | return pht( | ||||
'%s updated the comments widget for %s.', | '%s updated the comments widget for %s.', | ||||
$this->renderHandleLink($author_phid), | $this->renderHandleLink($author_phid), | ||||
$this->renderHandleLink($object_phid)); | $this->renderHandleLink($object_phid)); | ||||
break; | break; | ||||
} | } | ||||
return parent::getTitleForFeed(); | return parent::getTitleForFeed(); | ||||
} | } | ||||
public function getBodyForFeed(PhabricatorFeedStory $story) { | |||||
$new = $this->getNewValue(); | |||||
$body = null; | |||||
switch ($this->getTransactionType()) { | |||||
case self::TYPE_TITLE: | |||||
case self::TYPE_BODY: | |||||
return phutil_escape_html_newlines( | |||||
id(new PhutilUTF8StringTruncator()) | |||||
->setMaximumGlyphs(128) | |||||
->truncateString($new)); | |||||
break; | |||||
} | |||||
return parent::getBodyForFeed($story); | |||||
} | |||||
public function getColor() { | public function getColor() { | ||||
$old = $this->getOldValue(); | $old = $this->getOldValue(); | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case self::TYPE_TITLE: | case self::TYPE_TITLE: | ||||
if ($old === null) { | if ($old === null) { | ||||
return PhabricatorTransactions::COLOR_GREEN; | return PhabricatorTransactions::COLOR_GREEN; | ||||
} | } | ||||
Show All 32 Lines |