Sha256: 3f554db843baadbee264d4f9d9c867b86251dbfebedf387339e0c2a4fce68f80

Contents?: true

Size: 948 Bytes

Versions: 38

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module Thredded
  class NotifyPrivateTopicUsers
    def initialize(private_post)
      @post = private_post
      @private_topic = private_post.postable
    end

    def run
      Thredded.notifiers.each do |notifier|
        notifiable_users = targeted_users(notifier)
        notifier.new_private_post(@post, notifiable_users) if notifiable_users.present?
      end
    end

    def targeted_users(notifier)
      users = private_topic.users.includes(:thredded_notifications_for_private_topics) - [post.user]
      users = only_those_with_this_notifier_enabled(users, notifier)
      users
    end

    private

    attr_reader :post, :private_topic

    def only_those_with_this_notifier_enabled(users, notifier)
      users.select do |user|
        Thredded::NotificationsForPrivateTopics
          .detect_or_default(user.thredded_notifications_for_private_topics, notifier).enabled?
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
thredded-0.15.4 app/commands/thredded/notify_private_topic_users.rb
thredded-0.15.3 app/commands/thredded/notify_private_topic_users.rb
thredded-0.15.2 app/commands/thredded/notify_private_topic_users.rb
thredded-0.15.1 app/commands/thredded/notify_private_topic_users.rb
threddedDANIEL-0.14.5 app/commands/thredded/notify_private_topic_users.rb
thredded-0.14.4 app/commands/thredded/notify_private_topic_users.rb
thredded-0.14.3 app/commands/thredded/notify_private_topic_users.rb
thredded-0.14.2 app/commands/thredded/notify_private_topic_users.rb
thredded-0.14.1 app/commands/thredded/notify_private_topic_users.rb
thredded-0.14.0 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.8 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.7 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.6 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.5 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.4 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.3 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.2 app/commands/thredded/notify_private_topic_users.rb
thredded-0.13.1 app/commands/thredded/notify_private_topic_users.rb