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-1.1.0 app/commands/thredded/notify_private_topic_users.rb
thredded-1.0.1 app/commands/thredded/notify_private_topic_users.rb
thredded-1.0.0 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.16 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.15 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.14 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.13 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.12 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.11 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.10 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.9 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.8 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.7 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.6 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.5 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.4 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.3 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.1 app/commands/thredded/notify_private_topic_users.rb
thredded-0.16.0 app/commands/thredded/notify_private_topic_users.rb
thredded-0.15.5 app/commands/thredded/notify_private_topic_users.rb