Class: Jobs::GroupPmAlert

Inherits:
Base
  • Object
show all
Defined in:
app/jobs/regular/group_pm_alert.rb

Instance Method Summary collapse

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/jobs/regular/group_pm_alert.rb', line 5

def execute(args)
  return unless user = User.find_by(id: args[:user_id])
  return unless group = Group.find_by(id: args[:group_id])
  return unless post = Post.find_by(id: args[:post_id])
  return unless topic = post.topic

  group.set_message_default_notification_levels!(topic, ignore_existing: true)

  alerter = PostAlerter.new

  group
    .users
    .where("group_users.notification_level = :level", level: NotificationLevels.all[:tracking])
    .find_each { |u| alerter.notify_group_summary(u, topic) }

  notification_data = {
    notification_type: Notification.types[:invited_to_private_message],
    topic_id: topic.id,
    post_number: 1,
    data: {
      topic_title: topic.title,
      display_username: user.username,
      group_id: group.id,
    }.to_json,
  }

  group
    .users
    .where(
      "group_users.notification_level in (:levels) AND user_id != :id",
      levels: [NotificationLevels.all[:watching], NotificationLevels.all[:watching_first_post]],
      id: user.id,
    )
    .find_each { |u| u.notifications.create!(notification_data) }
end