Skip to content

Commit

Permalink
Merge pull request #4286 from nextcloud/fix/3404-always-save-on-close
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Jun 19, 2023
2 parents 3e347d5 + 6aa598b commit 1393fc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
15 changes: 0 additions & 15 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,11 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('empty.md').then((content) => {
Expand All @@ -87,17 +82,12 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('newfile.md').then((content) => {
Expand All @@ -114,17 +104,12 @@ describe('direct editing', function() {
})
const closeRequestAlias = 'closeRequest'
cy.intercept({ method: 'POST', url: '**/session/close' }).as(closeRequestAlias)
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')

cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')

// ensure we have received our own steps
cy.wait('@sync', { timeout: 7000 })
cy.wait('@sync', { timeout: 7000 })

cy.get('button.icon-close').click()
cy.wait(`@${closeRequestAlias}`).then(() => {
cy.getFileContent('empty.txt').then((content) => {
Expand Down
8 changes: 6 additions & 2 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,13 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
if ($autoSaveDocument === null) {
return $document;
}
// Do not save if version already saved
// Do not save if newer version already saved
// Note that $version is the version of the steps the client has fetched.
// It may have added steps on top of that - so if the versions match we still save.
$stepsVersion = $this->stepMapper->getLatestVersion($documentId);
if (!$force && ($version <= (string)$document->getLastSavedVersion() || $version > (string)$stepsVersion)) {
$savedVersion = $document->getLastSavedVersion();
$outdated = $savedVersion > 0 && $savedVersion > $version;
if (!$force && ($outdated || $version > (string)$stepsVersion)) {
return $document;
}

Expand Down

0 comments on commit 1393fc8

Please sign in to comment.