Class: TrackedTopicsUpdater

Inherits:
Object
  • Object
show all
Defined in:
app/services/tracked_topics_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_id, threshold) ⇒ TrackedTopicsUpdater

Returns a new instance of TrackedTopicsUpdater.



4
5
6
7
# File 'app/services/tracked_topics_updater.rb', line 4

def initialize(user_id, threshold)
  @id = user_id
  @threshold = threshold
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/tracked_topics_updater.rb', line 9

def call
  topic_users = TopicUser.where(notifications_reason_id: nil, user_id: @id)
  if @threshold < 0
    topic_users.update_all(notification_level: TopicUser.notification_levels[:regular])
  else
    topic_users.update_all(
      [
        "notification_level = CASE WHEN total_msecs_viewed < ? THEN ? ELSE ? END",
        @threshold,
        TopicUser.notification_levels[:regular],
        TopicUser.notification_levels[:tracking],
      ],
    )
  end
end