From 27699648ef8a73d20f0729e97b8ca684513edfd5 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Tue, 21 Sep 2021 13:49:56 +1000 Subject: [PATCH] FEATURE: Go to last unread for topic-level bookmark links (#14396) Instead of going to the OP of the topic for topic-level bookmarks (which are bookmarks where for_topic is true) when clicking on the bookmark in the quick access menu or on the user bookmark list, this commit takes the user to the last unread post in the topic instead. This should be generally more useful than landing on the unchanging OP. To make this work nicely, I needed to add the last_read_post_number to the BookmarkQuery based on the TopicUser association. It should not add too much extra weight to the query, because it is limited to the user that we are fetching bookmarks for. Also fixed an issue where the bookmark serializer highest_post_number was not taking into account whether the user was staff, which is when we should use highest_staff_post_number instead. --- .../discourse/app/models/bookmark.js | 17 ++++++++-- .../templates/components/bookmark-list.hbs | 2 +- .../app/widgets/quick-access-bookmarks.js | 15 ++++++--- app/serializers/user_bookmark_serializer.rb | 11 ++++++- lib/bookmark_query.rb | 4 +++ spec/lib/bookmark_query_spec.rb | 21 +++++++++++- spec/models/user_bookmark_list_spec.rb | 3 +- .../user_bookmark_serializer_spec.rb | 32 +++++++------------ 8 files changed, 73 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/discourse/app/models/bookmark.js b/app/assets/javascripts/discourse/app/models/bookmark.js index 52b032e2642..97d45b219ed 100644 --- a/app/assets/javascripts/discourse/app/models/bookmark.js +++ b/app/assets/javascripts/discourse/app/models/bookmark.js @@ -125,9 +125,20 @@ const Bookmark = RestModel.extend({ ).capitalize(); }, - @discourseComputed("linked_post_number", "fancy_title", "topic_id") - topicLink(linked_post_number, fancy_title, id) { - return Topic.create({ id, fancy_title, linked_post_number }); + @discourseComputed() + topicForList() { + // for topic level bookmarks we want to jump to the last unread post URL, + // which the topic-link helper does by default if no linked post number is + // provided + const linkedPostNumber = this.for_topic ? null : this.linked_post_number; + + return Topic.create({ + id: this.topic_id, + fancy_title: this.fancy_title, + linked_post_number: linkedPostNumber, + last_read_post_number: this.last_read_post_number, + highest_post_number: this.highest_post_number, + }); }, loadItems(params) { diff --git a/app/assets/javascripts/discourse/app/templates/components/bookmark-list.hbs b/app/assets/javascripts/discourse/app/templates/components/bookmark-list.hbs index 8816e46983b..9dbfd967959 100644 --- a/app/assets/javascripts/discourse/app/templates/components/bookmark-list.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/bookmark-list.hbs @@ -32,7 +32,7 @@ {{d-icon "thumbtack" class="bookmark-pinned"}} {{/if}} {{~topic-status topic=bookmark.topicStatus~}} - {{topic-link bookmark.topicLink}} + {{topic-link bookmark.topicForList}}