From dad7c65bf56384480be7c18e02fdc01ea67cf1ff Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 15 Feb 2013 17:10:51 -0800 Subject: [PATCH] Fix some bot issues Summary: - Deprecate differentialnotification in favor of feednotification; it's strictly better. - Fix feed notification + channels. - Fix rendering of new-style stories (pholio, macro), which currently fatal. Test Plan: See chatlog. Reviewers: codeblock, indiefan Reviewed By: codeblock CC: aran Differential Revision: https://secure.phabricator.com/D4981 --- ...ricatorApplicationTransactionFeedStory.php | 5 ++ ...atorBotDifferentialNotificationHandler.php | 53 +++---------------- .../PhabricatorBotFeedNotificationHandler.php | 6 ++- 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/src/applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php b/src/applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php index 0a04a29380..9a5f5b0ec5 100644 --- a/src/applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php +++ b/src/applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php @@ -48,4 +48,9 @@ class PhabricatorApplicationTransactionFeedStory return $view; } + public function renderText() { + // TODO: This is grotesque; the feed notification handler relies on it. + return strip_tags($this->renderView()->render()); + } + } diff --git a/src/infrastructure/daemon/bot/handler/PhabricatorBotDifferentialNotificationHandler.php b/src/infrastructure/daemon/bot/handler/PhabricatorBotDifferentialNotificationHandler.php index 3a252cfc5e..2eddba29ad 100644 --- a/src/infrastructure/daemon/bot/handler/PhabricatorBotDifferentialNotificationHandler.php +++ b/src/infrastructure/daemon/bot/handler/PhabricatorBotDifferentialNotificationHandler.php @@ -1,55 +1,18 @@ getConfig('notification.actions'); - - if (!$this->skippedOldEvents) { - // Since we only want to post notifications about new events, skip - // everything that's happened in the past when we start up so we'll - // only process real-time events. - foreach ($iterator as $event) { - // Ignore all old events. - } - $this->skippedOldEvents = true; - return; - } - - foreach ($iterator as $event) { - $data = $event->getData(); - if (!$data || ($show !== null && !in_array($data['action'], $show))) { - continue; - } - - $actor_phid = $data['actor_phid']; - $phids = array($actor_phid); - $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); - $verb = DifferentialAction::getActionPastTenseVerb($data['action']); - - $actor_name = $handles[$actor_phid]->getName(); - $message_body = - "{$actor_name} {$verb} revision D".$data['revision_id']."."; - - $channels = $this->getConfig('notification.channels', array()); - foreach ($channels as $channel) { - $this->writeMessage( - id(new PhabricatorBotMessage()) - ->setCommand('MESSAGE') - ->setTarget($channel) - ->setBody($message_body)); - } + static $notified; + if (!$notified) { + phlog( + 'PhabricatorBotDifferentialNotificationHandler is deprecated, use '. + 'PhabricatorBotFeedNotificationHandler instead.'); + $notified = true; } } diff --git a/src/infrastructure/daemon/bot/handler/PhabricatorBotFeedNotificationHandler.php b/src/infrastructure/daemon/bot/handler/PhabricatorBotFeedNotificationHandler.php index abec6a5664..eb4c5c6151 100644 --- a/src/infrastructure/daemon/bot/handler/PhabricatorBotFeedNotificationHandler.php +++ b/src/infrastructure/daemon/bot/handler/PhabricatorBotFeedNotificationHandler.php @@ -149,7 +149,11 @@ final class PhabricatorBotFeedNotificationHandler } $channels = $this->getConfig('join'); - foreach ($channels as $channel) { + foreach ($channels as $channel_name) { + + $channel = id(new PhabricatorBotChannel()) + ->setName($channel_name); + $this->writeMessage( id(new PhabricatorBotMessage()) ->setCommand('MESSAGE')