1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-26 11:10:16 +01:00

Add ability to reply to Ponder Answer emails

Summary: Ref T9068, Ref T3846. Maybe fixes both, but I'm having issues testing email replies in a sandbox. Moves answer feed/mail generation to the AnswerEditor, hides it in QuestionEditor.

Test Plan: Write an answer, see feed story, check /mail/ for mail generation.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T3846, T9068

Differential Revision: https://secure.phabricator.com/D13905
This commit is contained in:
Chad Little 2015-08-17 10:22:54 -07:00
parent 6010e80e5c
commit ee8e436390
6 changed files with 67 additions and 62 deletions

View file

@ -3406,8 +3406,10 @@ phutil_register_library_map(array(
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
'PonderAnswerHasVotingUserEdgeType' => 'applications/ponder/edge/PonderAnswerHasVotingUserEdgeType.php',
'PonderAnswerHistoryController' => 'applications/ponder/controller/PonderAnswerHistoryController.php',
'PonderAnswerMailReceiver' => 'applications/ponder/mail/PonderAnswerMailReceiver.php',
'PonderAnswerPHIDType' => 'applications/ponder/phid/PonderAnswerPHIDType.php',
'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php',
'PonderAnswerReplyHandler' => 'applications/ponder/mail/PonderAnswerReplyHandler.php',
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
'PonderAnswerStatus' => 'applications/ponder/constants/PonderAnswerStatus.php',
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
@ -3442,7 +3444,6 @@ phutil_register_library_map(array(
'PonderRemarkupRule' => 'applications/ponder/remarkup/PonderRemarkupRule.php',
'PonderSchemaSpec' => 'applications/ponder/storage/PonderSchemaSpec.php',
'PonderSearchIndexer' => 'applications/ponder/search/PonderSearchIndexer.php',
'PonderTransactionFeedStory' => 'applications/ponder/feed/PonderTransactionFeedStory.php',
'PonderVotableInterface' => 'applications/ponder/storage/PonderVotableInterface.php',
'PonderVote' => 'applications/ponder/constants/PonderVote.php',
'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php',
@ -7607,8 +7608,10 @@ phutil_register_library_map(array(
'PonderAnswerEditor' => 'PonderEditor',
'PonderAnswerHasVotingUserEdgeType' => 'PhabricatorEdgeType',
'PonderAnswerHistoryController' => 'PonderController',
'PonderAnswerMailReceiver' => 'PhabricatorObjectMailReceiver',
'PonderAnswerPHIDType' => 'PhabricatorPHIDType',
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PonderAnswerReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PonderAnswerSaveController' => 'PonderController',
'PonderAnswerStatus' => 'PonderConstants',
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
@ -7654,7 +7657,6 @@ phutil_register_library_map(array(
'PonderRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'PonderSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PonderSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
'PonderTransactionFeedStory' => 'PhabricatorApplicationTransactionFeedStory',
'PonderVote' => 'PonderConstants',
'PonderVoteEditor' => 'PhabricatorEditor',
'PonderVotingUserHasAnswerEdgeType' => 'PhabricatorEdgeType',

View file

@ -177,30 +177,13 @@ final class PonderQuestionEditor
return true;
}
protected function getFeedStoryType() {
return 'PonderTransactionFeedStory';
}
protected function getFeedStoryData(
PhabricatorLiskDAO $object,
array $xactions) {
$data = parent::getFeedStoryData($object, $xactions);
$answer = $this->getAnswer();
if ($answer) {
$data['answerPHID'] = $answer->getPHID();
}
return $data;
}
protected function shouldImplyCC(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_ANSWERS:
return true;
return false;
}
return parent::shouldImplyCC($object, $xaction);
@ -209,7 +192,25 @@ final class PonderQuestionEditor
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_ANSWERS:
return false;
}
}
return true;
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PonderQuestionTransaction::TYPE_ANSWERS:
return false;
}
}
return true;
}
public function getMailTagsMap() {
@ -248,14 +249,6 @@ final class PonderQuestionEditor
$body->addRawSection($new);
}
}
// If the user gave an answer, add the answer text. Also update
// the header and uri to be more answer-specific.
if ($type == PonderQuestionTransaction::TYPE_ANSWERS) {
$answer = $this->getAnswer();
$body->addRawSection($answer->getContent());
$header = pht('ANSWER DETAIL');
$uri = $answer->getURI();
}
}
$body->addLinkSection(

View file

@ -1,14 +0,0 @@
<?php
final class PonderTransactionFeedStory
extends PhabricatorApplicationTransactionFeedStory {
public function getRequiredObjectPHIDs() {
$phids = parent::getRequiredObjectPHIDs();
$answer_phid = $this->getValue('answerPHID');
if ($answer_phid) {
$phids[] = $answer_phid;
}
return $phids;
}
}

View file

@ -0,0 +1,27 @@
<?php
final class PonderAnswerMailReceiver extends PhabricatorObjectMailReceiver {
public function isEnabled() {
$app_class = 'PhabricatorPonderApplication';
return PhabricatorApplication::isClassInstalled($app_class);
}
protected function getObjectPattern() {
return 'ANSR[1-9]\d*';
}
protected function loadObject($pattern, PhabricatorUser $viewer) {
$id = (int)trim($pattern, 'ANSR');
return id(new PonderAnswerQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
}
protected function getTransactionReplyHandler() {
return new PonderAnswerReplyHandler();
}
}

View file

@ -0,0 +1,16 @@
<?php
final class PonderAnswerReplyHandler
extends PhabricatorApplicationTransactionReplyHandler {
public function validateMailReceiver($mail_receiver) {
if (!($mail_receiver instanceof PonderAnswer)) {
throw new Exception(pht('Mail receiver is not a %s!', 'PonderAnswer'));
}
}
public function getObjectPrefix() {
return 'ANSR';
}
}

View file

@ -336,23 +336,4 @@ final class PonderQuestionTransaction
return reset($add);
}
/**
* Generally, the answer object is only available if the transaction
* type is `self::TYPE_ANSWERS`.
*
* Some stories - notably ones made before D7027 - will be of the more
* generic @{class:PhabricatorApplicationTransactionFeedStory}. These
* poor stories won't have the PonderAnswer loaded, and thus will have
* less cool information.
*/
private function getNewAnswerObject(PhabricatorFeedStory $story) {
if ($story instanceof PonderTransactionFeedStory) {
$answer_phid = $this->getNewAnswerPHID();
if ($answer_phid) {
return $story->getObject($answer_phid);
}
}
return null;
}
}