-
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 1 commit
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class AlsoCommentedService | ||
def self.notify(comment, _) | ||
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) | ||
|
||
Notifications::AlsoCommented | ||
.concatenate_or_create(recipient, commentable, actor) | ||
.try(:email_the_user, comment, actor) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 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) | ||
|
||
Notifications::CommentOnPost | ||
.concatenate_or_create(commentable_author.owner, comment.commentable, actor) | ||
.email_the_user(comment, actor) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class ContactsBirthdayService | ||
def self.notify(contact, _=nil) | ||
recipient = contact.user | ||
actor = contact.person | ||
create_notification(recipient, actor, actor).try(:email_the_user, actor, actor) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class LikedService | ||
def self.notify(like, _) | ||
actor = like.author | ||
target_author = like.target.author | ||
|
||
return unless like.target_type == "Post" && target_author.local? && actor != target_author | ||
|
||
Notifications::Liked | ||
.concatenate_or_create(target_author.owner, like.target, actor) | ||
.email_the_user(like, actor) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class MentionedInCommentService | ||
def self.model | ||
Notifications::MentionedInComment | ||
end | ||
|
||
def self.notify(mentionable, recipient_user_ids) | ||
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. [<6, 27, 6> 28.3/20] 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.
|
||
actor = mentionable.author | ||
relevant_mentions = filter_mentions( | ||
mentionable.mentions.local.where.not(person: actor), | ||
mentionable, | ||
recipient_user_ids | ||
) | ||
|
||
relevant_mentions.each do |mention| | ||
recipient = mention.person.owner | ||
next if model.exists?(recipient: recipient, target: mention) | ||
|
||
model | ||
.create_notification(recipient, mention, actor) | ||
.try(:email_the_user, mention, actor) | ||
end | ||
end | ||
|
||
def self.filter_mentions(mentions, mentionable, _recipient_user_ids) | ||
mentions.includes(:person).merge(Person.allowed_to_be_mentioned_in_a_comment_to(mentionable.parent)) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class MentionedInPostService | ||
def self.model | ||
Notifications::MentionedInPost | ||
end | ||
|
||
def self.notify(mentionable, recipient_user_ids) | ||
actor = mentionable.author | ||
relevant_mentions = filter_mentions( | ||
mentionable.mentions.local.where.not(person: actor), | ||
mentionable, | ||
recipient_user_ids | ||
) | ||
|
||
relevant_mentions.each do |mention| | ||
recipient = mention.person.owner | ||
next if model.exists?(recipient: recipient, target: mention) | ||
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. This relies on the notification entity existing, which isn't the case if in-app notifications are disabled. This was a workaround for when posts were received twice, no duplicate notifications were created (#7721). I don't remember all the details and reasons, but I don't know/remember why a post should be received again if it already exists, maybe that was a workaround for when a post was created incomplete because of the scenario described here where some data for posts was missing, and receiving them again properly through the federation, would add this missing data. But if that gets fixed so it fetches the posts using federation code, it doesn't need to be received a second time, as it was already complete the first time. That would then also solve the problem of duplicate notifications, without needing the check for them here (as I don't know how otherwise this should be solved for not sending duplicate mails). 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. @SuperTux88 is it enough to do the proper fetching using federation code? It seems quite easy. Commit: ecb3923 Didn't look at the tests yet. 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.
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.
Yes, that's theoretically all that's needed, but the But you can even improve that a little bit more by just using But yes, basically that, it's fairly easy 👍 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. And the exception should be |
||
|
||
model | ||
.create_notification(recipient, mention, actor) | ||
.try(:email_the_user, mention, actor) | ||
end | ||
end | ||
|
||
def self.filter_mentions(mentions, mentionable, recipient_user_ids) | ||
return mentions if mentionable.public | ||
|
||
mentions.where(person: Person.where(owner_id: recipient_user_ids).ids) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class PrivateMessageService | ||
def self.notify(object, _) | ||
case object | ||
when Conversation | ||
object.messages.each {|message| notify_message(message) } | ||
when Message | ||
notify_message(object) | ||
end | ||
end | ||
|
||
private_class_method def self.notify_message(message) | ||
recipient_ids = message.conversation.participants.local.where.not(id: message.author_id).pluck(:owner_id) | ||
User.where(id: recipient_ids).find_each do |recipient| | ||
message.increase_unread(recipient) | ||
Notifications::PrivateMessage | ||
.new(recipient: recipient) | ||
Comment on lines
+18
to
+19
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. This isn't needed, this was only a workaround because the mail needed the object, but it's never persisted. |
||
.email_the_user(message, message.author) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class ResharedService | ||
def self.notify(reshare, _) | ||
return unless reshare.root.present? && reshare.root.author.local? | ||
|
||
actor = reshare.author | ||
Notifications::Reshared | ||
.concatenate_or_create(reshare.root.author.owner, reshare.root, actor) | ||
.try(:email_the_user, reshare, actor) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Notifications | ||
class StartedSharingService | ||
def self.notify(contact, _) | ||
sender = contact.person | ||
Notifications::StartedSharing | ||
.create_notification(contact.user, sender, sender) | ||
.try(:email_the_user, sender, sender) | ||
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?