From 602ed1525a696484ad80b95a4b1af976b586606c Mon Sep 17 00:00:00 2001 From: nicofrand Date: Fri, 29 Mar 2024 14:54:43 +0100 Subject: [PATCH] Request the native app to reload the direct editing view on 403 errors Signed-off-by: nicofrand --- src/components/Editor.vue | 6 ++++++ src/services/SyncService.js | 3 +++ src/views/DirectEditing.vue | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 0217e4babc1..c12dca0b194 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -597,6 +597,12 @@ export default { this.hasConnectionIssue = true } + if (type === ERROR_TYPE.PUSH_FORBIDDEN) { + this.hasConnectionIssue = true + this.emit('push:forbidden') + return + } + this.emit('ready') }, diff --git a/src/services/SyncService.js b/src/services/SyncService.js index 349dd75f0d0..527686e41fd 100644 --- a/src/services/SyncService.js +++ b/src/services/SyncService.js @@ -47,6 +47,8 @@ const ERROR_TYPE = { CONNECTION_FAILED: 3, SOURCE_NOT_FOUND: 4, + + PUSH_FORBIDDEN: 5, } class SyncService { @@ -170,6 +172,7 @@ class SyncService { if (!data.document) { // either the session is invalid or the document is read only. logger.error('failed to write to document - not allowed') + this.emit('error', { type: ERROR_TYPE.PUSH_FORBIDDEN, data: {} }) } // Only emit conflict event if we have synced until the latest version if (response.data.document?.currentVersion === this.version) { diff --git a/src/views/DirectEditing.vue b/src/views/DirectEditing.vue index d6b1b1581f3..f93c0938841 100644 --- a/src/views/DirectEditing.vue +++ b/src/views/DirectEditing.vue @@ -97,6 +97,11 @@ export default { }, mounted() { document.querySelector('meta[name="viewport"]').setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0') + + this.$refs.editor.$on('push:forbidden', () => { + logger.warn('push was forbidden due to invalidated session') + this.reload() + }) }, methods: { async close() { @@ -112,6 +117,9 @@ export default { loaded() { callMobileMessage('loaded') }, + reload() { + callMobileMessage('reload') + }, }, }