Skip to content

Commit 0c259af

Browse files
committed
FIX: Don't give weird progress numbers when there are deleted posts.
1 parent b37fae5 commit 0c259af

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

app/assets/javascripts/discourse/controllers/topic_controller.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
220220
},
221221

222222
jumpTopDisabled: function() {
223-
return (this.get('progressPosition') === 1);
224-
}.property('postStream.filteredPostsCount', 'progressPosition'),
223+
return (this.get('progressPosition') <= 3);
224+
}.property('progressPosition'),
225225

226226
jumpBottomDisabled: function() {
227-
return this.get('progressPosition') >= this.get('postStream.filteredPostsCount');
228-
}.property('postStream.filteredPostsCount', 'progressPosition'),
227+
return this.get('progressPosition') >= this.get('postStream.filteredPostsCount') ||
228+
this.get('progressPosition') >= this.get('highest_post_number');
229+
}.property('postStream.filteredPostsCount', 'highest_post_number', 'progressPosition'),
229230

230231
canMergeTopic: function() {
231232
if (!this.get('details.can_move_posts')) return false;
@@ -269,9 +270,9 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
269270

270271
streamPercentage: function() {
271272
if (!this.get('postStream.loaded')) { return 0; }
272-
if (this.get('postStream.filteredPostsCount') === 0) { return 0; }
273-
return this.get('progressPosition') / this.get('postStream.filteredPostsCount');
274-
}.property('postStream.loaded', 'progressPosition', 'postStream.filteredPostsCount'),
273+
if (this.get('postStream.highest_post_number') === 0) { return 0; }
274+
return this.get('progressPosition') / this.get('highest_post_number');
275+
}.property('postStream.loaded', 'progressPosition', 'highest_post_number'),
275276

276277
multiSelectChanged: function() {
277278
// Deselect all posts when multi select is turned off

app/assets/javascripts/discourse/models/post_stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ Discourse.PostStream = Em.Object.extend({
188188
var stream = this.get('stream');
189189
var lastIndex = this.indexOf(lastLoadedPost);
190190
if (lastIndex === -1) { return []; }
191-
if ((lastIndex + 1) >= this.get('filteredPostsCount')) { return []; }
191+
if ((lastIndex + 1) >= this.get('highest_post_number')) { return []; }
192192

193193
// find our window of posts
194194
return stream.slice(lastIndex+1, lastIndex+Discourse.SiteSettings.posts_per_page+1);

app/assets/javascripts/discourse/templates/topic.js.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<nav id='topic-progress' title="{{i18n topic.progress.title}}" {{bindAttr class="hideProgress:hidden"}}>
5353
<button id='jump-top' title="{{i18n topic.progress.jump_top}}" {{bindAttr disabled="jumpTopDisabled"}} {{action jumpTop}}><i class="icon-circle-arrow-up"></i></button>
5454
<div class='nums'>
55-
<h4 title="{{i18n topic.progress.current}}">{{progressPosition}}</h4> <span>{{i18n of_value}}</span> <h4>{{postStream.filteredPostsCount}}</h4>
55+
<h4 title="{{i18n topic.progress.current}}">{{progressPosition}}</h4> <span>{{i18n of_value}}</span> <h4>{{highest_post_number}}</h4>
5656
</div>
5757
<button id='jump-bottom' title="{{i18n topic.progress.jump_bottom}}" {{bindAttr disabled="jumpBottomDisabled"}} {{action jumpBottom}}><i class="icon-circle-arrow-down"></i></button>
5858
<div class='bg'>&nbsp;</div>

0 commit comments

Comments
 (0)