Sha256: df2932a6145e2cefcbfb3c78a26c0e3c26fa4df06b87aa4458e3c5463ba61e39

Contents?: true

Size: 828 Bytes

Versions: 6

Compression:

Stored size: 828 Bytes

Contents

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

    def run
      autofollowers.each do |user|
        Thredded::UserTopicFollow.create_unless_exists(user.id, post.postable_id, :mentioned)
      end
    end

    def autofollowers
      autofollowers = Thredded::AtNotificationExtractor.new(post).run
      autofollowers.delete(post.user)
      exclude_those_opting_out_of_at_notifications autofollowers
    end

    private

    attr_reader :post

    def exclude_those_opting_out_of_at_notifications(members)
      members.select do |member|
        member.thredded_user_preference.follow_topics_on_mention? &&
          member.thredded_user_messageboard_preferences.in(post.messageboard).follow_topics_on_mention?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
thredded-0.10.1 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.10.0 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.9.4 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.9.3 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.9.2 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.9.1 app/commands/thredded/autofollow_mentioned_users.rb