mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Bookmark pinning (#12431)
Users can now pin bookmarks from their bookmark list. This will anchor the bookmark to the top of the list, and show a pin icon next to it. This also applies in the nav bookmarks panel. If there are multiple pinned bookmarks they sort by last updated order.
This commit is contained in:
@@ -40,10 +40,7 @@ class BookmarkManager
|
||||
end
|
||||
|
||||
def destroy(bookmark_id)
|
||||
bookmark = Bookmark.find_by(id: bookmark_id)
|
||||
|
||||
raise Discourse::NotFound if bookmark.blank?
|
||||
raise Discourse::InvalidAccess.new if !Guardian.new(@user).can_delete?(bookmark)
|
||||
bookmark = find_bookmark_and_check_access(bookmark_id)
|
||||
|
||||
bookmark.destroy
|
||||
|
||||
@@ -72,10 +69,7 @@ class BookmarkManager
|
||||
end
|
||||
|
||||
def update(bookmark_id:, name:, reminder_type:, reminder_at:, options: {})
|
||||
bookmark = Bookmark.find_by(id: bookmark_id)
|
||||
|
||||
raise Discourse::NotFound if bookmark.blank?
|
||||
raise Discourse::InvalidAccess.new if !Guardian.new(@user).can_edit?(bookmark)
|
||||
bookmark = find_bookmark_and_check_access(bookmark_id)
|
||||
|
||||
reminder_type = parse_reminder_type(reminder_type)
|
||||
|
||||
@@ -95,8 +89,27 @@ class BookmarkManager
|
||||
success
|
||||
end
|
||||
|
||||
def toggle_pin(bookmark_id:)
|
||||
bookmark = find_bookmark_and_check_access(bookmark_id)
|
||||
bookmark.pinned = !bookmark.pinned
|
||||
success = bookmark.save
|
||||
|
||||
if bookmark.errors.any?
|
||||
return add_errors_from(bookmark)
|
||||
end
|
||||
|
||||
success
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_bookmark_and_check_access(bookmark_id)
|
||||
bookmark = Bookmark.find_by(id: bookmark_id)
|
||||
raise Discourse::NotFound if !bookmark
|
||||
raise Discourse::InvalidAccess.new if !Guardian.new(@user).can_edit?(bookmark)
|
||||
bookmark
|
||||
end
|
||||
|
||||
def update_topic_user_bookmarked(topic, opts = {})
|
||||
# PostCreator can specify whether auto_track is enabled or not, don't want to
|
||||
# create a TopicUser in that case
|
||||
|
||||
@@ -27,7 +27,9 @@ class BookmarkQuery
|
||||
end
|
||||
|
||||
def list_all
|
||||
results = user_bookmarks.order('bookmarks.updated_at DESC')
|
||||
results = user_bookmarks.order(
|
||||
'(CASE WHEN bookmarks.pinned THEN 0 ELSE 1 END), bookmarks.updated_at DESC'
|
||||
)
|
||||
|
||||
topics = Topic.listable_topics.secured(@guardian)
|
||||
pms = Topic.private_messages_for_user(@user)
|
||||
|
||||
Reference in New Issue
Block a user