mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 15:38:37 +00:00
07c8c0afcf
It is the notifier implementation's responsibility to check the user's notification preferences before sending a notification. This adds the check. Change-Id: I4b7fd7ea444f5a6db6d79fadb48a440d4fdf0ac9
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace EchoPush;
|
|
|
|
use CentralIdLookup;
|
|
use EchoAttributeManager;
|
|
use EchoEvent;
|
|
use JobQueueGroup;
|
|
use User;
|
|
|
|
class PushNotifier {
|
|
|
|
/**
|
|
* Submits a notification derived from an Echo event to each push notifications service
|
|
* subscription found for a user, via a configured service handler implementation
|
|
* @param User $user
|
|
* @param EchoEvent $event
|
|
*/
|
|
public static function notifyWithPush( User $user, EchoEvent $event ): void {
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
$userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' );
|
|
if ( in_array( $event->getType(), $userEnabledEvents ) ) {
|
|
JobQueueGroup::singleton()->push( self::createJobForUser( $user ) );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @return NotificationRequestJob
|
|
*/
|
|
private static function createJobForUser( User $user ): NotificationRequestJob {
|
|
$centralId = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
|
|
$params = [ 'centralId' => $centralId ];
|
|
return new NotificationRequestJob( 'EchoPushNotificationRequest', $params );
|
|
}
|
|
|
|
}
|