Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-07-28 11:33:17 +0300
committerJulius Härtl <jus@bitgrid.net>2019-07-28 11:33:17 +0300
commit9e19106df3c75fa0bdadbb6284452f241e2b97df (patch)
tree90bc12062592b28dc8ae0680ca8eca2b46df9f69 /src
parent14697e6f17bafac386e8d62c61c91d2cbc5dbd8d (diff)
Autosave on close
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src')
-rw-r--r--src/components/EditorWrapper.vue9
-rw-r--r--src/services/PollingBackend.js3
-rw-r--r--src/services/SyncService.js25
3 files changed, 31 insertions, 6 deletions
diff --git a/src/components/EditorWrapper.vue b/src/components/EditorWrapper.vue
index 5ba8da8ea..8b847c528 100644
--- a/src/components/EditorWrapper.vue
+++ b/src/components/EditorWrapper.vue
@@ -300,6 +300,7 @@ export default {
})
})
.on('sync', ({ steps, document }) => {
+ this.hasConnectionIssue = false
try {
this.tiptap.extensions.options.collaboration.update({
version: document.currentVersion,
@@ -322,7 +323,7 @@ export default {
data: data
}
}
- if (error === ERROR_TYPE.CONNECTION_FAILED) {
+ if (error === ERROR_TYPE.CONNECTION_FAILED && !this.hasConnectionIssue) {
this.hasConnectionIssue = true
// FIXME: ideally we just try to reconnect in the service, so we don't loose steps
OC.Notification.showTemporary('Connection failed, reconnecting')
@@ -363,12 +364,12 @@ export default {
},
reconnect() {
- this.syncService.close().catch((e) => {
- // Ignore issues closing the session since those might happen due to network issues
- }).finally(() => {
+ this.syncService.close().then(() => {
this.syncService = null
this.tiptap.destroy()
this.initSession()
+ }).catch((e) => {
+ // Ignore issues closing the session since those might happen due to network issues
})
},
diff --git a/src/services/PollingBackend.js b/src/services/PollingBackend.js
index 48382dcc8..7f78021aa 100644
--- a/src/services/PollingBackend.js
+++ b/src/services/PollingBackend.js
@@ -117,6 +117,7 @@ class PollingBackend {
if (this._authority.document.lastSavedVersion < response.data.document.lastSavedVersion) {
console.debug('Saved document', response.data.document)
+ this._authority.emit('save', { document: response.data.document, sessions: response.data.sessions })
}
this._authority.emit('change', { document: response.data.document, sessions: response.data.sessions })
@@ -145,6 +146,7 @@ class PollingBackend {
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, {})
+
} else {
console.error(`[PollingBackend:fetchSteps] Network error when fetching steps, retry ${this.fetchRetryCounter}`)
}
@@ -192,6 +194,7 @@ class PollingBackend {
this.lock = false
if (!e.response) {
this._authority.emit('error', ERROR_TYPE.CONNECTION_FAILED, {})
+ return
} else if (e.response.status === 403 && e.response.data.document.currentVersion === this._authority.document.currentVersion) {
// Only emit conflict event if we have synced until the latest version
this._authority.emit('error', ERROR_TYPE.PUSH_FAILURE, {})
diff --git a/src/services/SyncService.js b/src/services/SyncService.js
index c41f472ba..c2246153c 100644
--- a/src/services/SyncService.js
+++ b/src/services/SyncService.js
@@ -65,7 +65,9 @@ class SyncService {
/* error */
error: [],
/* Events for session and document meta data */
- change: []
+ change: [],
+ /* Emitted after successful save */
+ save: []
}
this.backend = new PollingBackend(this)
@@ -226,7 +228,26 @@ class SyncService {
}
close() {
- // TODO: save before close
+ let closed = false
+ return new Promise((resolve, reject) => {
+ this.on('save', () => {
+ this._close().then(() => {
+ closed = true
+ resolve()
+ }).catch(() => resolve())
+ })
+ setTimeout(() => {
+ if (!closed) {
+ this._close().then(() => {
+ resolve()
+ }).catch(() => resolve())
+ }
+ }, 2000)
+ this.save()
+ })
+ }
+
+ _close() {
if (this.document === null || this.session === null) {
return Promise.resolve()
}