FIX: add protection when removing auto delete on post bookmarks

FIX: add protection when removing auto delete on post bookmarks

If you reply to a topic and are looking at an admin page (like site settings) ,you have no postStream or posts.

diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js
index 1be8e37..49467d5 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic.js
@@ -189,17 +189,19 @@ export default Controller.extend(bufferedProperty("model"), {
   },
 
   _removeDeleteOnOwnerReplyBookmarks() {
-    let posts = this.model.get("postStream").posts;
-    posts
-      .filter(
-        p =>
-          p.bookmarked &&
-          p.bookmark_auto_delete_preference ===
-            AUTO_DELETE_PREFERENCES.ON_OWNER_REPLY
-      )
-      .forEach(p => {
-        p.clearBookmark();
-      });
+    const posts = this.get("model.postStream.posts");
+    if (posts) {
+      posts
+        .filter(
+          p =>
+            p.bookmarked &&
+            p.bookmark_auto_delete_preference ===
+              AUTO_DELETE_PREFERENCES.ON_OWNER_REPLY
+        )
+        .forEach(p => {
+          p.clearBookmark();
+        });
+    }
   },
 
   _forceRefreshPostStream() {

GitHub sha: 04a3b949

1 Like