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