FIX: Rename all instances of bookmarkWithReminder to just bookmark (#9579)

FIX: Rename all instances of bookmarkWithReminder to just bookmark (#9579)

  • Rename all instances of bookmarkWithReminder and bookmark_with_reminder to just bookmark
  • Delete old bookmark code at the same time
  • Add migration to remove the bookmarkWithReminder post menu item if people have it set in site settings
diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js
index b934c13..a49cbaf 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic.js
@@ -652,7 +652,7 @@ export default Controller.extend(bufferedProperty("model"), {
       if (!this.currentUser) {
         return bootbox.alert(I18n.t("bookmarks.not_bookmarked"));
       } else if (post) {
-        return post.toggleBookmarkWithReminder();
+        return post.toggleBookmark();
       } else {
         return this.model.toggleBookmark().then(changedIds => {
           if (!changedIds) {
@@ -665,16 +665,6 @@ export default Controller.extend(bufferedProperty("model"), {
       }
     },
 
-    toggleBookmarkWithReminder(post) {
-      if (!this.currentUser) {
-        return bootbox.alert(I18n.t("bookmarks.not_bookmarked"));
-      } else if (post) {
-        return post.toggleBookmarkWithReminder();
-      } else {
-        return this.model.toggleBookmarkWithReminder();
-      }
-    },
-
     jumpToIndex(index) {
       this._jumpToIndex(index);
     },
diff --git a/app/assets/javascripts/discourse/app/lib/transform-post.js b/app/assets/javascripts/discourse/app/lib/transform-post.js
index 986dc46..60823f0 100644
--- a/app/assets/javascripts/discourse/app/lib/transform-post.js
+++ b/app/assets/javascripts/discourse/app/lib/transform-post.js
@@ -35,7 +35,6 @@ export function transformBasicPost(post) {
     username: post.username,
     avatar_template: post.avatar_template,
     bookmarked: post.bookmarked,
-    bookmarkedWithReminder: post.bookmarked_with_reminder,
     bookmarkReminderAt: post.bookmark_reminder_at,
     bookmarkReminderType: post.bookmark_reminder_type,
     yours: post.yours,
diff --git a/app/assets/javascripts/discourse/app/models/post.js b/app/assets/javascripts/discourse/app/models/post.js
index 550a1fb..e7cf602 100644
--- a/app/assets/javascripts/discourse/app/models/post.js
+++ b/app/assets/javascripts/discourse/app/models/post.js
@@ -310,32 +310,6 @@ const Post = RestModel.extend({
   },
 
   toggleBookmark() {
-    let bookmarkedTopic;
-
-    this.toggleProperty("bookmarked");
-
-    if (this.bookmarked && !this.get("topic.bookmarked")) {
-      this.set("topic.bookmarked", true);
-      bookmarkedTopic = true;
-    }
-
-    // need to wait to hear back from server (stuff may not be loaded)
-
-    return Post.updateBookmark(this.id, this.bookmarked)
-      .then(result => {
-        this.set("topic.bookmarked", result.topic_bookmarked);
-        this.appEvents.trigger("page:bookmark-post-toggled", this);
-      })
-      .catch(error => {
-        this.toggleProperty("bookmarked");
-        if (bookmarkedTopic) {
-          this.set("topic.bookmarked", false);
-        }
-        throw new Error(error);
-      });
-  },
-
-  toggleBookmarkWithReminder() {
     return new Promise(resolve => {
       let controller = showModal("bookmark", {
         model: {
@@ -357,7 +331,7 @@ const Post = RestModel.extend({
         afterSave: savedData => {
           this.setProperties({
             "topic.bookmarked": true,
-            bookmarked_with_reminder: true,
+            bookmarked: true,
             bookmark_reminder_at: savedData.reminderAt,
             bookmark_reminder_type: savedData.reminderType,
             bookmark_name: savedData.name,
@@ -373,7 +347,7 @@ const Post = RestModel.extend({
             bookmark_reminder_type: null,
             bookmark_name: null,
             bookmark_id: null,
-            bookmarked_with_reminder: false
+            bookmarked: false
           });
           this.appEvents.trigger("page:bookmark-post-toggled", this);
         }
diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js
index 46be3e7..00f8c88 100644
--- a/app/assets/javascripts/discourse/app/models/topic.js
+++ b/app/assets/javascripts/discourse/app/models/topic.js
@@ -400,7 +400,6 @@ const Topic = RestModel.extend({
   afterTopicBookmarked(firstPost) {
     if (firstPost) {
       firstPost.set("bookmarked", true);
-      firstPost.set("bookmarked_with_reminder", true);
       this.set("bookmark_reminder_at", firstPost.bookmark_reminder_at);
       return [firstPost.id];
     }
@@ -439,7 +438,7 @@ const Topic = RestModel.extend({
     return this.firstPost().then(firstPost => {
       const toggleBookmarkOnServer = () => {
         if (bookmark) {
-          return firstPost.toggleBookmarkWithReminder().then(() => {
+          return firstPost.toggleBookmark().then(() => {
             this.set("bookmarking", false);
             return this.afterTopicBookmarked(firstPost);
           });
@@ -449,7 +448,7 @@ const Topic = RestModel.extend({
               this.toggleProperty("bookmarked");
               this.set("bookmark_reminder_at", null);
               let clearedBookmarkProps = {
-                bookmarked_with_reminder: false,
+                bookmarked: false,
                 bookmark_id: null,
                 bookmark_name: null,
                 bookmark_reminder_at: null
@@ -458,10 +457,6 @@ const Topic = RestModel.extend({
                 const updated = [];
                 posts.forEach(post => {
                   if (post.bookmarked) {
-                    post.set("bookmarked", false);
-                    updated.push(post.id);
-                  }
-                  if (post.bookmarked_with_reminder) {
                     post.setProperties(clearedBookmarkProps);
                     updated.push(post.id);
                   }
@@ -477,11 +472,7 @@ const Topic = RestModel.extend({
 
       const unbookmarkedPosts = [];
       if (!bookmark && posts) {
-        posts.forEach(
-          post =>
-            (post.bookmarked || post.bookmarked_with_reminder) &&
-            unbookmarkedPosts.push(post)
-        );
+        posts.forEach(post => post.bookmarked && unbookmarkedPosts.push(post));
       }
 
       return new Promise(resolve => {
diff --git a/app/assets/javascripts/discourse/app/templates/topic.hbs b/app/assets/javascripts/discourse/app/templates/topic.hbs
index 6fadf0b..488970c 100644
--- a/app/assets/javascripts/discourse/app/templates/topic.hbs
+++ b/app/assets/javascripts/discourse/app/templates/topic.hbs
@@ -225,7 +225,6 @@
                 recoverPost=(action "recoverPost")
                 expandHidden=(action "expandHidden")
                 toggleBookmark=(action "toggleBookmark")
-                toggleBookmarkWithReminder=(action "toggleBookmarkWithReminder")
                 togglePostType=(action "togglePostType")
                 rebakePost=(action "rebakePost")
                 changePostOwner=(action "changePostOwner")
diff --git a/app/assets/javascripts/discourse/app/widgets/post-menu.js b/app/assets/javascripts/discourse/app/widgets/post-menu.js
index 9804626..73a786e 100644
--- a/app/assets/javascripts/discourse/app/widgets/post-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/post-menu.js
@@ -287,31 +287,11 @@ registerButton("bookmark", attrs => {
     return;
   }
 
-  let className = "bookmark";
-
-  if (attrs.bookmarked) {
-    className += " bookmarked";
-  }
-
-  return {
-    id: attrs.bookmarked ? "unbookmark" : "bookmark",
-    action: "toggleBookmark",
-    title: attrs.bookmarked ? "bookmarks.created" : "bookmarks.not_bookmarked",
-    className,
-    icon: "bookmark"
-  };
-});
-
-registerButton("bookmarkWithReminder", attrs => {
-  if (!attrs.canBookmark) {
-    return;
-  }
-
   let classNames = ["bookmark", "with-reminder"];
   let title = "bookmarks.not_bookmarked";
   let titleOptions = {};
 
-  if (attrs.bookmarkedWithReminder) {
+  if (attrs.bookmarked) {
     classNames.push("bookmarked");
 
     if (attrs.bookmarkReminderAt) {
@@ -331,8 +311,8 @@ registerButton("bookmarkWithReminder", attrs => {
   }
 
   return {

[... diff too long, it was truncated ...]

GitHub sha: ca539fdc

This commit appears in #9579 which was merged by martin.