Updated PostRevisions to accept html string
- We also fix the name of the feature flag - We also correctly await the result of revision generation - We pass the HTML string so we can potentially do an easier word count diff
This commit is contained in:
parent
79a95268b6
commit
a507072eb8
@ -864,8 +864,8 @@ Post = ghostBookshelf.Model.extend({
|
||||
});
|
||||
}
|
||||
|
||||
if (model.hasChanged('lexical') && !model.get('mobiledoc') && !options.importing && !options.migrating) {
|
||||
if (!labs.isSet('postsHistory')) {
|
||||
if (!labs.isSet('postHistory')) {
|
||||
if (model.hasChanged('lexical') && !model.get('mobiledoc') && !options.importing && !options.migrating) {
|
||||
ops.push(function updateRevisions() {
|
||||
return ghostBookshelf.model('PostRevision')
|
||||
.findAll(Object.assign({
|
||||
@ -895,7 +895,9 @@ Post = ghostBookshelf.Model.extend({
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
if (!model.get('mobiledoc') && !options.importing && !options.migrating) {
|
||||
const postRevisions = new PostRevisions({
|
||||
config: {
|
||||
max_revisions: POST_REVISIONS_COUNT
|
||||
@ -911,17 +913,17 @@ Post = ghostBookshelf.Model.extend({
|
||||
const revisions = revisionModels.toJSON();
|
||||
const previous = {
|
||||
id: model.id,
|
||||
lexical: model.previous('lexical')
|
||||
lexical: model.previous('lexical'),
|
||||
html: model.previous('html')
|
||||
};
|
||||
const current = {
|
||||
id: model.id,
|
||||
lexical: model.get('lexical')
|
||||
lexical: model.get('lexical'),
|
||||
html: model.get('html')
|
||||
};
|
||||
|
||||
model.set(
|
||||
'post_revisions',
|
||||
postRevisions.getRevisions(previous, current, revisions)
|
||||
);
|
||||
const newRevisions = await postRevisions.getRevisions(previous, current, revisions);
|
||||
model.set('post_revisions', newRevisions);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
* @typedef {object} PostLike
|
||||
* @property {string} id
|
||||
* @property {string} lexical
|
||||
* @property {string} html
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -34,7 +35,7 @@ class PostRevisions {
|
||||
if (revisions.length === 0) {
|
||||
return true;
|
||||
}
|
||||
return previous.lexical !== current.lexical;
|
||||
return previous.html !== current.html;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,14 +25,16 @@ describe('PostRevisions', function () {
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
it('should return false if the current and previous lexical values are the same', function () {
|
||||
it('should return false if the current and previous html values are the same', function () {
|
||||
const postRevisions = new PostRevisions({config});
|
||||
|
||||
const expected = false;
|
||||
const actual = postRevisions.shouldGenerateRevision({
|
||||
lexical: 'blah'
|
||||
lexical: 'previous',
|
||||
html: 'blah'
|
||||
}, {
|
||||
lexical: 'blah'
|
||||
lexical: 'current',
|
||||
html: 'blah'
|
||||
}, [{
|
||||
lexical: 'blah'
|
||||
}]);
|
||||
@ -40,14 +42,16 @@ describe('PostRevisions', function () {
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
it('should return true if the current and previous lexical values are different', function () {
|
||||
it('should return true if the current and previous html values are different', function () {
|
||||
const postRevisions = new PostRevisions({config});
|
||||
|
||||
const expected = true;
|
||||
const actual = postRevisions.shouldGenerateRevision({
|
||||
lexical: 'blah'
|
||||
lexical: 'blah',
|
||||
html: 'blah'
|
||||
}, {
|
||||
lexical: 'blah2'
|
||||
lexical: 'blah',
|
||||
html: 'blah2'
|
||||
}, [{
|
||||
lexical: 'blah'
|
||||
}]);
|
||||
@ -77,9 +81,11 @@ describe('PostRevisions', function () {
|
||||
lexical: 'revision'
|
||||
}];
|
||||
const actual = await postRevisions.getRevisions({
|
||||
lexical: 'blah'
|
||||
lexical: 'blah',
|
||||
html: 'blah'
|
||||
}, {
|
||||
lexical: 'blah'
|
||||
lexical: 'blah',
|
||||
html: 'blah'
|
||||
}, [{
|
||||
lexical: 'revision'
|
||||
}]);
|
||||
@ -92,10 +98,12 @@ describe('PostRevisions', function () {
|
||||
|
||||
const actual = await postRevisions.getRevisions({
|
||||
id: '1',
|
||||
lexical: 'previous'
|
||||
lexical: 'previous',
|
||||
html: 'previous'
|
||||
}, {
|
||||
id: '1',
|
||||
lexical: 'current'
|
||||
lexical: 'current',
|
||||
html: 'current'
|
||||
}, []);
|
||||
|
||||
assert.equal(actual.length, 2);
|
||||
@ -112,18 +120,22 @@ describe('PostRevisions', function () {
|
||||
|
||||
const revisions = await postRevisions.getRevisions({
|
||||
id: '1',
|
||||
lexical: 'previous'
|
||||
lexical: 'previous',
|
||||
html: 'previous'
|
||||
}, {
|
||||
id: '1',
|
||||
lexical: 'current'
|
||||
lexical: 'current',
|
||||
html: 'current'
|
||||
}, []);
|
||||
|
||||
const actual = await postRevisions.getRevisions({
|
||||
id: '1',
|
||||
lexical: 'old'
|
||||
lexical: 'old',
|
||||
html: 'old'
|
||||
}, {
|
||||
id: '1',
|
||||
lexical: 'new'
|
||||
lexical: 'new',
|
||||
html: 'new'
|
||||
}, revisions);
|
||||
|
||||
assert.equal(actual.length, 2);
|
||||
|
Loading…
Reference in New Issue
Block a user