Bsitu has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/87018


Change subject: Topic creator should be notified on post reply/edit/moderation
......................................................................

Topic creator should be notified on post reply/edit/moderation

Change-Id: Ife2e63855a334d031b3b94191fd22b0c7bd9c4c9
---
M Flow.i18n.php
M includes/Notifications/Controller.php
M includes/Notifications/Formatter.php
3 files changed, 49 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/18/87018/1

diff --git a/Flow.i18n.php b/Flow.i18n.php
index d451c61..0095ead 100644
--- a/Flow.i18n.php
+++ b/Flow.i18n.php
@@ -84,7 +84,7 @@
        // Notification message
        'flow-notification-reply' => '$1 {{GENDER:$1|replied}} to your [$5 
post] in $2 on "$4".',
        'flow-notification-reply-bundle' => '$1 and $5 
{{PLURAL:$6|other|others}} {{GENDER:$1|replied}} to your [$4 post] in $2 on 
"$3".',
-       'flow-notification-edit' => '$1 {{GENDER:$1|edited}} your [$5 post] in 
$2 on [[$3|$4]].',
+       'flow-notification-edit' => '$1 {{GENDER:$1|edited}} [$5 post] in $2 on 
[[$3|$4]].',
        'flow-notification-newtopic' => '$1 {{GENDER:$1|created}} a [$5 new 
topic] on [[$2|$3]]: $4.',
        'flow-notification-rename' => '$1 {{GENDER:$1|changed}} the title of 
[$2 $3] to "$4" on [[$5|$6]].',
        'flow-notification-mention' => '$1 {{GENDER:$1|mentioned}} you in their 
[$2 post] in "$3" on "$4"',
diff --git a/includes/Notifications/Controller.php 
b/includes/Notifications/Controller.php
index f5dee8e..22b902d 100644
--- a/includes/Notifications/Controller.php
+++ b/includes/Notifications/Controller.php
@@ -351,17 +351,37 @@
                        }
                        break;
                case 'flow-topic-renamed':
-                       $postId = $extra['topic-workflow'];
+                       $users += self::getUserForPost( array( 
$extra['topic-workflow'] ) );
+                       break;
                case 'flow-post-reply':
                case 'flow-post-edited':
                case 'flow-post-moderated':
                        if ( isset( $extra['reply-to'] ) ) {
                                $postId = $extra['reply-to'];
-                       } elseif ( !isset( $postId ) || !$postId ) {
+                       } else {
                                $postId = $extra['post-id'];
                        }
 
-                       $post = $storage->find(
+                       $ids = array( $postId );
+                       $container = Container::getContainer();
+                       $treeRepository = $container['repository.tree'];
+                       $rootId = $treeRepository->findRoot( $postId );
+                       if ( $rootId->getBinary() != $postId->getBinary() ) {
+                               $ids[] = $rootId;
+                       }
+                       $users += self::getUserForPost( $ids );
+                       break;
+               default:
+                       // Do nothing
+               }
+               return true;
+       }
+
+       protected static function getUserForPost( array $posts ) {
+               $users = array();
+               $container = Container::getContainer();
+               foreach ( $posts as $postId ) {
+                       $post = $container['storage']->find(
                                'PostRevision',
                                array(
                                        'tree_rev_descendant_id' => 
UUID::create( $postId )
@@ -382,10 +402,7 @@
                                        $users[$user->getId()] = $user;
                                }
                        }
-                       break;
-               default:
-                       // Do nothing
                }
-               return true;
-       }
+               return $users;
+        }
 }
\ No newline at end of file
diff --git a/includes/Notifications/Formatter.php 
b/includes/Notifications/Formatter.php
index aab9a12..1b4fd0f 100644
--- a/includes/Notifications/Formatter.php
+++ b/includes/Notifications/Formatter.php
@@ -1,6 +1,7 @@
 <?php
 
 use Flow\UrlGenerator;
+use Flow\Container;
 
 class FlowCommentFormatter extends EchoBasicFormatter {
        protected $urlGenerator;
@@ -39,7 +40,7 @@
                                $event->getTitle(),
                                'view',
                                array(
-                                       'topic[postId]' => $postId->getHex(),
+                                       'topic[postId]' => 
$this->getRelevantPostIdForNotification( $event, $user, $postId )->getHex(),
                                        'workflow' => 
$extra['topic-workflow']->getHex(),
                                )
                        );
@@ -93,7 +94,7 @@
                                if ( $post && $flow && $title ) {
                                        list( $target, $query ) =
                                                $urlGenerator->generateUrlData( 
$flow, array(
-                                                       'topic[postId]' => 
$post->getHex(),
+                                                       'topic[postId]' => 
$this->getRelevantPostIdForNotification( $event, $user, $post )->getHex(),
                                                ) );
                                }
                                break;
@@ -124,4 +125,24 @@
 
                return $this->urlGenerator;
        }
+
+       /**
+        * Get the relevant post for notification, use topic id instead 
individual
+        * post id for bundle message on post-reply, post-edit, 
post-moderatation
+        */
+       protected function getRelevantPostIdForNotification( $event, $user, 
$postId ) {
+               $notifTypes = array( 'flow-post-reply', 'flow-post-edited', 
'flow-post-moderated' );
+               $container = Container::getContainer();
+               $storage = $container['storage'];
+
+               // Use the topic id for notification if this is a bundle message
+               if ( in_array( $event->getType(), $notifTypes ) ) {
+                       if ( $this->bundleData['use-bundle'] ) {
+                               $treeRepository = $container['repository.tree'];
+                               $postId = $treeRepository->findRoot( $postId );
+                       }
+               }
+
+               return $postId;
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ife2e63855a334d031b3b94191fd22b0c7bd9c4c9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to