discourse/app/controllers/bookmarks_controller.rb
Martin Brennan 41b43a2a25
FEATURE: Add "delete on owner reply" bookmark functionality (#10231)
This adds an option to "delete on owner reply" to bookmarks. If you select this option in the modal, then reply to the topic the bookmark is in, the bookmark will be deleted on reply.

This PR also changes the checkboxes for these additional bookmark options to an Integer column in the DB with a combobox to select the option you want.

The use cases are:

* Sometimes I will bookmark the topics to read it later. In this case we definitely don’t need to keep the bookmark after I replied to it.
* Sometimes I will read the topic in mobile and I will prefer to reply in PC later. Or I may have to do some research before reply. So I will bookmark it for reply later.
2020-07-21 10:00:39 +10:00

54 lines
1.4 KiB
Ruby

# frozen_string_literal: true
class BookmarksController < ApplicationController
requires_login
def create
params.require(:post_id)
bookmark_manager = BookmarkManager.new(current_user)
bookmark = bookmark_manager.create(
post_id: params[:post_id],
name: params[:name],
reminder_type: params[:reminder_type],
reminder_at: params[:reminder_at],
options: {
auto_delete_preference: params[:auto_delete_preference] || 0
}
)
if bookmark_manager.errors.empty?
return render json: success_json.merge(id: bookmark.id)
end
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
end
def destroy
params.require(:id)
result = BookmarkManager.new(current_user).destroy(params[:id])
render json: success_json.merge(result)
end
def update
params.require(:id)
bookmark_manager = BookmarkManager.new(current_user)
bookmark_manager.update(
bookmark_id: params[:id],
name: params[:name],
reminder_type: params[:reminder_type],
reminder_at: params[:reminder_at],
options: {
auto_delete_preference: params[:auto_delete_preference] || 0
}
)
if bookmark_manager.errors.empty?
return render json: success_json
end
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
end
end