diff --git a/app/assets/javascripts/discourse/components/post-gap.js.es6 b/app/assets/javascripts/discourse/components/post-gap.js.es6 index 3c3209a89e0..159d047f076 100644 --- a/app/assets/javascripts/discourse/components/post-gap.js.es6 +++ b/app/assets/javascripts/discourse/components/post-gap.js.es6 @@ -3,8 +3,8 @@ export default Ember.Component.extend({ initGaps: function(){ this.set('loading', false); - var before = this.get('before') === 'true', - gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after'); + const before = this.get('before') === 'true'; + const gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after'); if (gaps) { this.set('gap', gaps[this.get('post.id')]); @@ -16,29 +16,27 @@ export default Ember.Component.extend({ this.rerender(); }.observes('post.hasGap'), - render: function(buffer) { + render(buffer) { if (this.get('loading')) { buffer.push(I18n.t('loading')); } else { - var gapLength = this.get('gap.length'); + const gapLength = this.get('gap.length'); if (gapLength) { buffer.push(I18n.t('post.gap', {count: gapLength})); } } }, - click: function() { + click() { if (this.get('loading') || (!this.get('gap'))) { return false; } this.set('loading', true); this.rerender(); - var self = this, - postStream = this.get('postStream'), - filler = this.get('before') === 'true' ? postStream.fillGapBefore : postStream.fillGapAfter; + const postStream = this.get('postStream'); + const filler = this.get('before') === 'true' ? postStream.fillGapBefore : postStream.fillGapAfter; - filler.call(postStream, this.get('post'), this.get('gap')).then(function() { - // hide this control after the promise is resolved - self.set('gap', null); + filler.call(postStream, this.get('post'), this.get('gap')).then(() => { + this.set('gap', null); }); return false; diff --git a/app/assets/javascripts/discourse/controllers/topic-entrance.js.es6 b/app/assets/javascripts/discourse/controllers/topic-entrance.js.es6 index 4f453b98f14..4a7fdf61c61 100644 --- a/app/assets/javascripts/discourse/controllers/topic-entrance.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic-entrance.js.es6 @@ -1,7 +1,7 @@ import DiscourseURL from 'discourse/lib/url'; function entranceDate(dt, showTime) { - var today = new Date(); + const today = new Date(); if (dt.toDateString() === today.toDateString()) { return moment(dt).format(I18n.t("dates.time")); @@ -44,7 +44,7 @@ export default Ember.Controller.extend({ }.property('bumpedDate'), actions: { - show: function(data) { + show(data) { // Show the chooser but only if the model changes if (this.get('model') !== data.topic) { this.set('model', data.topic); @@ -52,11 +52,11 @@ export default Ember.Controller.extend({ } }, - enterTop: function() { + enterTop() { DiscourseURL.routeTo(this.get('model.url')); }, - enterBottom: function() { + enterBottom() { DiscourseURL.routeTo(this.get('model.lastPostUrl')); } } diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 9f625f3477c..b2f903526e7 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -281,14 +281,13 @@ const PostStream = RestModel.extend({ // Fill in a gap of posts after a particular post fillGapAfter(post, gap) { const postId = post.get('id'), - stream = this.get('stream'), - idx = stream.indexOf(postId), - self = this; + stream = this.get('stream'), + idx = stream.indexOf(postId); if (idx !== -1) { stream.pushObjects(gap); - return this.appendMore().then(function() { - self.get('stream').enumerableContentDidChange(); + return this.appendMore().then(() => { + this.get('stream').enumerableContentDidChange(); }); } return Ember.RSVP.resolve(); @@ -296,24 +295,18 @@ const PostStream = RestModel.extend({ // Appends the next window of posts to the stream. Call it when scrolling downwards. appendMore() { - const self = this; - // Make sure we can append more posts - if (!self.get('canAppendMore')) { return Ember.RSVP.resolve(); } + if (!this.get('canAppendMore')) { return Ember.RSVP.resolve(); } - const postIds = self.get('nextWindow'); + const postIds = this.get('nextWindow'); if (Ember.isEmpty(postIds)) { return Ember.RSVP.resolve(); } - self.set('loadingBelow', true); + this.set('loadingBelow', true); - const stopLoading = function() { - self.set('loadingBelow', false); - }; + const stopLoading = () => this.set('loadingBelow', false); - return self.findPostsByIds(postIds).then(function(posts) { - posts.forEach(function(p) { - self.appendPost(p); - }); + return this.findPostsByIds(postIds).then((posts) => { + posts.forEach(p => this.appendPost(p)); stopLoading(); }, stopLoading); }, @@ -685,6 +678,12 @@ const PostStream = RestModel.extend({ const postIdentityMap = this.get('postIdentityMap'), existing = postIdentityMap.get(post.get('id')); + // Update the `highest_post_number` if this post is higher. + const postNumber = post.get('post_number'); + if (postNumber && postNumber > (this.get('topic.highest_post_number') || 0)) { + this.set('topic.highest_post_number', postNumber); + } + if (existing) { // If the post is in the identity map, update it and return the old reference. existing.updateFromPost(post); @@ -693,12 +692,6 @@ const PostStream = RestModel.extend({ post.set('topic', this.get('topic')); postIdentityMap.set(post.get('id'), post); - - // Update the `highest_post_number` if this post is higher. - const postNumber = post.get('post_number'); - if (postNumber && postNumber > (this.get('topic.highest_post_number') || 0)) { - this.set('topic.highest_post_number', postNumber); - } } return post; }, diff --git a/app/assets/javascripts/discourse/templates/components/topic-map.hbs b/app/assets/javascripts/discourse/templates/components/topic-map.hbs index b851f03bcdc..915c3f0e711 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-map.hbs +++ b/app/assets/javascripts/discourse/templates/components/topic-map.hbs @@ -14,7 +14,7 @@