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

[WIP] Turn off notifications for posts' reactions #3391

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/jobs/notifications/new_reaction_job.rb
Expand Up @@ -14,7 +14,11 @@ def perform(reaction_data, receiver_data, service = Notifications::Reactions::Se
return unless %w[User Organization].include?(receiver_klass)

receiver = receiver_klass.constantize.find_by(id: receiver_data.fetch(:id))
service.call(reaction_data, receiver) if receiver
service.call(reaction_data, receiver) if shoud_send_reaction_notification?(receiver, receiver_data)
end

def shoud_send_reaction_notification?(receiver, receiver_data)
receiver && receiver_data.fetch(:post_reaction_notifications, true)
end
end
end
1 change: 1 addition & 0 deletions app/policies/user_policy.rb
Expand Up @@ -74,6 +74,7 @@ def permitted_attributes
editor_version
email_unread_notifications
mobile_comment_notifications
post_reaction_notifications
employer_name
employer_url
employment_title
Expand Down
9 changes: 8 additions & 1 deletion app/views/users/_notifications.html.erb
@@ -1,5 +1,12 @@
<h3>Email Notification Settings</h3>
<%= form_for(@user) do |f| %>
<h3>Notifications</h3>
<div class="checkbox-field">
<div class="sub-field">
<%= f.check_box :post_reaction_notifications %>
<%= f.label :post_reaction_notifications, "Notify me when someone reacts to my posts" %>
</div>
</div>
<h3>Email Notification Settings</h3>
<div class="checkbox-field">
<div class="sub-field">
<%= f.check_box :email_newsletter %>
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Expand Up @@ -986,6 +986,7 @@
t.string "medium_url"
t.datetime "membership_started_at"
t.boolean "mobile_comment_notifications", default: true
t.boolean "post_reaction_notifications", default: true
t.integer "monthly_dues", default: 0
t.string "mostly_work_with"
t.string "name"
Expand Down