FEATURE: Optionally delete bookmark when reminder sent (#9637)

We now show an options gear icon next to the bookmark name.

When expanded we show the "delete bookmark when reminder sent" option. The value of this checkbox is saved in local storage for the user.

If this is ticked, when a reminder is sent for the bookmark the bookmark itself is deleted. This is so people can use the reminder functionality by itself.

Also remove the blue alert reminder section from the "Edit Bookmark" modal as it just added clutter, because the user can already see they had a reminder set:

Adds a default false boolean column `delete_when_reminder_sent` to bookmarks.
This commit is contained in:
Martin Brennan
2020-05-07 13:37:39 +10:00
committed by GitHub
parent 423802fbce
commit 6fb0f36ce1
14 changed files with 196 additions and 31 deletions

View File

@@ -7,20 +7,22 @@ class BookmarkManager
@user = user
end
def create(post_id:, name: nil, reminder_type: nil, reminder_at: nil)
def create(post_id:, name: nil, reminder_type: nil, reminder_at: nil, options: {})
post = Post.unscoped.includes(:topic).find(post_id)
reminder_type = parse_reminder_type(reminder_type)
raise Discourse::InvalidAccess.new if !Guardian.new(@user).can_see_post?(post)
bookmark = Bookmark.create(
user_id: @user.id,
topic: post.topic,
post: post,
name: name,
reminder_type: reminder_type,
reminder_at: reminder_at,
reminder_set_at: Time.zone.now
{
user_id: @user.id,
topic: post.topic,
post: post,
name: name,
reminder_type: reminder_type,
reminder_at: reminder_at,
reminder_set_at: Time.zone.now
}.merge(options)
)
if bookmark.errors.any?
@@ -66,7 +68,7 @@ class BookmarkManager
BookmarkReminderNotificationHandler.send_notification(bookmark)
end
def update(bookmark_id:, name:, reminder_type:, reminder_at:)
def update(bookmark_id:, name:, reminder_type:, reminder_at:, options: {})
bookmark = Bookmark.find_by(id: bookmark_id)
raise Discourse::NotFound if bookmark.blank?
@@ -75,10 +77,12 @@ class BookmarkManager
reminder_type = parse_reminder_type(reminder_type)
success = bookmark.update(
name: name,
reminder_at: reminder_at,
reminder_type: reminder_type,
reminder_set_at: Time.zone.now
{
name: name,
reminder_at: reminder_at,
reminder_type: reminder_type,
reminder_set_at: Time.zone.now
}.merge(options)
)
if bookmark.errors.any?

View File

@@ -9,6 +9,11 @@ class BookmarkReminderNotificationHandler
end
create_notification(bookmark)
if bookmark.delete_when_reminder_sent?
return bookmark.destroy
end
clear_reminder(bookmark)
end
end