Differential D19861 Diff 47440 src/applications/notification/controller/PhabricatorNotificationTestController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/notification/controller/PhabricatorNotificationTestController.php
| <?php | <?php | ||||
| final class PhabricatorNotificationTestController | final class PhabricatorNotificationTestController | ||||
| extends PhabricatorNotificationController { | extends PhabricatorNotificationController { | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
| $story_type = 'PhabricatorNotificationTestFeedStory'; | if ($request->validateCSRF()) { | ||||
| $story_data = array( | $message_text = pht( | ||||
| 'title' => pht( | |||||
| 'This is a test notification, sent at %s.', | 'This is a test notification, sent at %s.', | ||||
| phabricator_datetime(time(), $viewer)), | phabricator_datetime(time(), $viewer)); | ||||
| ); | |||||
| $viewer_phid = $viewer->getPHID(); | |||||
| // NOTE: Because we don't currently show you your own notifications, make | // NOTE: Currently, the FeedStoryPublisher explicitly filters out | ||||
| // sure this comes from a different PHID. | // notifications about your own actions. Send this notification from | ||||
| // a different actor to get around this. | |||||
| $application_phid = id(new PhabricatorNotificationsApplication()) | $application_phid = id(new PhabricatorNotificationsApplication()) | ||||
| ->getPHID(); | ->getPHID(); | ||||
| // TODO: When it's easier to get these buttons to render as forms, this | $xactions = array(); | ||||
| // would be slightly nicer as a more standard isFormPost() check. | |||||
| if ($request->validateCSRF()) { | $xactions[] = id(new PhabricatorUserTransaction()) | ||||
| id(new PhabricatorFeedStoryPublisher()) | ->setTransactionType( | ||||
| ->setStoryType($story_type) | PhabricatorUserNotifyTransaction::TRANSACTIONTYPE) | ||||
| ->setStoryData($story_data) | ->setNewValue($message_text) | ||||
| ->setStoryTime(time()) | ->setForceNotifyPHIDs(array($viewer->getPHID())); | ||||
| ->setStoryAuthorPHID($application_phid) | |||||
| ->setRelatedPHIDs(array($viewer_phid)) | $editor = id(new PhabricatorUserTransactionEditor()) | ||||
| ->setPrimaryObjectPHID($viewer_phid) | ->setActor($viewer) | ||||
| ->setSubscribedPHIDs(array($viewer_phid)) | ->setActingAsPHID($application_phid) | ||||
| ->setNotifyAuthor(true) | ->setContentSourceFromRequest($request); | ||||
| ->publish(); | |||||
| $editor->applyTransactions($viewer, $xactions); | |||||
| } | } | ||||
| return id(new AphrontAjaxResponse()); | return id(new AphrontAjaxResponse()); | ||||
| } | } | ||||
| } | } | ||||