mirror of
https://github.com/discourse/discourse.git
synced 2024-12-18 15:33:45 +08:00
5268568d23
This PR removes the user reminder topic timers, because that system has been supplanted and improved by bookmark reminders. The option is removed from the UI and all existing user reminder topic timers are migrated to bookmark reminders. Migration does this: * Get all topic_timers with status_type 5 (reminders) * Gets all bookmarks where the user ID and topic ID match * Loops through the found topic timers * If there is no bookmark for the OP of the topic, then we just create a bookmark with a reminder * If there is a bookmark for the OP of the topic and it does **not** have a reminder set, then just update it with the topic timer reminder * If there is a bookmark for the OP of the topic with a reminder then just discard the topic timer * Cancels all outstanding user reminder topic timers * **Trashes (not deletes) all user reminder topic timers** Notes: * For now I have left the user reminder topic timer job class in place; this is so the jobs can be cancelled in the migration. It and the specs will be deleted in the next PR. * At a later date I will write a migration to delete all trashed user topic timers. They are not deleted here in case there are data issues and they need to be recovered. * A future PR will change the UI of the topic timer modal to make it look more like the bookmark modal.
32 lines
800 B
Ruby
32 lines
800 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class TopicReminder < ::Jobs::Base
|
|
|
|
def execute(args)
|
|
# noop, TODO(martin 2021-03-11): Remove this after timers migrated and outstanding jobs cancelled
|
|
return
|
|
|
|
topic_timer = TopicTimer.find_by(id: args[:topic_timer_id])
|
|
|
|
topic = topic_timer&.topic
|
|
user = topic_timer&.user
|
|
|
|
if topic_timer.blank? || topic.blank? || user.blank? ||
|
|
topic_timer.execute_at > Time.zone.now
|
|
return
|
|
end
|
|
|
|
user.notifications.create!(
|
|
notification_type: Notification.types[:topic_reminder],
|
|
topic_id: topic.id,
|
|
post_number: 1,
|
|
data: { topic_title: topic.title, display_username: user.username }.to_json
|
|
)
|
|
|
|
topic_timer.trash!(Discourse.system_user)
|
|
end
|
|
|
|
end
|
|
end
|