Skip to content

Commit

Permalink
fix: Clean up logic to return document state file or file content
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and mejo- committed Mar 20, 2024
1 parent b3097cf commit e268115
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/api/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ describe('The session Api', function() {
})
})

it('sends initial content if other session is alive but did not push any steps', function() {
it('does not send initial content if other session is alive but did not push any steps', function() {
let joining
cy.createTextSession(undefined, { filePath: '', shareToken })
.then(con => {
joining = con
return con
})
.its('state.documentSource')
.should('not.eql', '')
.should('eql', '')
.then(() => joining.close())
.then(() => connection.close())
})
Expand Down
14 changes: 4 additions & 10 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,19 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $t

$session = $this->sessionService->initSession($document->getId(), $guestName);

$documentState = null;
$content = null;
if ($freshSession) {
$this->logger->debug('Starting a fresh editing session for ' . $file->getId());
$documentState = null;
$content = $this->loadContent($file);
} else {
$this->logger->debug('Loading existing session for ' . $file->getId());
$content = null;
try {
$stateFile = $this->documentService->getStateFile($document->getId());
$documentState = $stateFile->getContent();
$this->logger->debug('Existing document, state file loaded ' . $file->getId());
} catch (NotFoundException $e) {
$this->logger->debug('State file not found for ' . $file->getId());
$documentState = ''; // no state saved yet.
// If there are no steps yet we might still need the content.
$steps = $this->documentService->getSteps($document->getId(), 0);
if (empty($steps)) {
$this->logger->debug('Empty steps, loading content for ' . $file->getId());
$content = $this->loadContent($file);
}
$this->logger->debug('Existing document, but state file not found for ' . $file->getId());
}
}

Expand Down

0 comments on commit e268115

Please sign in to comment.