Set notification settings per user and user groups
romainpoirier opened this issue · comments
What are you trying to do?
I'm using the Comments plugin only in a requireLogin
area of the website.
I would like that each (non-admin) user can set its settings preference on front-end for notificationAuthorEnabled
+ notificationReplyEnabled
.
Is there any way to do so individually out of the box, or any event that would trigger or block the sending of this email if the preference is checked/unchecked for a specific user?
To go one step further, I'm also looking for a notificationAdminEnabled
setting, but that would be sending to a special user group that are not admins but just moderators.
I also would like that they're able to set the settings preferences as explained previously, but for an equivalent of notificationAdminEnabled
.
What's your proposed solution?
No suggestion, but open for discussion.
Additional context
No response
You'd have to create a lightswitch field to allows users to manage this, and add it to user elements. You could then hook into the notification events to fire $event->isValid = false;
depending on the current user's account setting.
Excellent! Thank you, I'll test this out.
Thank you, I was able to make it works with this (where userNotificationsComments
is a lightswitch):
Event::on(CommentsService::class, CommentsService::EVENT_BEFORE_SEND_REPLY_EMAIL, function(EmailEvent $event) {
// Prevent sending
if (!empty($event->user->id ?? null)) {
if (empty(Craft::$app->users->getUserById($event->user->id)->userNotificationsComments)) {
$event->isValid = false;
}
}
});