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)
|
2024-08-26 09:17:39 +10:00
|
|
|
bookmark.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
|
|
|
|
2024-08-26 09:17:39 +10:00
|
|
|
bookmark.clear_reminder!
|
2020-05-07 13:37:39 +10:00
|
|
|
end
|
2020-03-12 10:16:00 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|