Push: Check that the event type is enabled before scheduling job

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
This commit is contained in:
Michael Holloway 2020-06-12 16:27:54 -04:00
parent 6bd34b6765
commit 07c8c0afcf

View file

@ -3,6 +3,7 @@
namespace EchoPush; namespace EchoPush;
use CentralIdLookup; use CentralIdLookup;
use EchoAttributeManager;
use EchoEvent; use EchoEvent;
use JobQueueGroup; use JobQueueGroup;
use User; use User;
@ -16,8 +17,12 @@ class PushNotifier {
* @param EchoEvent $event * @param EchoEvent $event
*/ */
public static function notifyWithPush( User $user, EchoEvent $event ): void { 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 ) ); JobQueueGroup::singleton()->push( self::createJobForUser( $user ) );
} }
}
/** /**
* @param User $user * @param User $user