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)
|
2024-08-25 18:17:39 -05:00
|
|
|
bookmark.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
|
|
|
|
2024-08-25 18:17:39 -05:00
|
|
|
bookmark.clear_reminder!
|
2020-05-06 22:37:39 -05:00
|
|
|
end
|
2020-03-11 19:16:00 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|