FIX: The time gap would disappear after a post was comitted
This commit is contained in:
parent
d12de36c82
commit
00572c4f11
|
@ -397,8 +397,13 @@ const PostStream = RestModel.extend({
|
||||||
const stored = this.storePost(post);
|
const stored = this.storePost(post);
|
||||||
if (stored) {
|
if (stored) {
|
||||||
const posts = this.get('posts');
|
const posts = this.get('posts');
|
||||||
calcDayDiff(stored, posts.get('lastObject'));
|
|
||||||
|
calcDayDiff(stored, this.get('lastAppended'));
|
||||||
posts.addObject(stored);
|
posts.addObject(stored);
|
||||||
|
|
||||||
|
if (stored.get('id') !== -1) {
|
||||||
|
this.set('lastAppended', stored);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return post;
|
return post;
|
||||||
},
|
},
|
||||||
|
|
|
@ -349,7 +349,9 @@ test("staging and undoing a new post", function() {
|
||||||
const postStream = buildStream(10101, [1]);
|
const postStream = buildStream(10101, [1]);
|
||||||
const store = postStream.store;
|
const store = postStream.store;
|
||||||
|
|
||||||
postStream.appendPost(store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101}));
|
const original = store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101});
|
||||||
|
postStream.appendPost(original);
|
||||||
|
ok(postStream.get('lastAppended'), original, "the original post is lastAppended");
|
||||||
|
|
||||||
const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
||||||
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 });
|
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 });
|
||||||
|
@ -365,6 +367,7 @@ test("staging and undoing a new post", function() {
|
||||||
equal(result, "staged", "it returns staged");
|
equal(result, "staged", "it returns staged");
|
||||||
equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number");
|
equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number");
|
||||||
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||||
|
ok(postStream.get('lastAppended'), original, "it doesn't consider staged posts as the lastAppended");
|
||||||
|
|
||||||
equal(topic.get('posts_count'), 2, "it increases the post count");
|
equal(topic.get('posts_count'), 2, "it increases the post count");
|
||||||
present(topic.get('last_posted_at'), "it updates last_posted_at");
|
present(topic.get('last_posted_at'), "it updates last_posted_at");
|
||||||
|
@ -384,13 +387,17 @@ test("staging and undoing a new post", function() {
|
||||||
equal(topic.get('posts_count'), 1, "it reverts the post count");
|
equal(topic.get('posts_count'), 1, "it reverts the post count");
|
||||||
equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount");
|
equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount");
|
||||||
ok(!postStream.get('posts').contains(stagedPost), "the post is removed from the stream");
|
ok(!postStream.get('posts').contains(stagedPost), "the post is removed from the stream");
|
||||||
|
ok(postStream.get('lastAppended'), original, "it doesn't consider undid post lastAppended");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("staging and committing a post", function() {
|
test("staging and committing a post", function() {
|
||||||
const postStream = buildStream(10101, [1]);
|
const postStream = buildStream(10101, [1]);
|
||||||
const store = postStream.store;
|
const store = postStream.store;
|
||||||
|
|
||||||
postStream.appendPost(store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101}));
|
const original = store.createRecord('post', {id: 1, post_number: 1, topic_id: 10101});
|
||||||
|
postStream.appendPost(original);
|
||||||
|
ok(postStream.get('lastAppended'), original, "the original post is lastAppended");
|
||||||
|
|
||||||
const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
const user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321});
|
||||||
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 });
|
const stagedPost = store.createRecord('post', { raw: 'hello world this is my new post', topic_id: 10101 });
|
||||||
|
|
||||||
|
@ -406,6 +413,7 @@ test("staging and committing a post", function() {
|
||||||
|
|
||||||
result = postStream.stagePost(stagedPost, user);
|
result = postStream.stagePost(stagedPost, user);
|
||||||
equal(result, "alreadyStaging", "you can't stage a post while it is currently staging");
|
equal(result, "alreadyStaging", "you can't stage a post while it is currently staging");
|
||||||
|
ok(postStream.get('lastAppended'), original, "staging a post doesn't change the lastAppended");
|
||||||
|
|
||||||
postStream.commitPost(stagedPost);
|
postStream.commitPost(stagedPost);
|
||||||
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
||||||
|
@ -417,7 +425,7 @@ test("staging and committing a post", function() {
|
||||||
present(found, "the post is in the identity map");
|
present(found, "the post is in the identity map");
|
||||||
ok(postStream.indexOf(stagedPost) > -1, "the post is in the stream");
|
ok(postStream.indexOf(stagedPost) > -1, "the post is in the stream");
|
||||||
equal(found.get('raw'), 'different raw value', 'it also updated the value in the stream');
|
equal(found.get('raw'), 'different raw value', 'it also updated the value in the stream');
|
||||||
|
ok(postStream.get('lastAppended'), found, "comitting a post changes lastAppended");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('triggerNewPostInStream', function() {
|
test('triggerNewPostInStream', function() {
|
||||||
|
|
Loading…
Reference in New Issue