Sha256: 4255f7f84d35673a55b56def044ad8e365512e49a4194a254299390333b7857a

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true
module Thredded
  class NotifyFollowingUsers
    def initialize(post)
      @post = post
    end

    def run
      return if targeted_users.empty?
      PostMailer.post_notification(@post.id, targeted_users.map(&:email)).deliver_now
      MembersMarkedNotified.new(@post, targeted_users).run
    end

    def targeted_users
      @targeted_users ||= @post.postable.followers.reject { |u| u == @post.user }
      exclude_those_opting_out_of_followed_activity_notifications @targeted_users
    end

    private

    def exclude_those_opting_out_of_followed_activity_notifications(members)
      members.select do |member|
        member.thredded_user_preference.followed_topic_emails &&
          member.thredded_user_messageboard_preferences.in(@post.messageboard).followed_topic_emails
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thredded-0.8.4 app/commands/thredded/notify_following_users.rb
thredded-0.8.2 app/commands/thredded/notify_following_users.rb