Class: Thredded::AutofollowUsers

Inherits:
Object
  • Object
show all
Defined in:
app/commands/thredded/autofollow_users.rb

Instance Method Summary collapse

Constructor Details

#initialize(post) ⇒ AutofollowUsers

Returns a new instance of AutofollowUsers.



5
6
7
# File 'app/commands/thredded/autofollow_users.rb', line 5

def initialize(post)
  @post = post
end

Instance Method Details

#mentioned_usersArray<Thredded.user_class>

Returns:



16
17
18
# File 'app/commands/thredded/autofollow_users.rb', line 16

def mentioned_users
  @mentioned_users ||= Thredded::AtNotificationExtractor.new(post).run
end

#new_followersHash<Thredded.user_class, Symbol]

Returns ] a map of users that should get subscribed to their the follow reason.

Returns:

  • (Hash<Thredded.user_class, Symbol])

    ] a map of users that should get subscribed to their the follow reason.



21
22
23
24
25
26
27
# File 'app/commands/thredded/autofollow_users.rb', line 21

def new_followers
  result = {}
  auto_followers.each { |user| result[user] = :auto }
  exclude_follow_on_mention_opt_outs(mentioned_users).each { |user| result[user] = :mentioned }
  result.delete(post.user)
  result
end

#runObject



9
10
11
12
13
# File 'app/commands/thredded/autofollow_users.rb', line 9

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