Class: Thredded::NotifyMentionedUsers

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

Constant Summary collapse

DELIVER_METHOD =
Rails.version < '4.2.0' ? :deliver : :deliver_later

Instance Method Summary collapse

Constructor Details

#initialize(post) ⇒ NotifyMentionedUsers

Returns a new instance of NotifyMentionedUsers.



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

def initialize(post)
  @post = post
end

Instance Method Details

#at_notifiable_members ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'app/commands/thredded/notify_mentioned_users.rb', line 20

def at_notifiable_members
  user_names = AtNotificationExtractor.new(post.content).run
  members = post.readers_from_user_names(user_names).to_a

  members.delete post.user
  members = exclude_previously_notified(members)
  members = exclude_those_that_are_not_private(members)
  members = exclude_those_opting_out_of_at_notifications(members)

  members
end

#run ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'app/commands/thredded/notify_mentioned_users.rb', line 9

def run
  members = at_notifiable_members
  return unless members.present?

  user_emails = members.map(&:email)
  (post.private_topic_post? ? PrivatePostMailer : PostMailer)
    .at_notification(post.id, user_emails)
    .send(DELIVER_METHOD)
  MembersMarkedNotified.new(post, members).run
end