jenkins-bot has submitted this change and it was merged.

Change subject: Move remaining usage of EchoGetDefaultNotifiedUsers into 
UserLocator
......................................................................


Move remaining usage of EchoGetDefaultNotifiedUsers into UserLocator

Change-Id: Ib321dfbd993d7e5fd22a189d7f46bf3d9fa6b409
---
M Flow.php
M includes/Import/Postprocessor/LqtNotifications.php
M includes/Notifications/Controller.php
M includes/Notifications/Notifications.php
M includes/Notifications/UserLocator.php
5 files changed, 114 insertions(+), 111 deletions(-)

Approvals:
  Sbisson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Flow.php b/Flow.php
index 8c0308c..63d77ab 100644
--- a/Flow.php
+++ b/Flow.php
@@ -166,7 +166,6 @@
 
 // Echo integration
 $wgHooks['BeforeCreateEchoEvent'][] = 
'Flow\NotificationController::onBeforeCreateEchoEvent';
-$wgHooks['EchoGetDefaultNotifiedUsers'][] = 
'Flow\NotificationController::getDefaultNotifiedUsers';
 $wgHooks['EchoGetBundleRules'][] = 
'Flow\NotificationController::onEchoGetBundleRules';
 
 // Beta feature Flow on user talk page
diff --git a/includes/Import/Postprocessor/LqtNotifications.php 
b/includes/Import/Postprocessor/LqtNotifications.php
index 896d2ae..fabb203 100644
--- a/includes/Import/Postprocessor/LqtNotifications.php
+++ b/includes/Import/Postprocessor/LqtNotifications.php
@@ -49,17 +49,7 @@
         * of determining users to notify so they can be replaced with this 
class during imports.
         */
        protected function overrideUsersToNotify() {
-               global $wgHooks, $wgEchoNotifications;
-
-               // Remove the hook subscriber that chooses users for some 
notifications
-               $idx = array_search(
-                       'Flow\NotificationController::getDefaultNotifiedUsers',
-                       $wgHooks['EchoGetDefaultNotifiedUsers']
-               );
-               if ( $idx !== false ) {
-                       unset( $wgHooks['EchoGetDefaultNotifiedUsers'][$idx] );
-               }
-
+               global $wgEchoNotifications;
 
                // Remove the user-locators that choose on a per-notification 
basis who
                // should be notified.
diff --git a/includes/Notifications/Controller.php 
b/includes/Notifications/Controller.php
index 365f010..8a55dde 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -165,7 +165,7 @@
         * @throws FlowException When $params contains unexpected types/values
         */
        public function notifyNewTopic( $params ) {
-               if ( ! class_exists( 'EchoEvent' ) ) {
+               if ( !class_exists( 'EchoEvent' ) ) {
                        // Nothing to do here.
                        return array();
                }
@@ -411,104 +411,6 @@
                        break;
                }
                return true;
-       }
-
-       /**
-        * Handler for EchoGetDefaultNotifiedUsers hook
-        *  Returns a list of User objects in the second param
-        *
-        * @param $event EchoEvent being triggered
-        * @param &$users Array of User objects.
-        * @return bool
-        */
-       public static function getDefaultNotifiedUsers( EchoEvent $event, 
&$users ) {
-               $extra = $event->getExtra();
-               switch ( $event->getType() ) {
-               case 'flow-mention':
-                       $mentionedUsers = $extra['mentioned-users'];
-
-                       // Ignore mention if the user gets another notification
-                       // already from the same flow event
-                       $ids = array();
-                       $topic = $extra['topic-workflow'];
-                       if ( $topic instanceof UUID ) {
-                               $ids[$topic->getAlphadecimal()] = $topic;
-                       }
-                       if ( isset( $extra['reply-to'] ) ) {
-                               if ( $extra['reply-to'] instanceof UUID ) {
-                                       
$ids[$extra['reply-to']->getAlphadecimal()] = $extra['reply-to'];
-                               } else {
-                                       wfDebugLog( 'Flow', __METHOD__ . ': 
Expected UUID but received ' . get_class( $extra['reply-to'] ) );
-                               }
-                       }
-                       $notifiedUsers = self::getCreatorsFromPostIDs( $ids );
-
-                       foreach( $mentionedUsers as $uid ) {
-                               if ( !isset( $notifiedUsers[$uid] ) ) {
-                                       $users[$uid] = User::newFromId( $uid );
-                               }
-                       }
-                       break;
-               case 'flow-topic-renamed':
-                       $users += self::getCreatorsFromPostIDs( array( 
$extra['topic-workflow'] ) );
-                       break;
-               case 'flow-post-edited':
-               case 'flow-post-moderated':
-                       if ( isset( $extra['reply-to'] ) ) {
-                               $postId = $extra['reply-to'];
-                       } else {
-                               $postId = $extra['post-id'];
-                       }
-                       if ( !$postId instanceof UUID ) {
-                               wfDebugLog( 'Flow', __METHOD__ . ': Non-UUID 
value provided' );
-                               break;
-                       }
-
-                       $users += self::getCreatorsFromPostIDs( array( $postId 
) );
-                       break;
-               default:
-                       // Do nothing
-               }
-               return true;
-       }
-
-       /**
-        * Retrieves the post creators from a set of posts.
-        * @param  array  $posts Array of UUIDs or hex representations
-        * @return array Associative array, of user ID => User object.
-        */
-       protected static function getCreatorsFromPostIDs( array $posts ) {
-               $users = array();
-               /** @var ManagerGroup $storage */
-               $storage = Container::get( 'storage' );
-
-               $user = new User;
-               $actionPermissions = new RevisionActionPermissions( 
Container::get( 'flow_actions' ), $user );
-
-               foreach ( $posts as $postId ) {
-                       $post = $storage->find(
-                               'PostRevision',
-                               array(
-                                       'rev_type_id' => UUID::create( $postId )
-                               ),
-                               array(
-                                       'sort' => 'rev_id',
-                                       'order' => 'DESC',
-                                       'limit' => 1
-                               )
-                       );
-
-                       $post = reset( $post );
-
-                       if ( $post && $actionPermissions->isAllowed( $post, 
'view' ) ) {
-                               $userid = $post->getCreatorId();
-                               if ( $userid ) {
-                                       $users[$userid] = User::newFromId( 
$userid );
-                               }
-                       }
-               }
-
-               return $users;
        }
 
        /**
diff --git a/includes/Notifications/Notifications.php 
b/includes/Notifications/Notifications.php
index 76466fd..4775d65 100644
--- a/includes/Notifications/Notifications.php
+++ b/includes/Notifications/Notifications.php
@@ -64,6 +64,9 @@
        ) + $notificationTemplate,
        'flow-post-edited' => array(
                'presentation-model' => 'Flow\\PostEditedPresentationModel',
+               'user-locators' => array(
+                       'Flow\\NotificationsUserLocator::locatePostAuthors',
+               ),
                'primary-link' => array(
                        'message' => 'flow-notification-link-text-view-post',
                        'destination' => 'flow-post'
@@ -86,6 +89,9 @@
        ) + $notificationTemplate,
        'flow-topic-renamed' => array(
                'presentation-model' => 'Flow\\TopicRenamedPresentationModel',
+               'user-locators' => array(
+                       'Flow\\NotificationsUserLocator::locateTopicAuthors',
+               ),
                'primary-link' => array(
                        'message' => 'flow-notification-link-text-view-post',
                        'destination' => 'flow-post'
@@ -100,6 +106,9 @@
        ) + $notificationTemplate,
        'flow-mention' => array(
                'presentation-model' => 'Flow\\MentionPresentationModel',
+               'user-locators' => array(
+                       'Flow\\NotificationsUserLocator::locateMentionedUsers',
+               ),
                'primary-link' => array(
                        'message' => 'notification-link-text-view-mention',
                        'destination' => 'flow-post'
diff --git a/includes/Notifications/UserLocator.php 
b/includes/Notifications/UserLocator.php
index 67e64a7..61737e3 100644
--- a/includes/Notifications/UserLocator.php
+++ b/includes/Notifications/UserLocator.php
@@ -4,6 +4,7 @@
 
 use EchoEvent;
 use EchoUserLocator;
+use Flow\Data\ManagerGroup;
 use Flow\Model\UUID;
 use Title;
 use User;
@@ -47,4 +48,106 @@
 
                return $users;
        }
+
+       /**
+        * @param EchoEvent $event
+        * @return User[]
+        */
+       public static function locateTopicAuthors( EchoEvent $event ) {
+               $workflowId = $event->getExtraParam( 'topic-workflow' );
+               if ( !$workflowId instanceof UUID ) {
+                       // something wrong; don't notify anyone
+                       return array();
+               }
+
+               return self::getCreatorsFromPostIDs( array( $workflowId ) );
+       }
+
+       /**
+        * @param EchoEvent $event
+        * @return User[]
+        */
+       public static function locatePostAuthors( EchoEvent $event ) {
+               $extra = $event->getExtra();
+
+               if ( isset( $extra['reply-to'] ) ) {
+                       $postId = $extra['reply-to'];
+               } else {
+                       $postId = $extra['post-id'];
+               }
+
+               if ( !$postId instanceof UUID ) {
+                       // something wrong; don't notify anyone
+                       return array();
+               }
+
+               return self::getCreatorsFromPostIDs( array( $postId ) );
+       }
+
+       /**
+        * @param EchoEvent $event
+        * @return array
+        */
+       public static function locateMentionedUsers( EchoEvent $event ) {
+               $mentionedUserIds = $event->getExtraParam( 'mentioned-users' );
+               if ( !$mentionedUserIds ) {
+                       return array();
+               }
+
+               // figure out which users may already receive a notification 
for this event because they're author,
+               // or because they're watching this topic
+               $notifiedUsers = array();
+               $locators = array( self::locatePostAuthors( $event ), 
self::locateUsersWatchingTopic( $event ) );
+               foreach ( $locators as $locator ) {
+                       /** @var User $user */
+                       foreach ( $locator as $user ) {
+                               $notifiedUsers[$user->getId()] = $user;
+                       }
+               }
+
+               // now subtract those that already receive another notification
+               $mentionedUserIds = array_diff( $mentionedUserIds, array_keys( 
$notifiedUsers ) );
+
+               return array_map( array( 'User', 'newFromId' ), 
$mentionedUserIds );
+       }
+
+       /**
+        * Retrieves the post creators from a set of posts.
+        *
+        * @param array $posts Array of UUIDs or hex representations
+        * @return User[] Associative array, of user ID => User object.
+        */
+       protected static function getCreatorsFromPostIDs( array $posts ) {
+               $users = array();
+               /** @var ManagerGroup $storage */
+               $storage = Container::get( 'storage' );
+
+               $user = new User;
+               $actionPermissions = new RevisionActionPermissions( 
Container::get( 'flow_actions' ), $user );
+
+               foreach ( $posts as $postId ) {
+                       $post = $storage->find(
+                               'PostRevision',
+                               array(
+                                       'rev_type_id' => UUID::create( $postId )
+                               ),
+                               array(
+                                       'sort' => 'rev_id',
+                                       'order' => 'DESC',
+                                       'limit' => 1
+                               )
+                       );
+
+                       $post = reset( $post );
+
+                       if ( $post && $actionPermissions->isAllowed( $post, 
'view' ) ) {
+                               $userid = $post->getCreatorId();
+                               if ( $userid ) {
+                                       $users[$userid] = User::newFromId( 
$userid );
+                               }
+                       }
+               }
+
+               return $users;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/265460
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib321dfbd993d7e5fd22a189d7f46bf3d9fa6b409
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Sbisson <sbis...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to