FIX: A post via the message bus wasn't updating highest_post_number properly.

This commit is contained in:
Robin Ward 2013-12-03 16:25:26 -05:00
parent 915861a646
commit cb9fb2acfa
3 changed files with 13 additions and 4 deletions

View File

@ -271,7 +271,8 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
streamPercentage: function() {
if (!this.get('postStream.loaded')) { return 0; }
if (this.get('postStream.highest_post_number') === 0) { return 0; }
return this.get('progressPosition') / this.get('highest_post_number');
var perc = this.get('progressPosition') / this.get('highest_post_number');
return (perc > 1.0) ? 1.0 : perc;
}.property('postStream.loaded', 'progressPosition', 'highest_post_number'),
multiSelectChanged: function() {

View File

@ -563,6 +563,12 @@ Discourse.PostStream = Em.Object.extend({
post.set('topic', this.get('topic'));
postIdentityMap.set(post.get('id'), post);
// Update the `highest_post_number` if this post is higher.
var postNumber = post.get('post_number');
if (postNumber && postNumber > (this.get('topic.highest_post_number') || 0)) {
this.set('topic.highest_post_number', postNumber);
}
}
return post;
},

View File

@ -206,14 +206,16 @@ test("previousWindow", function() {
});
test("storePost", function() {
var postStream = buildStream(1234);
var postStream = buildStream(1234),
post = Discourse.Post.create({id: 1, post_number: 100, raw: 'initial value'});
var post = Discourse.Post.create({id: 1, post_number: 1, raw: 'initial value'});
blank(postStream.get('topic.highest_post_number'), "it has no highest post number yet");
var stored = postStream.storePost(post);
equal(post, stored, "it returns the post it stored");
equal(post.get('topic'), postStream.get('topic'), "it creates the topic reference properly");
equal(postStream.get('topic.highest_post_number'), 100, "it set the highest post number");
var dupePost = Discourse.Post.create({id: 1, post_number: 1, raw: 'updated value'});
var dupePost = Discourse.Post.create({id: 1, post_number: 100, raw: 'updated value'});
var storedDupe = postStream.storePost(dupePost);
equal(storedDupe, post, "it returns the previously stored post instead to avoid dupes");
equal(storedDupe.get('raw'), 'updated value', 'it updates the previously stored post');