Sha256: 26754c4fb513f054df90f9c261ed7141a5380e35219e3cbc4ff577459ea30599

Contents?: true

Size: 938 Bytes

Versions: 4

Compression:

Stored size: 938 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|
        NotificationsForPrivateTopics
          .detect_or_default(user.thredded_notifications_for_private_topics, notifier).enabled?
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thredded-0.13.0 app/commands/thredded/notify_private_topic_users.rb
thredded-0.12.4 app/commands/thredded/notify_private_topic_users.rb
thredded-0.12.3 app/commands/thredded/notify_private_topic_users.rb
thredded-0.12.2 app/commands/thredded/notify_private_topic_users.rb