Commit 0d338b6f authored by Benjamin Neff's avatar Benjamin Neff
Browse files

don't create notifications if the notification-actor is ignored

Also move "shareable hidden"-logic to AlsoCommented, because it is the
only one that needs it. And write some specs for mentioned and started
sharing notifications.

Fixes #6294
parent f4459488
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class Notification < ActiveRecord::Base
  end

  def self.concatenate_or_create(recipient, target, actor)
    return nil if suppress_notification?(recipient, target)
    return nil if suppress_notification?(recipient, actor)

    find_or_initialize_by(recipient: recipient, target: target, unread: true).tap do |notification|
      notification.actors |= [actor]
@@ -42,12 +42,14 @@ class Notification < ActiveRecord::Base
    end
  end

  def self.create_notification(recipient_id, target, actor)
    create(recipient_id: recipient_id, target: target, actors: [actor])
  def self.create_notification(recipient, target, actor)
    return nil if suppress_notification?(recipient, actor)

    create(recipient: recipient, target: target, actors: [actor])
  end

  private_class_method def self.suppress_notification?(recipient, post)
    post.is_a?(Post) && recipient.is_shareable_hidden?(post)
  private_class_method def self.suppress_notification?(recipient, actor)
    recipient.blocks.where(person: actor).exists?
  end

  def self.types
+3 −2
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@ module Notifications
      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|
        concatenate_or_create(recipient, commentable, actor)
          .try {|notification| notification.email_the_user(comment, actor) }
        next if recipient.is_shareable_hidden?(commentable)

        concatenate_or_create(recipient, commentable, actor).try(:email_the_user, comment, actor)
      end
    end
  end
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ module Notifications

        next if recipient == actor || !(mentionable.public || recipient_user_ids.include?(recipient.owner_id))

        create_notification(recipient.owner_id, mention, actor).email_the_user(mention, actor)
        create_notification(recipient.owner, mention, actor).try(:email_the_user, mention, actor)
      end
    end
  end
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ module Notifications
      return unless reshare.root.present? && reshare.root.author.local?

      actor = reshare.author
      concatenate_or_create(reshare.root.author.owner, reshare.root, actor).email_the_user(reshare, actor)
      concatenate_or_create(reshare.root.author.owner, reshare.root, actor).try(:email_the_user, reshare, actor)
    end
  end
end
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ module Notifications

    def self.notify(contact, _recipient_user_ids)
      sender = contact.person
      create_notification(contact.user_id, sender, sender).email_the_user(sender, sender)
      create_notification(contact.user, sender, sender).try(:email_the_user, sender, sender)
    end

    def contact
Loading