Sha256: ee11f609154b70ad64589c5172e3a9fe4138085d560b13e8bca3ff9d986481d1

Contents?: true

Size: 887 Bytes

Versions: 3

Compression:

Stored size: 887 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
      user_names = Thredded::AtNotificationExtractor.new(post.content).run
      autofollowers = post.readers_from_user_names(user_names).to_a
      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.notify_on_mention? &&
          member.thredded_user_messageboard_preferences.in(post.messageboard).notify_on_mention?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thredded-0.6.0 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.5.1 app/commands/thredded/autofollow_mentioned_users.rb
thredded-0.5.0 app/commands/thredded/autofollow_mentioned_users.rb