Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F1546
PhabricatorBotFeedNotificationHandler_now_filters_IRC_notifications_by_projects
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
dereckson
Apr 4 2015, 12:46
2015-04-04 12:46:42 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
PhabricatorBotFeedNotificationHandler_now_filters_IRC_notifications_by_projects
View Options
--- PhabricatorBotFeedNotificationHandler.php.orig 2015-04-04 14:39:41.733038612 +0200
+++ PhabricatorBotFeedNotificationHandler.php 2015-04-04 14:39:08.554318370 +0200
@@ -83,6 +83,91 @@
return false;
}
+ /**
+ * Gets the list of the projects attached to an object
+ *
+ * @param string $objectPHID the object's PHID
+ * @return Array the name of the projects attached to the specified object PHID
+ */
+ private static function getProjects ($objectPHID) {
+ //Query projects attached to this object.
+ $PHIDs = self::getProjectsPHIDs($objectPHID);
+ $projects = id(new $class())
+ ->loadAllWhere('phid IN (%Ls)',
+ $PHIDs);
+
+ //Returns an array with project names
+ if (!count($projects)) {
+ return [];
+ }
+
+ $projectsNames = [];
+ foreach ($project in $projects) {
+ $projectsNames[] = $project->name;
+ }
+ return $projectsNames;
+ }
+
+ /**
+ * Gets projects' PHIDs attached to an object
+ *
+ * @param string $objectPHID the object's PHID
+ * @return Array the PHIDs of the projects attached to the specified object PHID
+ */
+ private static function getProjectsPHIDs ($objectPHID) {
+ $object_type = phid_get_type($objectPHID);
+ switch ($object_type) {
+ case 'DREV':
+ $class = 'DifferentialRevision';
+ break;
+
+ case 'TASK':
+ $class = 'ManiphestTask';
+ break;
+
+ case 'CMIT':
+ $class = 'PhabricatorRepositoryCommit';
+ break;
+
+ default:
+ return [];
+ }
+
+ $object = id(new $class())
+ ->loadOneWhere('phid = %s',
+ $objectPHID);
+ if ($object) {
+ if ($class == "PhabricatorRepositoryCommit" || $class == "DifferentialRevision") {
+ return $object->getRepository()->getProjectPHIDs();
+ }
+ return $object->getProjectPHIDs();
+ }
+
+ return [];
+ }
+
+ /**
+ * Determines if the story message should be shown on the specified channel
+ *
+ * @param string $channel the channel we may notify
+ * @param string $channel the $storyObjectPHID the story object's PHID
+ * @return boolean true if the message should be shown; otherwise, false.
+ */
+ private function shouldShowStoryOnChannel ($channel, $storyObjectPHID) {
+ $filters = $this->getConfig('notification.filtersByProject');
+ if ($filters === null || !array_key_exists($channel, $filters)) {
+ return true;
+ }
+ $projects = $filters[$channel];
+ $storyObjectProjects = $this->getProjectsPHIDs($storyObjectPHID); //TODO: replace by getProjects
+ foreach ($projects as $project) {
+ if (in_array($project, $storyObjectProjects)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public function receiveMessage(PhabricatorBotMessage $message) {
return;
}
@@ -167,6 +252,10 @@
$channel = id(new PhabricatorBotChannel())
->setName($channel_name);
+ if (!$this->shouldShowStoryOnChannel($channel_name, $story['objectPHID'])) {
+ continue;
+ }
+
$this->writeMessage(
id(new PhabricatorBotMessage())
->setCommand('MESSAGE')
@@ -176,5 +265,4 @@
}
}
}
-
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1526
Default Alt Text
PhabricatorBotFeedNotificationHandler_now_filters_IRC_notifications_by_projects (3 KB)
Attached To
Mode
P45 PhabricatorBotFeedNotificationHandler now filters IRC notifications by projects
Attached
Detach File
Event Timeline
Log In to Comment