FIX: Remove last_unread_post excerpt logic for bookmarks (#17979)

The logic to determine what post excerpt to show for
a topic-level bookmark based on the last unread post
was complex and slow, so we decided to remove it and
always just use the first post excerpt.

This commit also fixes an issue where a couple of
instances of for_topic were missed when doing the
Bookmarkable refactors, so:

1. Clicking the topic bookmark link was not taking
   the user to the last unread post
2. When replying to a topic where there was a topic
   level bookmark with the auto delete preference
   of "on owner reply", we were not removing the
   bookmark from the UI correctly.

A test has been added for the former, the latter would
be quite time-consuming to test and not really worth
it considering it's quite an edge case UI bug.
This commit is contained in:
Martin Brennan
2022-08-19 09:35:25 +10:00
committed by GitHub
parent df9e546f5d
commit 49a70a37f1
6 changed files with 55 additions and 66 deletions
@@ -240,7 +240,10 @@ export default Controller.extend(bufferedProperty("model"), {
this.model.removeBookmark(post.bookmark_id);
});
}
const forTopicBookmark = this.model.bookmarks.findBy("for_topic", true);
const forTopicBookmark = this.model.bookmarks.findBy(
"bookmarkable_type",
"Topic"
);
if (
forTopicBookmark?.auto_delete_preference ===
AUTO_DELETE_PREFERENCES.ON_OWNER_REPLY
@@ -143,7 +143,8 @@ const Bookmark = RestModel.extend({
// 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;
const linkedPostNumber =
this.bookmarkable_type === "Topic" ? null : this.linked_post_number;
return Topic.create({
id: this.topic_id,
@@ -0,0 +1,42 @@
import { module, test } from "qunit";
import Bookmark from "discourse/models/bookmark";
module("Unit | Model | bookmark", function () {
test("topicForList - Topic bookmarkable", function (assert) {
let bookmark = Bookmark.create({
id: 1,
bookmarkable_type: "Topic",
bookmarkable_id: 999,
linked_post_number: null,
topic_id: 999,
fancy_title: "Some test topic",
last_read_post_number: 23,
highest_post_number: 30,
});
assert.strictEqual(
bookmark.topicForList.linked_post_number,
null,
"linked_post_number is null"
);
});
test("topicForList - Post bookmarkable", function (assert) {
let bookmark = Bookmark.create({
id: 1,
bookmarkable_type: "Post",
bookmarkable_id: 999,
linked_post_number: 787,
topic_id: 999,
fancy_title: "Some test topic",
last_read_post_number: 23,
highest_post_number: 30,
});
assert.strictEqual(
bookmark.topicForList.linked_post_number,
787,
"linked_post_number is correct"
);
});
});