mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Only create notifications that are wanted by the recipients
Also moving getUserEnabledEvents from EchoBackend to NotificationController since it has nothing to do with the backend. Bug: 47664 Change-Id: I4f9682b861d9f035ae45f206c37ec0ae1c09ab64
This commit is contained in:
parent
ccb93c653b
commit
5a4704e357
|
@ -12,6 +12,13 @@ class EchoNotifier {
|
||||||
public static function notifyWithNotification( $user, $event ) {
|
public static function notifyWithNotification( $user, $event ) {
|
||||||
global $wgEchoConfig, $wgEchoNotifications;
|
global $wgEchoConfig, $wgEchoNotifications;
|
||||||
|
|
||||||
|
// Only create the notification if the user wants to recieve that type
|
||||||
|
// of notification and they are eligible to recieve it. See bug 47664.
|
||||||
|
$userWebNotifications = EchoNotificationController::getUserEnabledEvents( $user, 'web' );
|
||||||
|
if ( !in_array( $event->getType(), $userWebNotifications ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
EchoNotification::create( array( 'user' => $user, 'event' => $event ) );
|
||||||
|
|
||||||
self::logEvent( $user, $event, 'web' );
|
self::logEvent( $user, $event, 'web' );
|
||||||
|
|
|
@ -30,6 +30,29 @@ class EchoNotificationController {
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the enabled events for a user, which excludes user-dismissed events
|
||||||
|
* from the general enabled events
|
||||||
|
* @param $user User
|
||||||
|
* @param $outputFormat string
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getUserEnabledEvents( $user, $outputFormat ) {
|
||||||
|
global $wgEchoNotifications;
|
||||||
|
$eventTypesToLoad = $wgEchoNotifications;
|
||||||
|
foreach ( $eventTypesToLoad as $eventType => $eventData ) {
|
||||||
|
$category = self::getNotificationCategory( $eventType );
|
||||||
|
// Make sure the user is eligible to recieve this type of notification
|
||||||
|
if ( !self::getCategoryEligibility( $user, $category ) ) {
|
||||||
|
unset( $eventTypesToLoad[$eventType] );
|
||||||
|
}
|
||||||
|
if ( !$user->getOption( 'echo-subscriptions-' . $outputFormat . '-' . $category ) ) {
|
||||||
|
unset( $eventTypesToLoad[$eventType] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return array_keys( $eventTypesToLoad );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See if a user is eligible to recieve a certain type of notification
|
* See if a user is eligible to recieve a certain type of notification
|
||||||
* (based on user groups, not user preferences)
|
* (based on user groups, not user preferences)
|
||||||
|
|
|
@ -42,7 +42,7 @@ class MWDbEchoBackend extends MWEchoBackend {
|
||||||
public function loadNotifications( $user, $limit, $timestamp, $offset, $outputFormat = 'web' ) {
|
public function loadNotifications( $user, $limit, $timestamp, $offset, $outputFormat = 'web' ) {
|
||||||
$dbr = MWEchoDbFactory::getDB( DB_SLAVE );
|
$dbr = MWEchoDbFactory::getDB( DB_SLAVE );
|
||||||
|
|
||||||
$eventTypesToLoad = $this->getUserEnabledEvents( $user, $outputFormat );
|
$eventTypesToLoad = EchoNotificationController::getUserEnabledEvents( $user, $outputFormat );
|
||||||
if ( !$eventTypesToLoad ) {
|
if ( !$eventTypesToLoad ) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ class MWDbEchoBackend extends MWEchoBackend {
|
||||||
$dbSource = DB_SLAVE;
|
$dbSource = DB_SLAVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
$eventTypesToLoad = $this->getUserEnabledEvents( $user, 'web' );
|
$eventTypesToLoad = EchoNotificationController::getUserEnabledEvents( $user, 'web' );
|
||||||
|
|
||||||
if ( !$eventTypesToLoad ) {
|
if ( !$eventTypesToLoad ) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -25,30 +25,6 @@ abstract class MWEchoBackend {
|
||||||
return new $className();
|
return new $className();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the enabled events for a user, which excludes user-dismissed events
|
|
||||||
* from the general enabled events
|
|
||||||
* @param $user User
|
|
||||||
* @param $outputFormat string
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getUserEnabledEvents( $user, $outputFormat ) {
|
|
||||||
global $wgEchoNotifications;
|
|
||||||
$eventTypesToLoad = $wgEchoNotifications;
|
|
||||||
foreach ( $eventTypesToLoad as $eventType => $eventData ) {
|
|
||||||
$category = EchoNotificationController::getNotificationCategory( $eventType );
|
|
||||||
// Make sure the user is eligible to recieve this type of notification
|
|
||||||
if ( !EchoNotificationController::getCategoryEligibility( $user, $category ) ) {
|
|
||||||
unset( $eventTypesToLoad[$eventType] );
|
|
||||||
}
|
|
||||||
if ( !$user->getOption( 'echo-subscriptions-' . $outputFormat . '-' . $category ) ) {
|
|
||||||
unset( $eventTypesToLoad[$eventType] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_keys( $eventTypesToLoad );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new notification
|
* Create a new notification
|
||||||
* @param $row array
|
* @param $row array
|
||||||
|
|
Loading…
Reference in a new issue