Skip to content

Commit dad7c65

Browse files
author
epriestley
committed
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
1 parent 02f7ece commit dad7c65

File tree

3 files changed

+18
-46
lines changed

3 files changed

+18
-46
lines changed

src/applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ public function renderView() {
4848
return $view;
4949
}
5050

51+
public function renderText() {
52+
// TODO: This is grotesque; the feed notification handler relies on it.
53+
return strip_tags($this->renderView()->render());
54+
}
55+
5156
}

src/infrastructure/daemon/bot/handler/PhabricatorBotDifferentialNotificationHandler.php

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,18 @@
11
<?php
22

33
/**
4-
* @group irc
4+
* @deprecated
55
*/
66
final class PhabricatorBotDifferentialNotificationHandler
7-
extends PhabricatorBotHandler {
8-
9-
private $skippedOldEvents;
7+
extends PhabricatorBotHandler {
108

119
public function receiveMessage(PhabricatorBotMessage $message) {
12-
return;
13-
}
14-
15-
public function runBackgroundTasks() {
16-
$iterator = new PhabricatorTimelineIterator('ircdiffx', array('difx'));
17-
$show = $this->getConfig('notification.actions');
18-
19-
if (!$this->skippedOldEvents) {
20-
// Since we only want to post notifications about new events, skip
21-
// everything that's happened in the past when we start up so we'll
22-
// only process real-time events.
23-
foreach ($iterator as $event) {
24-
// Ignore all old events.
25-
}
26-
$this->skippedOldEvents = true;
27-
return;
28-
}
29-
30-
foreach ($iterator as $event) {
31-
$data = $event->getData();
32-
if (!$data || ($show !== null && !in_array($data['action'], $show))) {
33-
continue;
34-
}
35-
36-
$actor_phid = $data['actor_phid'];
37-
$phids = array($actor_phid);
38-
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
39-
$verb = DifferentialAction::getActionPastTenseVerb($data['action']);
40-
41-
$actor_name = $handles[$actor_phid]->getName();
42-
$message_body =
43-
"{$actor_name} {$verb} revision D".$data['revision_id'].".";
44-
45-
$channels = $this->getConfig('notification.channels', array());
46-
foreach ($channels as $channel) {
47-
$this->writeMessage(
48-
id(new PhabricatorBotMessage())
49-
->setCommand('MESSAGE')
50-
->setTarget($channel)
51-
->setBody($message_body));
52-
}
10+
static $notified;
11+
if (!$notified) {
12+
phlog(
13+
'PhabricatorBotDifferentialNotificationHandler is deprecated, use '.
14+
'PhabricatorBotFeedNotificationHandler instead.');
15+
$notified = true;
5316
}
5417
}
5518

src/infrastructure/daemon/bot/handler/PhabricatorBotFeedNotificationHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public function runBackgroundTasks() {
149149
}
150150

151151
$channels = $this->getConfig('join');
152-
foreach ($channels as $channel) {
152+
foreach ($channels as $channel_name) {
153+
154+
$channel = id(new PhabricatorBotChannel())
155+
->setName($channel_name);
156+
153157
$this->writeMessage(
154158
id(new PhabricatorBotMessage())
155159
->setCommand('MESSAGE')

0 commit comments

Comments
 (0)