Class: Thredded::AutofollowUsers
- Inherits:
-
Object
- Object
- Thredded::AutofollowUsers
- Defined in:
- app/commands/thredded/autofollow_users.rb
Instance Method Summary collapse
-
#initialize(post) ⇒ AutofollowUsers
constructor
A new instance of AutofollowUsers.
- #mentioned_users ⇒ Array<Thredded.user_class>
-
#new_followers ⇒ Hash<Thredded.user_class, Symbol]
] a map of users that should get subscribed to their the follow reason.
- #run ⇒ Object
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_users ⇒ Array<Thredded.user_class>
16 17 18 |
# File 'app/commands/thredded/autofollow_users.rb', line 16 def mentioned_users @mentioned_users ||= Thredded::AtNotificationExtractor.new(post).run end |
#new_followers ⇒ Hash<Thredded.user_class, Symbol]
Returns ] 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 |
#run ⇒ Object
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 |