mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-04 04:09:00 +00:00
33 lines
855 B
PHP
33 lines
855 B
PHP
|
<?php
|
||
|
|
||
|
namespace EchoPush;
|
||
|
|
||
|
use CentralIdLookup;
|
||
|
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 {
|
||
|
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 );
|
||
|
}
|
||
|
|
||
|
}
|