mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-27 07:50:57 +01:00
Add mail/feed support to PhamePost
Summary: Allows feed stories and mail for new Phame Posts. Test Plan: Write Post, Get Mail Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D14426
This commit is contained in:
parent
80f1d01602
commit
6fe2377cc2
8 changed files with 169 additions and 14 deletions
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE {$NAMESPACE}_phame.phame_post
|
||||
ADD mailKey binary(20) NOT NULL;
|
18
resources/sql/autopatches/20151106.phame.post.mailkey.2.php
Normal file
18
resources/sql/autopatches/20151106.phame.post.mailkey.2.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
$table = new PhamePost();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
$iterator = new LiskMigrationIterator($table);
|
||||
foreach ($iterator as $post) {
|
||||
$id = $post->getID();
|
||||
|
||||
echo pht('Adding mail key for Post %d...', $id);
|
||||
echo "\n";
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'UPDATE %T SET mailKey = %s WHERE id = %d',
|
||||
$table->getTableName(),
|
||||
Filesystem::readRandomCharacters(20),
|
||||
$id);
|
||||
}
|
|
@ -3275,6 +3275,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
|
||||
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
|
||||
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
|
||||
'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php',
|
||||
'PhamePostSearchEngine' => 'applications/phame/query/PhamePostSearchEngine.php',
|
||||
'PhamePostTransaction' => 'applications/phame/storage/PhamePostTransaction.php',
|
||||
'PhamePostTransactionQuery' => 'applications/phame/query/PhamePostTransactionQuery.php',
|
||||
|
@ -7544,6 +7545,7 @@ phutil_register_library_map(array(
|
|||
'PhamePostPreviewController' => 'PhamePostController',
|
||||
'PhamePostPublishController' => 'PhamePostController',
|
||||
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||
'PhamePostSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhamePostTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhamePostTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
|
|
|
@ -8,7 +8,7 @@ final class PhameBlogEditor
|
|||
}
|
||||
|
||||
public function getEditorObjectsDescription() {
|
||||
return pht('Blogs');
|
||||
return pht('Phame Blogs');
|
||||
}
|
||||
|
||||
public function getTransactionTypes() {
|
||||
|
|
|
@ -8,7 +8,7 @@ final class PhamePostEditor
|
|||
}
|
||||
|
||||
public function getEditorObjectsDescription() {
|
||||
return pht('Blog Posts');
|
||||
return pht('Phame Posts');
|
||||
}
|
||||
|
||||
public function getTransactionTypes() {
|
||||
|
@ -149,14 +149,75 @@ final class PhamePostEditor
|
|||
protected function shouldSendMail(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
if ($object->isDraft()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function shouldPublishFeedStory(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
if ($object->isDraft()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getMailTo(PhabricatorLiskDAO $object) {
|
||||
$phids = array();
|
||||
$phids[] = $object->getBloggerPHID();
|
||||
$phids[] = $this->requireActor()->getPHID();
|
||||
|
||||
$blog_phid = $object->getBlogPHID();
|
||||
if ($blog_phid) {
|
||||
$phids[] = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
||||
$blog_phid);
|
||||
}
|
||||
return $phids;
|
||||
}
|
||||
|
||||
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
|
||||
$phid = $object->getPHID();
|
||||
$title = $object->getTitle();
|
||||
|
||||
return id(new PhabricatorMetaMTAMail())
|
||||
->setSubject($title)
|
||||
->addHeader('Thread-Topic', $phid);
|
||||
}
|
||||
|
||||
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
|
||||
return id(new PhamePostReplyHandler())
|
||||
->setMailReceiver($object);
|
||||
}
|
||||
|
||||
protected function buildMailBody(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
|
||||
$body = parent::buildMailBody($object, $xactions);
|
||||
|
||||
$body->addLinkSection(
|
||||
pht('POST DETAIL'),
|
||||
PhabricatorEnv::getProductionURI($object->getViewURI()));
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
public function getMailTagsMap() {
|
||||
return array(
|
||||
PhamePostTransaction::MAILTAG_CONTENT =>
|
||||
pht("A post's content changes."),
|
||||
PhamePostTransaction::MAILTAG_COMMENT =>
|
||||
pht('Someone comments on a post.'),
|
||||
PhamePostTransaction::MAILTAG_OTHER =>
|
||||
pht('Other post activity not listed above occurs.'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getMailSubjectPrefix() {
|
||||
return '[Phame]';
|
||||
}
|
||||
|
||||
protected function supportsSearch() {
|
||||
return false;
|
||||
|
|
21
src/applications/phame/mail/PhamePostReplyHandler.php
Normal file
21
src/applications/phame/mail/PhamePostReplyHandler.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
final class PhamePostReplyHandler
|
||||
extends PhabricatorApplicationTransactionReplyHandler {
|
||||
|
||||
public function validateMailReceiver($mail_receiver) {
|
||||
if (!($mail_receiver instanceof PhamePost)) {
|
||||
throw new Exception(
|
||||
pht('Mail receiver is not a %s.', 'PhamePost'));
|
||||
}
|
||||
}
|
||||
|
||||
public function getObjectPrefix() {
|
||||
return PhabricatorPhamePostPHIDType::TYPECONST;
|
||||
}
|
||||
|
||||
protected function shouldCreateCommentFromMailBody() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ final class PhamePost extends PhameDAO
|
|||
protected $configData;
|
||||
protected $datePublished;
|
||||
protected $blogPHID;
|
||||
protected $mailKey;
|
||||
|
||||
private $blog;
|
||||
|
||||
|
@ -102,6 +103,7 @@ final class PhamePost extends PhameDAO
|
|||
'title' => 'text255',
|
||||
'phameTitle' => 'sort64',
|
||||
'visibility' => 'uint32',
|
||||
'mailKey' => 'bytes20',
|
||||
|
||||
// T6203/NULLABILITY
|
||||
// These seem like they should always be non-null?
|
||||
|
@ -135,6 +137,13 @@ final class PhamePost extends PhameDAO
|
|||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if (!$this->getMailKey()) {
|
||||
$this->setMailKey(Filesystem::readRandomCharacters(20));
|
||||
}
|
||||
return parent::save();
|
||||
}
|
||||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPhamePostPHIDType::TYPECONST);
|
||||
|
|
|
@ -8,6 +8,10 @@ final class PhamePostTransaction
|
|||
const TYPE_BODY = 'phame.post.body';
|
||||
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() {
|
||||
return 'phame';
|
||||
}
|
||||
|
@ -57,6 +61,27 @@ final class PhamePostTransaction
|
|||
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() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
$object_phid = $this->getObjectPHID();
|
||||
|
@ -69,7 +94,7 @@ final class PhamePostTransaction
|
|||
case self::TYPE_TITLE:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created this post.',
|
||||
'%s authored this post.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
} else {
|
||||
return pht(
|
||||
|
@ -80,12 +105,12 @@ final class PhamePostTransaction
|
|||
break;
|
||||
case self::TYPE_BODY:
|
||||
return pht(
|
||||
'%s updated the post\'s body.',
|
||||
'%s updated the blog post.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
break;
|
||||
case self::TYPE_PHAME_TITLE:
|
||||
return pht(
|
||||
'%s updated the post\'s phame title to "%s".',
|
||||
'%s updated the post\'s Phame title to "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
rtrim($new, '/'));
|
||||
break;
|
||||
|
@ -112,7 +137,7 @@ final class PhamePostTransaction
|
|||
case self::TYPE_TITLE:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created %s.',
|
||||
'%s authored %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else {
|
||||
|
@ -124,13 +149,13 @@ final class PhamePostTransaction
|
|||
break;
|
||||
case self::TYPE_BODY:
|
||||
return pht(
|
||||
'%s updated the body for %s.',
|
||||
'%s updated the blog post %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
break;
|
||||
case self::TYPE_PHAME_TITLE:
|
||||
return pht(
|
||||
'%s updated the phame title for %s.',
|
||||
'%s updated the Phame title for %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
break;
|
||||
|
@ -145,6 +170,23 @@ final class PhamePostTransaction
|
|||
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() {
|
||||
$old = $this->getOldValue();
|
||||
|
||||
|
|
Loading…
Reference in a new issue