1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Expose all application mail receivers

Summary:
Fixes T7199. This still isn't a shining example of perfect code, but the raw amount of copy/paste is much lower than it used to be.

  - Reduce code duplication between existing receivers.
  - Expose receiving objects in help menus where appropriate.
  - Connect some "TODO" receivers.

Test Plan:
  - Sent mail to every supported object type.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7199

Differential Revision: https://secure.phabricator.com/D12249
This commit is contained in:
epriestley 2015-04-01 11:01:21 -07:00
parent 52eab87608
commit eb81fd1562
25 changed files with 177 additions and 135 deletions

View file

@ -391,7 +391,6 @@ phutil_register_library_map(array(
'DifferentialLintField' => 'applications/differential/customfield/DifferentialLintField.php',
'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php',
'DifferentialLocalCommitsView' => 'applications/differential/view/DifferentialLocalCommitsView.php',
'DifferentialMail' => 'applications/differential/mail/DifferentialMail.php',
'DifferentialManiphestTasksField' => 'applications/differential/customfield/DifferentialManiphestTasksField.php',
'DifferentialModernHunk' => 'applications/differential/storage/DifferentialModernHunk.php',
'DifferentialParseCacheGarbageCollector' => 'applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php',
@ -976,7 +975,7 @@ phutil_register_library_map(array(
'LegalpadDocumentSignatureSearchEngine' => 'applications/legalpad/query/LegalpadDocumentSignatureSearchEngine.php',
'LegalpadDocumentSignatureVerificationController' => 'applications/legalpad/controller/LegalpadDocumentSignatureVerificationController.php',
'LegalpadDocumentSignatureViewController' => 'applications/legalpad/controller/LegalpadDocumentSignatureViewController.php',
'LegalpadMockMailReceiver' => 'applications/legalpad/mail/LegalpadMockMailReceiver.php',
'LegalpadMailReceiver' => 'applications/legalpad/mail/LegalpadMailReceiver.php',
'LegalpadObjectNeedsSignatureEdgeType' => 'applications/legalpad/edge/LegalpadObjectNeedsSignatureEdgeType.php',
'LegalpadReplyHandler' => 'applications/legalpad/mail/LegalpadReplyHandler.php',
'LegalpadSchemaSpec' => 'applications/legalpad/storage/LegalpadSchemaSpec.php',
@ -3442,6 +3441,7 @@ phutil_register_library_map(array(
'ConpherenceThread' => array(
'ConpherenceDAO',
'PhabricatorPolicyInterface',
'PhabricatorApplicationTransactionInterface',
),
'ConpherenceThreadIndexer' => 'PhabricatorSearchDocumentIndexer',
'ConpherenceThreadListView' => 'AphrontView',
@ -3577,7 +3577,6 @@ phutil_register_library_map(array(
'DifferentialLegacyHunk' => 'DifferentialHunk',
'DifferentialLintField' => 'DifferentialCustomField',
'DifferentialLocalCommitsView' => 'AphrontView',
'DifferentialMail' => 'PhabricatorMail',
'DifferentialManiphestTasksField' => 'DifferentialCoreCustomField',
'DifferentialModernHunk' => 'DifferentialHunk',
'DifferentialParseCacheGarbageCollector' => 'PhabricatorGarbageCollector',
@ -4229,7 +4228,7 @@ phutil_register_library_map(array(
'LegalpadDocumentSignatureSearchEngine' => 'PhabricatorApplicationSearchEngine',
'LegalpadDocumentSignatureVerificationController' => 'LegalpadController',
'LegalpadDocumentSignatureViewController' => 'LegalpadController',
'LegalpadMockMailReceiver' => 'PhabricatorObjectMailReceiver',
'LegalpadMailReceiver' => 'PhabricatorObjectMailReceiver',
'LegalpadObjectNeedsSignatureEdgeType' => 'PhabricatorEdgeType',
'LegalpadReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'LegalpadSchemaSpec' => 'PhabricatorConfigSchemaSpec',

View file

@ -38,12 +38,6 @@ final class PhabricatorAuditCommentEditor extends PhabricatorEditor {
return array_keys($phids);
}
public static function newReplyHandlerForCommit($commit) {
$reply_handler = new PhabricatorAuditReplyHandler();
$reply_handler->setMailReceiver($commit);
return $reply_handler;
}
public static function getMailThreading(
PhabricatorRepository $repository,
PhabricatorRepositoryCommit $commit) {

View file

@ -21,17 +21,8 @@ final class PhabricatorAuditMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = PhabricatorAuditCommentEditor::newReplyHandlerForCommit($object);
$handler->setActor($sender);
$handler->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
$handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new PhabricatorAuditReplyHandler();
}
}

View file

@ -65,4 +65,14 @@ final class PhabricatorConpherenceApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
// TODO: Conpherence threads don't currently support any commands directly,
// so the documentation page we end up generating is empty and funny
// looking. Add support here once we support "!add", "!leave", "!topic",
// or whatever else.
return array();
}
}

View file

@ -23,18 +23,8 @@ final class ConpherenceThreadMailReceiver
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = id(new ConpherenceReplyHandler())
->setMailReceiver($object);
$handler->setActor($sender);
$handler->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
$handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new ConpherenceReplyHandler();
}
}

View file

@ -1,7 +1,9 @@
<?php
final class ConpherenceThread extends ConpherenceDAO
implements PhabricatorPolicyInterface {
implements
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface {
protected $title;
protected $isRoom = 0;
@ -290,4 +292,26 @@ final class ConpherenceThread extends ConpherenceDAO
return $icon;
}
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
public function getApplicationTransactionEditor() {
return new ConpherenceEditor();
}
public function getApplicationTransactionObject() {
return $this;
}
public function getApplicationTransactionTemplate() {
return new ConpherenceTransaction();
}
public function willRenderTimeline(
PhabricatorApplicationTransactionView $timeline,
AphrontRequest $request) {
return $timeline;
}
}

View file

@ -1,12 +0,0 @@
<?php
abstract class DifferentialMail extends PhabricatorMail {
public static function newReplyHandlerForRevision(
DifferentialRevision $revision) {
$reply_handler = new DifferentialReplyHandler();
$reply_handler->setMailReceiver($revision);
return $reply_handler;
}
}

View file

@ -24,17 +24,8 @@ final class DifferentialRevisionMailReceiver
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = DifferentialMail::newReplyHandlerForRevision($object);
$handler->setActor($sender);
$handler->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
$handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new DifferentialReplyHandler();
}
}

View file

@ -148,4 +148,17 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
return array(
'commit' => array(
'name' => pht('Email Commands: Commits'),
'header' => pht('Interacting with Commits'),
'object' => new PhabricatorRepositoryCommit(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'commits and audits in Diffusion.'),
),
);
}
}

View file

@ -96,4 +96,17 @@ final class PhabricatorFilesApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
return array(
'file' => array(
'name' => pht('Email Commands: Files'),
'header' => pht('Interacting with Files'),
'object' => new PhabricatorFile(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'files.'),
),
);
}
}

View file

@ -20,18 +20,8 @@ final class FileMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = id(new FileReplyHandler())
->setMailReceiver($object);
$handler->setActor($sender);
$handler->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
$handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new FileReplyHandler();
}
}

View file

@ -80,4 +80,17 @@ final class PhabricatorLegalpadApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
return array(
'document' => array(
'name' => pht('Email Commands: Legalpad Documents'),
'header' => pht('Interacting with Legalpad Documents'),
'object' => new LegalpadDocument(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'documents in Legalpad.'),
),
);
}
}

View file

@ -1,6 +1,6 @@
<?php
final class LegalpadMockMailReceiver extends PhabricatorObjectMailReceiver {
final class LegalpadMailReceiver extends PhabricatorObjectMailReceiver {
public function isEnabled() {
$app_class = 'PhabricatorLegalpadApplication';
@ -21,18 +21,8 @@ final class LegalpadMockMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = id(new LegalpadReplyHandler())
->setMailReceiver($object)
->setActor($sender)
->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
return $handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new LegalpadReplyHandler();
}
}

View file

@ -57,4 +57,17 @@ final class PhabricatorMacroApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
return array(
'macro' => array(
'name' => pht('Email Commands: Macros'),
'header' => pht('Interacting with Macros'),
'object' => new PhabricatorFileImageMacro(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'image macros.'),
),
);
}
}

View file

@ -20,13 +20,8 @@ final class PhabricatorMacroMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
// TODO: For now, we just drop this mail on the floor.
protected function getTransactionReplyHandler() {
return new PhabricatorMacroReplyHandler();
}
}

View file

@ -24,18 +24,8 @@ final class ManiphestTaskMailReceiver extends PhabricatorObjectMailReceiver {
return head($results);
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = new ManiphestReplyHandler();
$handler->setMailReceiver($object);
$handler->setActor($sender);
$handler->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
$handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new ManiphestReplyHandler();
}
}

View file

@ -39,10 +39,26 @@ abstract class PhabricatorObjectMailReceiver extends PhabricatorMailReceiver {
return $this;
}
abstract protected function processReceivedObjectMail(
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender);
PhabricatorUser $sender) {
$handler = $this->getTransactionReplyHandler();
if ($handler) {
return $handler
->setMailReceiver($object)
->setActor($sender)
->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())
->processEmail($mail);
}
throw new PhutilMethodNotImplementedException();
}
protected function getTransactionReplyHandler() {
return null;
}
public function loadMailReceiverObject($pattern, PhabricatorUser $viewer) {
return $this->loadObject($pattern, $viewer);

View file

@ -82,4 +82,17 @@ final class PhabricatorPasteApplication extends PhabricatorApplication {
return $items;
}
public function getMailCommandObjects() {
return array(
'paste' => array(
'name' => pht('Email Commands: Pastes'),
'header' => pht('Interacting with Pastes'),
'object' => new PhabricatorPaste(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'pastes.'),
),
);
}
}

View file

@ -20,18 +20,8 @@ final class PasteMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
$handler = id(new PasteReplyHandler())
->setMailReceiver($object);
$handler->setActor($sender);
$handler->setExcludeMailRecipientPHIDs(
$mail->loadExcludeMailRecipientPHIDs());
$handler->processEmail($mail);
protected function getTransactionReplyHandler() {
return new PasteReplyHandler();
}
}

View file

@ -77,4 +77,17 @@ final class PhabricatorPholioApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
return array(
'mock' => array(
'name' => pht('Email Commands: Mocks'),
'header' => pht('Interacting with Pholio Mocks'),
'object' => new PholioMock(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'mocks in Pholio.'),
),
);
}
}

View file

@ -20,12 +20,8 @@ final class PholioMockMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
// TODO: For now, we just drop this mail on the floor.
protected function getTransactionReplyHandler() {
return new PholioReplyHandler();
}
}

View file

@ -66,4 +66,17 @@ final class PhabricatorPonderApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
return array(
'question' => array(
'name' => pht('Email Commands: Questions'),
'header' => pht('Interacting with Ponder Questions'),
'object' => new PonderQuestion(),
'summary' => pht(
'This page documents the commands you can use to interact with '.
'questions in Ponder.'),
),
);
}
}

View file

@ -20,13 +20,8 @@ final class PonderQuestionMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
// TODO: For now, we just drop this mail on the floor.
protected function getTransactionReplyHandler() {
return new PonderQuestionReplyHandler();
}
}

View file

@ -78,4 +78,11 @@ final class PhabricatorReleephApplication extends PhabricatorApplication {
);
}
public function getMailCommandObjects() {
// TODO: Pull requests don't implement any interfaces which give them
// meaningful commands, so don't expose ReleephRequest here for now.
// Once we add relevant commands, return it here.
return array();
}
}

View file

@ -20,13 +20,8 @@ final class ReleephRequestMailReceiver extends PhabricatorObjectMailReceiver {
->executeOne();
}
protected function processReceivedObjectMail(
PhabricatorMetaMTAReceivedMail $mail,
PhabricatorLiskDAO $object,
PhabricatorUser $sender) {
// TODO: For now, we just drop this mail on the floor.
protected function getTransactionReplyHandler() {
return new ReleephRequestReplyHandler();
}
}