diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-06-21 13:50:40 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-06-21 13:50:40 +0300 |
commit | 9522d31e9d46be1e9e169a7b6e27229af81aa86b (patch) | |
tree | 56725137983f263cc32def80bae21f5d64b5469a | |
parent | 3067a8b33aeae361e1d47de586d96e8e68d3b96b (diff) |
Sync documents before handling conflicts
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r-- | lib/Service/ApiService.php | 7 | ||||
-rw-r--r-- | lib/Service/DocumentService.php | 4 | ||||
-rw-r--r-- | src/services/PollingBackend.js | 3 |
3 files changed, 11 insertions, 3 deletions
diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 351e8fe89..8ff6ddcd5 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -160,7 +160,10 @@ class ApiService { $file = $this->documentService->getFileById($documentId); } return new DataResponse([ - 'outsideChange' => $file->getContent() + 'outsideChange' => $file->getContent(), + 'steps' => $this->documentService->getSteps($documentId, $version), + 'sessions' => $this->sessionService->getActiveSessions($documentId), + 'document' => $this->documentService->get($documentId) ], 409); } catch (Exception $e) { return new DataResponse([ @@ -171,7 +174,7 @@ class ApiService { return new DataResponse([ 'steps' => $this->documentService->getSteps($documentId, $version), 'sessions' => $this->sessionService->getActiveSessions($documentId), - 'document' => $document + 'document' => $document ?? $document = $this->documentService->get($documentId) ]); } diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 513b4116b..e35898f77 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -161,6 +161,10 @@ class DocumentService { return $this->appData->getFolder('documents')->getFile($document); } + public function get($documentId) { + return $this->documentMapper->find($documentId); + } + /** * @param $documentId * @param $sessionId diff --git a/src/services/PollingBackend.js b/src/services/PollingBackend.js index 79c4dba03..563ecdea2 100644 --- a/src/services/PollingBackend.js +++ b/src/services/PollingBackend.js @@ -138,7 +138,8 @@ class PollingBackend { if (!e.response) { throw e } - if (e.response.status === 409) { + // Only emit conflict event if we have synced until the latest version + if (e.response.status === 409 && e.response.data.document.currentVersion === this._authority.document.currentVersion) { console.error('Conflict during file save, please resolve') this._authority.emit('error', ERROR_TYPE.SAVE_COLLISSION, { outsideChange: e.response.data.outsideChange |