-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
base: develop
Are you sure you want to change the base?
Changes from 5 commits
4be89fc
048b204
e55b876
8abf74c
8e221db
0b0e146
1c4a897
dede976
04dcbf6
790117c
f92775b
79031b3
80759b7
90678ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,13 +2,17 @@ | |||||||||||||||
|
||||||||||||||||
class NotificationService | ||||||||||||||||
NOTIFICATION_TYPES = { | ||||||||||||||||
Comment => [Notifications::MentionedInComment, Notifications::CommentOnPost, Notifications::AlsoCommented], | ||||||||||||||||
Like => [Notifications::Liked], | ||||||||||||||||
StatusMessage => [Notifications::MentionedInPost], | ||||||||||||||||
Conversation => [Notifications::PrivateMessage], | ||||||||||||||||
Message => [Notifications::PrivateMessage], | ||||||||||||||||
Reshare => [Notifications::Reshared], | ||||||||||||||||
Contact => [Notifications::StartedSharing] | ||||||||||||||||
Comment => [ | ||||||||||||||||
Notifications::MentionedInCommentService, | ||||||||||||||||
Notifications::CommentOnPostService, | ||||||||||||||||
Notifications::AlsoCommentedService | ||||||||||||||||
], | ||||||||||||||||
Like => [Notifications::LikedService], | ||||||||||||||||
StatusMessage => [Notifications::MentionedInPostService], | ||||||||||||||||
Conversation => [Notifications::PrivateMessageService], | ||||||||||||||||
Message => [Notifications::PrivateMessageService], | ||||||||||||||||
Reshare => [Notifications::ResharedService], | ||||||||||||||||
Contact => [Notifications::StartedSharingService] | ||||||||||||||||
}.freeze | ||||||||||||||||
|
||||||||||||||||
NOTIFICATIONS_JSON_TYPES = { | ||||||||||||||||
|
@@ -51,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still would write this as guard clause and the
Suggested change
|
||||||||||||||||
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 | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class AlsoCommentedService | ||
def self.notify(comment, _) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/AbcSize: Assignment Branch Condition size for notify is too high. [<4, 20, 2> 20.49/20] |
||
actor = comment.author | ||
commentable = comment.commentable | ||
recipient_ids = commentable.participants.local.where.not(id: [commentable.author_id, actor.id]).pluck(:owner_id) | ||
|
||
User.where(id: recipient_ids).find_each do |recipient| | ||
next if recipient.is_shareable_hidden?(commentable) || mention_notification_exists?(comment, recipient.person) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I don't know what's the best solution for this. The mentions notification already handles mails being disabled for mentions, and then sends a normal commented mail. But when we would for example check here, if there is a mention in the comment, then we wouldn't send duplicate mails (but still one mail, as that's already handled in the mentions notification service ... but we wouldn't send an in-app notification if that's disabled for mentions (unless we also move that logic to the mentions notification service as well?) But then we have even more logic in the mentions notification service, that's kinda duplicated? 🤷♂️ Maybe you have an idea how to solve that the best? |
||
|
||
Notifications::AlsoCommented | ||
.concatenate_or_create(recipient, commentable, actor) | ||
|
||
NotificationService.new(recipient).mail( | ||
Workers::Mail::AlsoCommented, | ||
recipient.id, | ||
actor.id, | ||
comment.id | ||
) | ||
Comment on lines
+16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit duplicate that the job.perform_async(user.id, *args) |
||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class CommentOnPostService | ||
def self.notify(comment, _) | ||
actor = comment.author | ||
commentable_author = comment.commentable.author | ||
|
||
return unless commentable_author.local? && actor != commentable_author | ||
return if mention_notification_exists?(comment, commentable_author) | ||
|
||
recipient = commentable_author.owner | ||
Notifications::CommentOnPost | ||
.concatenate_or_create(recipient, comment.commentable, actor) | ||
|
||
NotificationService.new(recipient).mail( | ||
Workers::Mail::CommentOnPost, | ||
recipient.id, | ||
actor.id, | ||
comment.id | ||
) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class ContactsBirthdayService | ||
def self.notify(contact, _=nil) | ||
recipient = contact.user | ||
actor = contact.person | ||
Notifications::ContactsBirthday | ||
.create_notification(recipient, actor, actor) | ||
|
||
NotificationService.new(recipient).mail( | ||
Workers::Mail::ContactsBirthday, | ||
recipient.id, | ||
actor.id, | ||
actor.id | ||
) | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename that
NOTIFICATION_SERVICES
now?