2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-23 16:24:50 -05: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
|
|
|
|
topic_users.update_all(notification_level: TopicUser.notification_levels[:regular])
|
|
|
|
else
|
|
|
|
topic_users.update_all(
|
2023-01-09 06:20:10 -06:00
|
|
|
[
|
2013-10-23 16:24:50 -05:00
|
|
|
"notification_level = CASE WHEN total_msecs_viewed < ? THEN ? ELSE ? END",
|
|
|
|
@threshold,
|
|
|
|
TopicUser.notification_levels[:regular],
|
|
|
|
TopicUser.notification_levels[:tracking],
|
2023-01-09 06:20:10 -06:00
|
|
|
],
|
2013-10-23 16:24:50 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|