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

Add in-app notification configuration #8375

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 0 additions & 8 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,6 @@ def perform_export_photos!
end

######### Mailer #######################
def mail(job, *args)
return unless job.present?
pref = job.to_s.gsub('Workers::Mail::', '').underscore
email_enabled = (disable_mail == false) &&
NotificationSettingsService.new(self).email_enabled?(pref)

job.perform_async(*args) if email_enabled
end

def send_confirm_email
return if unconfirmed_email.blank?
Expand Down
12 changes: 12 additions & 0 deletions app/services/notification_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,24 @@ def update_status_by_guid(guid, is_read_status)
true
end

def mail(job, *args)
return if job.blank?

pref = job.to_s.gsub("Workers::Mail::", "").underscore
email_enabled = (user.disable_mail == false) &&
NotificationSettingsService.new(user).email_enabled?(pref)

job.perform_async(*args) if email_enabled
Comment on lines +62 to +65
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still would write this as guard clause and the == false doesn't make a lot of sense (see old comment)

Suggested change
email_enabled = (user.disable_mail == false) &&
NotificationSettingsService.new(user).email_enabled?(pref)
job.perform_async(*args) if email_enabled
return if user.disable_mail || NotificationSettingsService.new(user).email_disabled?(pref)
job.perform_async(*args)

end

def notify(object, recipient_user_ids)
notification_types(object).each {|type| type.notify(object, recipient_user_ids) }
end

private

attr_reader :user

def notification_types(object)
NOTIFICATION_TYPES.fetch(object.class, [])
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/also_commented_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.notify(comment, _)
Notifications::AlsoCommented
.concatenate_or_create(recipient, commentable, actor)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::AlsoCommented,
recipient.id,
actor.id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/comment_on_post_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.notify(comment, _)
Notifications::CommentOnPost
.concatenate_or_create(recipient, comment.commentable, actor)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::CommentOnPost,
recipient.id,
actor.id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/contacts_birthday_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.notify(contact, _=nil)
Notifications::ContactsBirthday
.create_notification(recipient, actor, actor)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::ContactsBirthday,
recipient.id,
actor.id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/liked_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.notify(like, _)
Notifications::Liked
.concatenate_or_create(recipient, like.target, actor)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::Liked,
recipient.id,
actor.id,
Expand Down
7 changes: 6 additions & 1 deletion app/services/notifications/mentioned_in_comment_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def self.notify(mentionable, recipient_user_ids)
Workers::Mail::AlsoCommented
end

recipient.mail(mail_job, recipient.id, actor.id, mention.id)
NotificationService.new(recipient).mail(
mail_job,
recipient.id,
actor.id,
mention.id
)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/mentioned_in_post_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.notify(mentionable, recipient_user_ids)
model
.create_notification(recipient, mention, actor)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::Mentioned,
recipient.id,
actor.id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/private_message_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.notify(object, _)
Notifications::PrivateMessage
.new(recipient: recipient)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::PrivateMessage,
recipient.id,
message.author.id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/reshared_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.notify(reshare, _)
Notifications::Reshared
.concatenate_or_create(recipient, reshare.root, actor)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::Reshared,
recipient.id,
actor.id,
Expand Down
2 changes: 1 addition & 1 deletion app/services/notifications/started_sharing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.notify(contact, _)
Notifications::StartedSharing
.create_notification(recipient, sender, sender)

recipient.mail(
NotificationService.new(recipient).mail(
Workers::Mail::StartedSharing,
recipient.id,
sender.id,
Expand Down