Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fallback to `bookmarkable_url` if bookmark reminder notification has no topic info (#17883)

Osama Sayeghb5a601515560
diff --git a/app/assets/javascripts/discourse/app/lib/notification-items/bookmark-reminder.js b/app/assets/javascripts/discourse/app/lib/notification-items/bookmark-reminder.js
index d465f4a71b9..60318963539 100644
--- a/app/assets/javascripts/discourse/app/lib/notification-items/bookmark-reminder.js
+++ b/app/assets/javascripts/discourse/app/lib/notification-items/bookmark-reminder.js
@@ -1,5 +1,6 @@
import NotificationItemBase from "discourse/lib/notification-items/base";
import I18n from "I18n";
+import getUrl from "discourse-common/lib/get-url";
export default class extends NotificationItemBase {
get linkTitle() {
@@ -14,4 +15,14 @@ export default class extends NotificationItemBase {
get description() {
return super.description || this.notification.data.title;
}
+
+ get linkHref() {
+ let linkHref = super.linkHref;
+ if (linkHref) {
+ return linkHref;
+ }
+ if (this.notification.data.bookmarkable_url) {
+ return getUrl(this.notification.data.bookmarkable_url);
+ }
+ }
}
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/notification-items/bookmark-reminder-test.js b/app/assets/javascripts/discourse/tests/unit/lib/notification-items/bookmark-reminder-test.js
index 53fa1539036..8bbe50351bd 100644
--- a/app/assets/javascripts/discourse/tests/unit/lib/notification-items/bookmark-reminder-test.js
+++ b/app/assets/javascripts/discourse/tests/unit/lib/notification-items/bookmark-reminder-test.js
@@ -82,4 +82,42 @@ discourseModule("Unit | Notification Items | bookmark-reminder", function () {
"description falls back to the bookmark title if there's no fancy title"
);
});
+
+ test("linkHref", function (assert) {
+ let notification = getNotification();
+ let director = createRenderDirector(
+ notification,
+ "bookmark_reminder",
+ this.siteSettings
+ );
+ assert.strictEqual(
+ director.linkHref,
+ "/t/this-is-fancy-title/449/113",
+ "is a link to the topic that the bookmark belongs to"
+ );
+
+ notification = getNotification({
+ post_number: null,
+ topic_id: null,
+ fancy_title: null,
+ slug: null,
+ data: {
+ title: "bookmark from some plugin",
+ display_username: "osama",
+ bookmark_name: "",
+ bookmarkable_url: "/link/to/somewhere",
+ bookmarkable_id: 4324,
+ },
+ });
+ director = createRenderDirector(
+ notification,
+ "bookmark_reminder",
+ this.siteSettings
+ );
+ assert.strictEqual(
+ director.linkHref,
+ "/link/to/somewhere",
+ "falls back to bookmarkable_url"
+ );
+ });
});