A platform for community discussion. Free, open, simple.
FIX: Show topic level bookmark with reminder modal (#9336)
Martin Brennan42c2678d8f4b
diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.jsindex 2629afcb338..535ac4b4192 100644--- a/app/assets/javascripts/discourse/models/post.js+++ b/app/assets/javascripts/discourse/models/post.js@@ -339,26 +339,30 @@ const Post = RestModel.extend({toggleBookmarkWithReminder() {this.toggleProperty("bookmarked_with_reminder");if (this.bookmarked_with_reminder) {- let controller = showModal("bookmark", {- model: {- postId: this.id- },- title: "post.bookmarks.create",- modalClass: "bookmark-with-reminder"- });- controller.setProperties({- onCloseWithoutSaving: () => {- this.toggleProperty("bookmarked_with_reminder");- this.appEvents.trigger("post-stream:refresh", { id: this.id });- },- afterSave: (reminderAtISO, reminderType) => {- this.setProperties({- "topic.bookmarked": true,- bookmark_reminder_at: reminderAtISO,- bookmark_reminder_type: reminderType- });- this.appEvents.trigger("post-stream:refresh", { id: this.id });- }+ return new Promise(resolve => {+ let controller = showModal("bookmark", {+ model: {+ postId: this.id+ },+ title: "post.bookmarks.create",+ modalClass: "bookmark-with-reminder"+ });+ controller.setProperties({+ onCloseWithoutSaving: () => {+ this.toggleProperty("bookmarked_with_reminder");+ this.appEvents.trigger("post-stream:refresh", { id: this.id });+ resolve();+ },+ afterSave: (reminderAtISO, reminderType) => {+ this.setProperties({+ "topic.bookmarked": true,+ bookmark_reminder_at: reminderAtISO,+ bookmark_reminder_type: reminderType+ });+ this.appEvents.trigger("post-stream:refresh", { id: this.id });+ resolve();+ }+ });});} else {this.setProperties({diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.jsindex 26afbd4ba2b..045f31123d6 100644--- a/app/assets/javascripts/discourse/models/topic.js+++ b/app/assets/javascripts/discourse/models/topic.js@@ -397,6 +397,16 @@ const Topic = RestModel.extend({}).then(() => this.set("archetype", "regular"));},+ afterTopicBookmarked(firstPost) {+ if (firstPost) {+ firstPost.set("bookmarked", true);+ if (this.siteSettings.enable_bookmarks_with_reminders) {+ firstPost.set("bookmarked_with_reminder", true);+ }+ return [firstPost.id];+ }+ },+toggleBookmark() {if (this.bookmarking) {return Promise.resolve();@@ -408,41 +418,48 @@ const Topic = RestModel.extend({const firstPost =posts && posts[0] && posts[0].get("post_number") === 1 && posts[0];const bookmark = !this.bookmarked;- const path = bookmark ? "/bookmark" : "/remove_bookmarks";const toggleBookmarkOnServer = () => {- return ajax(`/t/${this.id}${path}`, { type: "PUT" })- .then(() => {- this.toggleProperty("bookmarked");- if (bookmark && firstPost) {- firstPost.set("bookmarked", true);- if (this.siteSettings.enable_bookmarks_with_reminders) {- firstPost.set("bookmarked_with_reminder", true);+ if (bookmark) {+ if (this.siteSettings.enable_bookmarks_with_reminders) {+ return firstPost.toggleBookmarkWithReminder().then(() => {+ this.set("bookmarking", false);+ return this.afterTopicBookmarked(firstPost);+ });+ } else {+ return ajax(`/t/${this.id}/bookmark`, { type: "PUT" })+ .then(() => {+ this.toggleProperty("bookmarked");+ return this.afterTopicBookmarked(firstPost);+ })+ .catch(popupAjaxError)+ .finally(() => this.set("bookmarking", false));+ }+ } else {+ return ajax(`/t/${this.id}/remove_bookmarks`, { type: "PUT" })+ .then(() => {+ this.toggleProperty("bookmarked");+ if (posts) {+ const updated = [];+ posts.forEach(post => {+ if (post.get("bookmarked")) {+ post.set("bookmarked", false);+ updated.push(post.id);+ }+ if (+ this.siteSettings.enable_bookmarks_with_reminders &&+ post.get("bookmarked_with_reminder")+ ) {+ post.set("bookmarked_with_reminder", false);+ updated.push(post.id);+ }+ });+ return updated;}- return [firstPost.id];- }- if (!bookmark && posts) {- const updated = [];- posts.forEach(post => {- if (post.get("bookmarked")) {- post.set("bookmarked", false);- updated.push(post.id);- }- if (- this.siteSettings.enable_bookmarks_with_reminders &&- post.get("bookmarked_with_reminder")- ) {- post.set("bookmarked_with_reminder", false);- updated.push(post.id);- }- });- return updated;- }-- return [];- })- .catch(popupAjaxError)- .finally(() => this.set("bookmarking", false));+ })+ .catch(popupAjaxError)+ .finally(() => this.set("bookmarking", false));+ }};const unbookmarkedPosts = [];diff --git a/app/assets/javascripts/discourse/widgets/bookmark-reminder-notification-item.js b/app/assets/javascripts/discourse/widgets/bookmark-reminder-notification-item.jsindex f02bc7a223e..1a6691dda88 100644--- a/app/assets/javascripts/discourse/widgets/bookmark-reminder-notification-item.js+++ b/app/assets/javascripts/discourse/widgets/bookmark-reminder-notification-item.js@@ -14,6 +14,19 @@ createWidgetFrom(description,username});+ },+ notificationTitle(notificationName, data) {+ if (notificationName) {+ if (data.bookmark_name) {+ return I18n.t(`notifications.titles.${notificationName}_with_name`, {+ name: data.bookmark_name+ });+ } else {+ return I18n.t(`notifications.titles.${notificationName}`);+ }+ } else {+ return "";+ }}});diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex a05ced4e1e8..62cfd14763e 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -1880,6 +1880,7 @@ en:moved_post: "post moved"linked: "linked"bookmark_reminder: "bookmark reminder"+ bookmark_reminder_with_name: "bookmark reminder - %{name}"granted_badge: "badge granted"invited_to_topic: "invited to topic"group_mentioned: "group mentioned"