mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 11:58:47 +08:00
FIX: A post via the message bus wasn't updating highest_post_number
properly.
This commit is contained in:
parent
915861a646
commit
cb9fb2acfa
|
@ -271,7 +271,8 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
||||||
streamPercentage: function() {
|
streamPercentage: function() {
|
||||||
if (!this.get('postStream.loaded')) { return 0; }
|
if (!this.get('postStream.loaded')) { return 0; }
|
||||||
if (this.get('postStream.highest_post_number') === 0) { 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'),
|
}.property('postStream.loaded', 'progressPosition', 'highest_post_number'),
|
||||||
|
|
||||||
multiSelectChanged: function() {
|
multiSelectChanged: function() {
|
||||||
|
|
|
@ -563,6 +563,12 @@ Discourse.PostStream = Em.Object.extend({
|
||||||
|
|
||||||
post.set('topic', this.get('topic'));
|
post.set('topic', this.get('topic'));
|
||||||
postIdentityMap.set(post.get('id'), post);
|
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;
|
return post;
|
||||||
},
|
},
|
||||||
|
|
|
@ -206,14 +206,16 @@ test("previousWindow", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("storePost", 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);
|
var stored = postStream.storePost(post);
|
||||||
equal(post, stored, "it returns the post it stored");
|
equal(post, stored, "it returns the post it stored");
|
||||||
equal(post.get('topic'), postStream.get('topic'), "it creates the topic reference properly");
|
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);
|
var storedDupe = postStream.storePost(dupePost);
|
||||||
equal(storedDupe, post, "it returns the previously stored post instead to avoid dupes");
|
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');
|
equal(storedDupe.get('raw'), 'updated value', 'it updates the previously stored post');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user