From a51c91ac05e55dde008ab218c3d976a75c011e31 Mon Sep 17 00:00:00 2001
From: Robin Ward <robin.ward@gmail.com>
Date: Fri, 4 Dec 2015 15:59:39 -0500
Subject: [PATCH] Revert "FIX: Errors with summary views and placeholders"

This reverts commit 5be3bf80eb6fa80740713430c2835a6090a3e2e5.
---
 .../discourse/controllers/topic.js.es6        |  1 -
 .../discourse/models/post-stream.js.es6       |  5 +--
 .../discourse/views/cloaked-collection.js.es6 | 45 +++++++++++--------
 .../discourse/views/cloaked.js.es6            |  2 +-
 .../models/post-stream-test.js.es6            |  1 -
 5 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6
index 4185d680b91..a6e098ee2d2 100644
--- a/app/assets/javascripts/discourse/controllers/topic.js.es6
+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6
@@ -710,7 +710,6 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
     const postStream = this.get('model.postStream');
     const lastLoadedPost = postStream.get('posts.lastObject');
 
-    console.log(postStream.progressIndexOfPost(post));
     this.set('controllers.topic-progress.progressPosition', postStream.progressIndexOfPost(post));
 
     if (lastLoadedPost && lastLoadedPost === post) {
diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6
index e8aa1d2ec18..6eacd91fe2d 100644
--- a/app/assets/javascripts/discourse/models/post-stream.js.es6
+++ b/app/assets/javascripts/discourse/models/post-stream.js.es6
@@ -669,11 +669,8 @@ export default RestModel.extend({
 
   updateFromJson(postStreamData) {
     const posts = this.get('posts');
+
     posts.clear();
-
-    const postsWithPlaceholders = this.get('postsWithPlaceholders');
-    postsWithPlaceholders.clear();
-
     this.set('gaps', null);
     if (postStreamData) {
       // Load posts if present
diff --git a/app/assets/javascripts/discourse/views/cloaked-collection.js.es6 b/app/assets/javascripts/discourse/views/cloaked-collection.js.es6
index 02d4fc2fefa..7e5bb25e418 100644
--- a/app/assets/javascripts/discourse/views/cloaked-collection.js.es6
+++ b/app/assets/javascripts/discourse/views/cloaked-collection.js.es6
@@ -2,12 +2,11 @@
 const CloakedCollectionView = Ember.CollectionView.extend({
   cloakView: Ember.computed.alias('itemViewClass'),
   topVisible: null,
+  bottomVisible: null,
   offsetFixedTopElement: null,
   offsetFixedBottomElement: null,
   loadingHTML: 'Loading...',
   scrollDebounce: 10,
-  _topVisible: null,
-  _bottomVisible: null,
 
   init() {
     const cloakView = this.get('cloakView'),
@@ -18,7 +17,6 @@ const CloakedCollectionView = Ember.CollectionView.extend({
     const slackRatio = parseFloat(this.get('slackRatio'));
     if (!slackRatio) { this.set('slackRatio', 1.0); }
 
-
     const CloakedView = this.container.lookupFactory('view:cloaked');
     this.set('itemViewClass', CloakedView.extend({
       classNames: [cloakView + '-cloak'],
@@ -44,6 +42,28 @@ const CloakedCollectionView = Ember.CollectionView.extend({
     Ember.run.next(this, 'scrolled');
   },
 
+  /**
+    If the topmost visible view changed, we will notify the controller if it has an appropriate hook.
+
+    @method _topVisibleChanged
+    @observes topVisible
+  **/
+  _topVisibleChanged: function() {
+    const controller = this.get('controller');
+    if (controller.topVisibleChanged) { controller.topVisibleChanged(this.get('topVisible')); }
+  }.observes('topVisible'),
+
+  /**
+    If the bottommost visible view changed, we will notify the controller if it has an appropriate hook.
+
+    @method _bottomVisible
+    @observes bottomVisible
+  **/
+  _bottomVisible: function() {
+    const controller = this.get('controller');
+    if (controller.bottomVisibleChanged) { controller.bottomVisibleChanged(this.get('bottomVisible')); }
+  }.observes('bottomVisible'),
+
   /**
     Binary search for finding the topmost view on screen.
 
@@ -120,7 +140,6 @@ const CloakedCollectionView = Ember.CollectionView.extend({
     // Find the bottom view and what's onscreen
     let bottomView = topView;
     let bottomVisible = null;
-    const controller = this.get('controller');
     while (bottomView < childViews.length) {
       const view = childViews[bottomView];
       const $view = view.$();
@@ -149,31 +168,19 @@ const CloakedCollectionView = Ember.CollectionView.extend({
     }
     if (bottomView >= childViews.length) { bottomView = childViews.length - 1; }
 
-    let topVisible = onscreen[0];
-
     // If our controller has a `sawObjects` method, pass the on screen objects to it.
+    const controller = this.get('controller');
     if (onscreen.length) {
-      this.setProperties({topVisible, bottomVisible });
+      this.setProperties({topVisible: onscreen[0], bottomVisible });
       if (controller && controller.sawObjects) {
         Em.run.schedule('afterRender', function() {
           controller.sawObjects(onscreen);
         });
       }
     } else {
-      bottomVisible = topVisible = null;
+      this.setProperties({topVisible: null, bottomVisible: null});
     }
 
-    if (topVisible !== this._topVisible && controller.topVisibleChanged) {
-      controller.topVisibleChanged(topVisible);
-    }
-    this._topVisible = topVisible;
-
-    if (bottomVisible !== this._bottomVisible && controller.bottomVisibleChanged) {
-      controller.bottomVisibleChanged(bottomVisible);
-    }
-    this._bottomVisible = bottomVisible;
-
-
     const toCloak = childViews.slice(0, topView).concat(childViews.slice(bottomView+1));
 
     this._uncloak = toUncloak;
diff --git a/app/assets/javascripts/discourse/views/cloaked.js.es6 b/app/assets/javascripts/discourse/views/cloaked.js.es6
index 0e59995fe97..71ff329175c 100644
--- a/app/assets/javascripts/discourse/views/cloaked.js.es6
+++ b/app/assets/javascripts/discourse/views/cloaked.js.es6
@@ -97,7 +97,7 @@ export default Ember.View.extend({
         createArgs.context = target;
       }
       if (controller) { createArgs.controller = controller; }
-      this.setProperties({ style: ''.htmlSafe(), loading: false });
+      this.setProperties({ style: null, loading: false });
 
       const cloaks = target && (target instanceof Placeholder) ? target.viewName : this.get('cloaks');
       this.setContainedView(this.createChildView(cloaks, createArgs));
diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6
index 4408b6027a6..db1d0f07d08 100644
--- a/test/javascripts/models/post-stream-test.js.es6
+++ b/test/javascripts/models/post-stream-test.js.es6
@@ -135,7 +135,6 @@ test('updateFromJson', function() {
   });
 
   equal(postStream.get('posts.length'), 1, 'it loaded the posts');
-  equal(postStream.get('postsWithPlaceholders.length'), 1, 'it loaded the posts');
   containsInstance(postStream.get('posts'), Discourse.Post);
 
   equal(postStream.get('extra_property'), 12);