FIX: Recovering a post does not insert it back into the stream correctly.
This commit is contained in:
parent
252e5574cc
commit
d1c3eb6bfa
|
@ -1096,13 +1096,13 @@ export default Ember.Controller.extend(BufferedContent, {
|
||||||
}
|
}
|
||||||
case "deleted": {
|
case "deleted": {
|
||||||
postStream
|
postStream
|
||||||
.triggerDeletedPost(data.id, data.post_number)
|
.triggerDeletedPost(data.id)
|
||||||
.then(() => refresh({ id: data.id }));
|
.then(() => refresh({ id: data.id }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "recovered": {
|
case "recovered": {
|
||||||
postStream
|
postStream
|
||||||
.triggerRecoveredPost(data.id, data.post_number)
|
.triggerRecoveredPost(data.id)
|
||||||
.then(() => refresh({ id: data.id }));
|
.then(() => refresh({ id: data.id }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -565,8 +565,9 @@ export default RestModel.extend({
|
||||||
return this.triggerChangedPost(postId, new Date());
|
return this.triggerChangedPost(postId, new Date());
|
||||||
} else {
|
} else {
|
||||||
// need to insert into stream
|
// need to insert into stream
|
||||||
const url = "/posts/" + postId;
|
const url = `/posts/${postId}`;
|
||||||
const store = this.store;
|
const store = this.store;
|
||||||
|
|
||||||
return ajax(url).then(p => {
|
return ajax(url).then(p => {
|
||||||
const post = store.createRecord("post", p);
|
const post = store.createRecord("post", p);
|
||||||
const stream = this.get("stream");
|
const stream = this.get("stream");
|
||||||
|
@ -591,7 +592,9 @@ export default RestModel.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
if (index < posts.length) {
|
if (index < posts.length) {
|
||||||
posts.insertAt(index, post);
|
this.get("postsWithPlaceholders").refreshAll(() => {
|
||||||
|
posts.insertAt(index, post);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (post.post_number < posts[posts.length - 1].post_number + 5) {
|
if (post.post_number < posts[posts.length - 1].post_number + 5) {
|
||||||
this.appendMore();
|
this.appendMore();
|
||||||
|
|
|
@ -681,6 +681,40 @@ QUnit.test("loadedAllPosts when the id changes", assert => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test("triggerRecoveredPost", async assert => {
|
||||||
|
const postStream = buildStream(4567);
|
||||||
|
const store = postStream.store;
|
||||||
|
|
||||||
|
[1, 2, 3, 5].forEach(id => {
|
||||||
|
postStream.appendPost(
|
||||||
|
store.createRecord("post", { id: id, post_number: id })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = object => {
|
||||||
|
return [200, { "Content-Type": "application/json" }, object];
|
||||||
|
};
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
server.get("/posts/4", () => { // eslint-disable-line no-undef
|
||||||
|
return response({ id: 4, post_number: 4 });
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
postStream.get("postsWithPlaceholders.length"),
|
||||||
|
4,
|
||||||
|
"it should return the right length"
|
||||||
|
);
|
||||||
|
|
||||||
|
await postStream.triggerRecoveredPost(4);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
postStream.get("postsWithPlaceholders.length"),
|
||||||
|
5,
|
||||||
|
"it should return the right length"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
|
QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
|
||||||
const postStream = buildStream(4964);
|
const postStream = buildStream(4964);
|
||||||
const store = postStream.store;
|
const store = postStream.store;
|
||||||
|
|
Loading…
Reference in New Issue