2020-03-12 08:16:00 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BookmarkReminderNotificationHandler
|
2022-05-09 07:37:23 +08:00
|
|
|
attr_reader :bookmark
|
|
|
|
|
|
|
|
def initialize(bookmark)
|
|
|
|
@bookmark = bookmark
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_notification
|
2020-03-12 08:16:00 +08:00
|
|
|
return if bookmark.blank?
|
|
|
|
Bookmark.transaction do
|
2022-05-23 08:07:15 +08:00
|
|
|
if !bookmark.registered_bookmarkable.can_send_reminder?(bookmark)
|
2022-05-09 07:37:23 +08:00
|
|
|
clear_reminder
|
2021-09-15 08:16:54 +08:00
|
|
|
else
|
2022-05-23 08:07:15 +08:00
|
|
|
bookmark.registered_bookmarkable.send_reminder_notification(bookmark)
|
2020-03-12 08:16:00 +08:00
|
|
|
|
2021-04-21 17:36:32 +08:00
|
|
|
if bookmark.auto_delete_when_reminder_sent?
|
|
|
|
BookmarkManager.new(bookmark.user).destroy(bookmark.id)
|
|
|
|
end
|
2020-05-07 11:37:39 +08:00
|
|
|
|
2022-05-09 07:37:23 +08:00
|
|
|
clear_reminder
|
2020-05-07 11:37:39 +08:00
|
|
|
end
|
2020-03-12 08:16:00 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-09 07:37:23 +08:00
|
|
|
def clear_reminder
|
2020-03-12 08:16:00 +08:00
|
|
|
Rails.logger.debug(
|
2021-09-16 07:56:54 +08:00
|
|
|
"Clearing bookmark reminder for bookmark_id #{bookmark.id}. reminder at: #{bookmark.reminder_at}",
|
2020-03-12 08:16:00 +08:00
|
|
|
)
|
|
|
|
|
2022-03-09 01:44:18 +08:00
|
|
|
bookmark.reminder_at = nil if bookmark.auto_clear_reminder_when_reminder_sent?
|
|
|
|
|
2020-07-29 07:43:32 +08:00
|
|
|
bookmark.clear_reminder!
|
2020-03-12 08:16:00 +08:00
|
|
|
end
|
|
|
|
end
|