2015-05-15 22:07:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhamePostEditor
|
|
|
|
extends PhabricatorApplicationTransactionEditor {
|
|
|
|
|
|
|
|
public function getEditorApplicationClass() {
|
|
|
|
return 'PhabricatorPhameApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditorObjectsDescription() {
|
2015-11-07 02:40:13 +01:00
|
|
|
return pht('Phame Posts');
|
2015-05-15 22:07:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTransactionTypes() {
|
|
|
|
$types = parent::getTransactionTypes();
|
|
|
|
|
|
|
|
$types[] = PhamePostTransaction::TYPE_TITLE;
|
|
|
|
$types[] = PhamePostTransaction::TYPE_BODY;
|
2015-11-07 15:52:42 +01:00
|
|
|
$types[] = PhamePostTransaction::TYPE_VISIBILITY;
|
2015-11-10 06:20:35 +01:00
|
|
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
2015-05-15 22:07:45 +02:00
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionOldValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
|
|
return $object->getTitle();
|
|
|
|
case PhamePostTransaction::TYPE_BODY:
|
|
|
|
return $object->getBody();
|
2015-11-07 15:52:42 +01:00
|
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
|
|
return $object->getVisibility();
|
2015-05-15 22:07:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionNewValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
|
|
case PhamePostTransaction::TYPE_BODY:
|
2015-11-07 15:52:42 +01:00
|
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
2015-05-15 22:07:45 +02:00
|
|
|
return $xaction->getNewValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomInternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
|
|
return $object->setTitle($xaction->getNewValue());
|
|
|
|
case PhamePostTransaction::TYPE_BODY:
|
|
|
|
return $object->setBody($xaction->getNewValue());
|
2015-11-07 15:52:42 +01:00
|
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
|
|
if ($xaction->getNewValue() == PhameConstants::VISIBILITY_DRAFT) {
|
|
|
|
$object->setDatePublished(0);
|
2015-11-13 17:52:05 +01:00
|
|
|
} else {
|
2015-12-03 22:43:35 +01:00
|
|
|
$object->setDatePublished(PhabricatorTime::getNow());
|
2015-11-07 15:52:42 +01:00
|
|
|
}
|
|
|
|
return $object->setVisibility($xaction->getNewValue());
|
2015-05-15 22:07:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::applyCustomInternalTransaction($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomExternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
|
|
case PhamePostTransaction::TYPE_BODY:
|
2015-11-07 15:52:42 +01:00
|
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
2015-05-15 22:07:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::applyCustomExternalTransaction($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function validateTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
$type,
|
|
|
|
array $xactions) {
|
|
|
|
|
|
|
|
$errors = parent::validateTransaction($object, $type, $xactions);
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case PhamePostTransaction::TYPE_TITLE:
|
|
|
|
$missing = $this->validateIsEmptyTextField(
|
|
|
|
$object->getTitle(),
|
|
|
|
$xactions);
|
|
|
|
|
|
|
|
if ($missing) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
pht('Required'),
|
|
|
|
pht('Title is required.'),
|
|
|
|
nonempty(last($xactions), null));
|
|
|
|
|
|
|
|
$error->setIsMissingFieldError(true);
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldSendMail(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
array $xactions) {
|
2015-11-07 02:40:13 +01:00
|
|
|
if ($object->isDraft()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-05-15 22:07:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function shouldPublishFeedStory(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
array $xactions) {
|
2015-11-07 02:40:13 +01:00
|
|
|
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) {
|
2015-11-07 20:29:20 +01:00
|
|
|
$cc_phids = PhabricatorSubscribersQuery::loadSubscribersForPHID(
|
2015-11-07 02:40:13 +01:00
|
|
|
$blog_phid);
|
2015-11-07 20:29:20 +01:00
|
|
|
foreach ($cc_phids as $cc) {
|
|
|
|
$phids[] = $cc;
|
|
|
|
}
|
2015-11-07 02:40:13 +01:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
2015-12-02 22:27:56 +01:00
|
|
|
// We don't send mail if the object is a draft, and we only want
|
|
|
|
// to include the full body of the post on the either the
|
|
|
|
// first creation or if it was created as a draft, once it goes live.
|
2015-11-10 21:57:33 +01:00
|
|
|
if ($this->getIsNewObject()) {
|
|
|
|
$body->addRemarkupSection(null, $object->getBody());
|
2015-12-02 22:27:56 +01:00
|
|
|
} else {
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case PhamePostTransaction::TYPE_VISIBILITY:
|
|
|
|
if (!$object->isDraft()) {
|
|
|
|
$body->addRemarkupSection(null, $object->getBody());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 21:57:33 +01:00
|
|
|
}
|
|
|
|
|
2015-11-07 02:40:13 +01:00
|
|
|
$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."),
|
2015-12-05 19:01:24 +01:00
|
|
|
PhamePostTransaction::MAILTAG_SUBSCRIBERS =>
|
|
|
|
pht("A post's subscribers change."),
|
2015-11-07 02:40:13 +01:00
|
|
|
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]';
|
2015-05-15 22:07:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function supportsSearch() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|