2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-24 05:24:50 +08:00
|
|
|
class TrackedTopicsUpdater
|
|
|
|
|
|
|
|
def initialize(user_id, threshold)
|
|
|
|
@id = user_id
|
|
|
|
@threshold = threshold
|
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
|
|
topic_users = TopicUser.where(notifications_reason_id: nil, user_id: @id)
|
|
|
|
if @threshold < 0
|
2017-07-28 09:20:09 +08:00
|
|
|
topic_users.update_all(notification_level: TopicUser.notification_levels[:regular])
|
2013-10-24 05:24:50 +08:00
|
|
|
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
|
|
|
|
end
|