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