Skip to content

Commit

Permalink
Merge pull request #1221 from nextcloud/backport/stable20/1202
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Dec 17, 2020
2 parents 45a37fe + 72746fc commit c748b7f
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 32 deletions.
12 changes: 6 additions & 6 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer.js.map

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCA\Text\DocumentHasUnsavedChangesException;
use OCA\Text\DocumentSaveConflictException;
use OCA\Text\VersionMismatchException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
Expand Down Expand Up @@ -161,20 +162,25 @@ public function sync($documentId, $sessionId, $sessionToken, $version = 0, $auto
return new DataResponse(['steps' => []]);
}

$result = [
'steps' => $this->documentService->getSteps($documentId, $version),
'sessions' => $this->sessionService->getActiveSessions($documentId),
'document' => $this->documentService->get($documentId)
];

$session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken);
try {
$result = [
'steps' => $this->documentService->getSteps($documentId, $version),
'sessions' => $this->sessionService->getActiveSessions($documentId),
'document' => $this->documentService->get($documentId)
];

$session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken);
$file = $this->documentService->getFileForSession($session, $token);
} catch (NotFoundException $e) {
$this->logger->logException($e, ['level' => ILogger::INFO]);
return new DataResponse([
'message' => 'File not found'
], 404);
} catch (DoesNotExistException $e) {
$this->logger->logException($e, ['level' => ILogger::INFO]);
return new DataResponse([
'message' => 'Document no longer exists'
], 404);
}

try {
Expand Down
9 changes: 8 additions & 1 deletion lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use \InvalidArgumentException;
use OCA\Text\Db\Session;
use OCA\Text\Db\SessionMapper;
use OCP\DirectEditing\IManager;
use OCP\IRequest;
use OCP\Lock\ILockingProvider;
Expand Down Expand Up @@ -73,6 +74,10 @@ class DocumentService {
* @var DocumentMapper
*/
private $documentMapper;
/**
* @var SessionMapper
*/
private $sessionMapper;
/**
* @var ILogger
*/
Expand All @@ -98,9 +103,10 @@ class DocumentService {
*/
private $appData;

public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, IAppData $appData, $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, ILogger $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockingProvider $lockingProvider) {
public function __construct(DocumentMapper $documentMapper, StepMapper $stepMapper, SessionMapper $sessionMapper, IAppData $appData, $userId, IRootFolder $rootFolder, ICacheFactory $cacheFactory, ILogger $logger, ShareManager $shareManager, IRequest $request, IManager $directManager, ILockingProvider $lockingProvider) {
$this->documentMapper = $documentMapper;
$this->stepMapper = $stepMapper;
$this->sessionMapper = $sessionMapper;
$this->userId = $userId;
$this->appData = $appData;
$this->rootFolder = $rootFolder;
Expand Down Expand Up @@ -342,6 +348,7 @@ public function resetDocument($documentId, $force = false): void {

if ($force || !$this->hasUnsavedChanges($document)) {
$this->stepMapper->deleteAll($documentId);
$this->sessionMapper->deleteByDocumentId($documentId);
$this->documentMapper->delete($document);

try {
Expand Down
13 changes: 7 additions & 6 deletions src/components/EditorWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<p v-if="hasSyncCollission" class="msg icon-error">
{{ t('text', 'The document has been changed outside of the editor. The changes cannot be applied.') }}
</p>
<p v-if="hasConnectionIssue" class="msg icon-info">
<p v-else-if="hasConnectionIssue" class="msg icon-info">
{{ t('text', 'File could not be loaded. Please check your internet connection.') }} <a class="button primary" @click="reconnect">{{ t('text', 'Retry') }}</a>
</p>
</div>
<div v-if="currentSession && active" id="editor-wrapper" :class="{'has-conflicts': hasSyncCollission, 'icon-loading': !initialLoading || hasConnectionIssue, 'richEditor': isRichEditor}">
<div v-if="currentSession && active" id="editor-wrapper" :class="{'has-conflicts': hasSyncCollission, 'icon-loading': !initialLoading && !hasConnectionIssue, 'richEditor': isRichEditor}">
<div id="editor">
<MenuBar v-if="!syncError && !readOnly"
ref="menubar"
Expand All @@ -52,7 +52,7 @@
<div>
<MenuBubble v-if="!readOnly && isRichEditor"
:editor="tiptap"
:filePath="relativePath" />
:file-path="relativePath" />
<EditorContent v-show="initialLoading"
class="editor__content"
:editor="tiptap" />
Expand Down Expand Up @@ -375,10 +375,9 @@ export default {
}
}
if (error === ERROR_TYPE.SOURCE_NOT_FOUND) {
this.initialLoading = false
this.$emit('close')
this.$emit('error')
this.hasConnectionIssue = true
}
this.$emit('ready')
})
.on('stateChange', (state) => {
if (state.initialLoading && !this.initialLoading) {
Expand Down Expand Up @@ -421,6 +420,8 @@ export default {
},
reconnect() {
this.initialLoading = false
this.hasConnectionIssue = false
if (this.syncService) {
this.syncService.close().then(() => {
this.syncService = null
Expand Down
8 changes: 5 additions & 3 deletions src/services/PollingBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class PollingBackend {
if (!e.response || e.code === 'ECONNABORTED') {
if (this.fetchRetryCounter++ >= MAX_RETRY_FETCH_COUNT) {
console.error('[PollingBackend:fetchSteps] Network error when fetching steps, emitting CONNECTION_FAILED')
this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, {})
this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, { retry: false })

} else {
console.error(`[PollingBackend:fetchSteps] Network error when fetching steps, retry ${this.fetchRetryCounter}`)
Expand All @@ -158,14 +158,16 @@ class PollingBackend {
})
} else if (e.response.status === 403) {
this._authority.emit('error', ERROR_TYPE.SOURCE_NOT_FOUND, {})
this.disconnect()
} else if (e.response.status === 404) {
this._authority.emit('error', ERROR_TYPE.SOURCE_NOT_FOUND, {})
this.disconnect()
} else if (e.response.status === 503) {
this.increaseRefetchTimer()
this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, { retry: true })
this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, { retry: false })
console.error('Failed to fetch steps due to unavailable service', e)
} else {
this.increaseRefetchTimer()
this.disconnect()
this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, { retry: false })
console.error('Failed to fetch steps due to other reason', e)
}
Expand Down

0 comments on commit c748b7f

Please sign in to comment.