| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Push; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\Model\Event; |
| 6 |
use MediaWiki\Extension\Notifications\Services; |
| 7 |
use MediaWiki\MediaWikiServices; |
| 8 |
use MediaWiki\User\UserIdentity; |
| 9 |
|
| 10 |
class PushNotifier { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public static function notifyWithPush( UserIdentity $user, Event $event ): void { |
| 19 |
$attributeManager = Services::getInstance()->getAttributeManager(); |
| 20 |
$userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' ); |
| 21 |
if ( in_array( $event->getType(), $userEnabledEvents ) ) { |
| 22 |
MediaWikiServices::getInstance()->getJobQueueGroup()->push( self::createJob( $user, $event ) ); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
private static function createJob( UserIdentity $user, ?Event $event = null ): NotificationRequestJob { |
| 32 |
$centralId = Utils::getPushUserId( $user ); |
| 33 |
$params = [ 'centralId' => $centralId ]; |
| 34 |
|
| 35 |
if ( $event !== null ) { |
| 36 |
$params['eventId'] = $event->getId(); |
| 37 |
$params['eventType'] = $event->getType(); |
| 38 |
if ( $event->getAgent() !== null ) { |
| 39 |
$params['agent'] = $event->getAgent()->getId(); |
| 40 |
} |
| 41 |
} |
| 42 |
return new NotificationRequestJob( 'EchoPushNotificationRequest', $params ); |
| 43 |
} |
| 44 |
|
| 45 |
} |
| 46 |
|
| 47 |
class_alias( PushNotifier::class, 'EchoPush\\PushNotifier' ); |