Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The package doesn't let you use the NotificationSending listener in the app #19

Open
77media-creations opened this issue Aug 20, 2022 · 0 comments · May be fixed by #20
Open

The package doesn't let you use the NotificationSending listener in the app #19

77media-creations opened this issue Aug 20, 2022 · 0 comments · May be fixed by #20

Comments

@77media-creations
Copy link

77media-creations commented Aug 20, 2022

In my App/Providers/EventServiceProvider.php, I was listening to the NotificationSending event to do some checks before sending a notification as follows:

// namespace App\Providers;

protected $listen = [
    'Illuminate\Notifications\Events\NotificationSending' => [
        'App\Listeners\NotificationSendingListener',
    ],
];

After I installed this package, my App\Listeners\NotificationSendingListener does not seem to work.
I believe, it is being overridden by the package because the package is listening to the same event as:

// namespace LiranCo\NotificationSubscriptions\Providers;

protected $listen = [
    'Illuminate\Notifications\Events\NotificationSending' => [
        'LiranCo\NotificationSubscriptions\Listeners\NotificationSendingListener',
    ],
];

Maybe the same array key issue and the first value gets overridden by the second.

As the protected $listen is an associative array and using the same array key results in the last key-value pair actually being registered and ignoring any previous ones.

Found the reason causing this issue.

As we know the listener LiranCo\NotificationSubscriptions\Listeners\NotificationSendingListener checks if the user has unsubscribed from the notification and returns false which suppress that notification from being processed and sent out to the user. All good here.

But if user has not unsubscribed from the notification, this class returns $event.
And this causes the other listeners for the same event NotificationSending not processed.

Solution

Returning void return; instead of return $event in the handle method of LiranCo\NotificationSubscriptions\Listeners\NotificationSendingListener class resolves the issue.

@liran-co I'll open a pull request soon for a review.

@77media-creations 77media-creations changed the title This package overrides the NotificationSending listener The package doesn't let you use the NotificationSending listener in the app Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant