From f5d6b41f914ab95e40e2ea18689b083713d1d3f6 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 3 Jul 2013 19:03:11 -0400 Subject: [PATCH] FIX: posts weren't being marked as last read correctly --- .../routes/topic_from_params_route.js | 5 ++- .../javascripts/discourse/views/topic_view.js | 40 ++++++++++--------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/topic_from_params_route.js b/app/assets/javascripts/discourse/routes/topic_from_params_route.js index f8efd57556b..677b2efaaf3 100644 --- a/app/assets/javascripts/discourse/routes/topic_from_params_route.js +++ b/app/assets/javascripts/discourse/routes/topic_from_params_route.js @@ -38,7 +38,8 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({ topicController.setProperties({ currentPost: closest, - progressPosition: closest + progressPosition: closest, + enteredAt: new Date().getTime() }); if (topic.present('draft')) { @@ -50,6 +51,8 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({ ignoreIfChanged: true }); } + + }); diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic_view.js index 339b3915787..9a8a7f93f0c 100644 --- a/app/assets/javascripts/discourse/views/topic_view.js +++ b/app/assets/javascripts/discourse/views/topic_view.js @@ -57,6 +57,25 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { composerController.set('topic', this.get('topic')); }.observes('composer'), + enteredTopic: function() { + if (this.present('controller.enteredAt')) { + var topicView = this; + Em.run.schedule('afterRender', function() { + topicView.updateBar(); + topicView.updatePosition(); + }); + } + }.observes('controller.enteredAt'), + + didInsertElement: function(e) { + this.bindScrolling({debounce: 0}); + $(window).bind('resize.discourse-on-scroll', function() { topicView.updatePosition(); }); + + this.$().on('mouseup.discourse-redirect', '.cooked a, a.track-link', function(e) { + return Discourse.ClickTrack.trackClick(e); + }); + }, + // This view is being removed. Shut down operations willDestroyElement: function() { @@ -72,22 +91,6 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { this.set('controller.controllers.header.showExtraInfo', false); }, - didInsertElement: function(e) { - this.bindScrolling({debounce: 0}); - - var topicView = this; - $(window).bind('resize.discourse-on-scroll', function() { topicView.updatePosition(); }); - - this.$().on('mouseup.discourse-redirect', '.cooked a, a.track-link', function(e) { - return Discourse.ClickTrack.trackClick(e); - }); - - this.updatePosition(); - - // We want to make sure the progress bar is updated after it's rendered - this.updateBar(); - }, - debounceLoadSuggested: Discourse.debounce(function(){ if (this.get('isDestroyed') || this.get('isDestroying')) { return; } @@ -147,12 +150,13 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { // Called for every post seen, returns the post number postSeen: function($post) { + var post = this.getPost($post); if (post) { var postNumber = post.get('post_number'); - if (postNumber > (this.get('last_read_post_number') || 0)) { - this.set('last_read_post_number', postNumber); + if (postNumber > (this.get('controller.last_read_post_number') || 0)) { + this.set('controller.last_read_post_number', postNumber); } if (!post.get('read')) { post.set('read', true);