diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index f882b258d1b..8ac58459708 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -16,6 +16,7 @@ function calcDayDiff(p1, p2) { } } } + const PostStream = RestModel.extend({ loading: Em.computed.or('loadingAbove', 'loadingBelow', 'loadingFilter', 'stagingPost'), notLoading: Em.computed.not('loading'), @@ -137,7 +138,13 @@ const PostStream = RestModel.extend({ toggleSummary() { this.get('userFilters').clear(); this.toggleProperty('summary'); - return this.refresh(); + + const self = this; + return this.refresh().then(function() { + if (self.get('summary')) { + self.jumpToSecondVisible(); + } + }); }, toggleDeleted() { @@ -145,17 +152,33 @@ const PostStream = RestModel.extend({ return this.refresh(); }, + jumpToSecondVisible() { + const posts = this.get('posts'); + if (posts.length > 1) { + const secondPostNum = posts[1].get('post_number'); + Discourse.URL.jumpToPost(secondPostNum); + } + }, + // Filter the stream to a particular user. toggleParticipant(username) { const userFilters = this.get('userFilters'); this.set('summary', false); this.set('show_deleted', true); + + let jump = false; if (userFilters.contains(username)) { userFilters.removeObject(username); } else { userFilters.addObject(username); + jump = true; } - return this.refresh(); + const self = this; + return this.refresh().then(function() { + if (jump) { + self.jumpToSecondVisible(); + } + }); }, /**