Class: Thredded::NotifyPrivateTopicUsers

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(private_topic) ⇒ NotifyPrivateTopicUsers

Returns a new instance of NotifyPrivateTopicUsers.



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

def initialize(private_topic)
  @post = private_topic.posts.first || Post.new
  @private_topic = private_topic
end

Instance Method Details

#private_topic_recipients ⇒ Object



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

def private_topic_recipients
  members = private_topic.users - [private_topic.user]
  members = exclude_those_opting_out_of_message_notifications(members)
  members = exclude_previously_notified(members)
  members
end

#run ⇒ Object



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

def run
  members = private_topic_recipients

  return unless members.present?
  user_emails = members.map(&:email)
  PrivateTopicMailer
    .message_notification(private_topic.id, user_emails)
    .send(DELIVER_METHOD)
  mark_notified(members)
end