logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: 90afcd3420a911856bde794f2b4dc1380a1a0751
parent 2e7bd99444546b3a71e1ff0753e12e6706c8228e
Author: Henry Jameson <me@hjkos.com>
Date:   Mon,  8 Mar 2021 22:24:39 +0200

WIP some work on making errors less spammy

Diffstat:

Msrc/i18n/en.json3+--
Msrc/modules/api.js44++++++++++++++++++++++++++------------------
Msrc/services/notifications_fetcher/notifications_fetcher.service.js14++++++++------
Msrc/services/timeline_fetcher/timeline_fetcher.service.js14++++++++------
4 files changed, 43 insertions(+), 32 deletions(-)

diff --git a/src/i18n/en.json b/src/i18n/en.json @@ -664,8 +664,7 @@ "no_more_statuses": "No more statuses", "no_statuses": "No statuses", "socket_reconnected": "Realtime connection established", - "socket_broke": "Realtime connection lost: CloseEvent code {0}", - "socket_closed": "No realtime connection, updates can arrive with a delaye until connection is re-established" + "socket_broke": "Realtime connection lost: CloseEvent code {0}" }, "status": { "favorites": "Favorites", diff --git a/src/modules/api.js b/src/modules/api.js @@ -5,6 +5,8 @@ import { Socket } from 'phoenix' const api = { state: { + connectionBroken: false, + retryMultiplier: 1, backendInteractor: backendInteractorService(), fetchers: {}, socket: null, @@ -34,12 +36,18 @@ const api = { }, setMastoUserSocketStatus (state, value) { state.mastoUserSocketStatus = value + }, + recoverConnection (state) { + state.connectionBroken = false + }, + breakConnection (state) { + state.connectionBroken = true } }, actions: { // Global MastoAPI socket control, in future should disable ALL sockets/(re)start relevant sockets enableMastoSockets (store) { - const { state, dispatch } = store + const { state, dispatch, commit } = store // Do not initialize unless nonexistent or closed if ( state.mastoUserSocket && @@ -50,11 +58,13 @@ const api = { ) { return } + commit('recoverConnection') return dispatch('startMastoUserSocket') }, disableMastoSockets (store) { - const { state, dispatch } = store + const { state, dispatch, commit } = store if (!state.mastoUserSocket) return + commit('recoverConnection') return dispatch('stopMastoUserSocket') }, @@ -102,6 +112,7 @@ const api = { state.mastoUserSocket.addEventListener('open', () => { // Do not show notification when we just opened up the page if (state.mastoUserSocketStatus !== null) { + commit('recoverConnection') dispatch('pushGlobalNotice', { level: 'success', messageKey: 'timeline.socket_reconnected', @@ -114,15 +125,6 @@ const api = { console.error('Error in MastoAPI websocket:', error) commit('setMastoUserSocketStatus', WSConnectionStatus.ERROR) dispatch('clearOpenedChats') - /* Since data in WS event for error is useless it's better to show - * generic warning instead of in "close" which actually has some - * useful data - */ - dispatch('pushGlobalNotice', { - level: 'error', - messageKey: 'timeline.socket_closed', - timeout: 5000 - }) }) state.mastoUserSocket.addEventListener('close', ({ detail: closeEvent }) => { const ignoreCodes = new Set([ @@ -137,13 +139,19 @@ const api = { dispatch('startFetchingTimeline', { timeline: 'friends' }) dispatch('startFetchingNotifications') dispatch('startFetchingChats') - dispatch('restartMastoUserSocket') - dispatch('pushGlobalNotice', { - level: 'error', - messageKey: 'timeline.socket_broke', - messageArgs: [code], - timeout: 5000 - }) + setTimeout(() => { + console.log('TEST') + dispatch('restartMastoUserSocket') + }, 1000) + if (!state.connectionBroken) { + dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'timeline.socket_broke', + messageArgs: [code], + timeout: 5000 + }) + } + commit('breakConnection') } commit('setMastoUserSocketStatus', WSConnectionStatus.CLOSED) dispatch('clearOpenedChats') diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -57,12 +57,14 @@ const fetchNotifications = ({ store, args, older }) => { return notifications }) .catch((error) => { - store.dispatch('pushGlobalNotice', { - level: 'error', - messageKey: 'notifications.error', - messageArgs: [error.message], - timeout: 5000 - }) + if (!store.rootState.api.connectionBroken) { + store.dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'notifications.error', + messageArgs: [error.message], + timeout: 5000 + }) + } }) } diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js @@ -66,12 +66,14 @@ const fetchAndUpdate = ({ return { statuses, pagination } }) .catch((error) => { - store.dispatch('pushGlobalNotice', { - level: 'error', - messageKey: 'timeline.error', - messageArgs: [error.message], - timeout: 5000 - }) + if (!store.rootState.api.connectionBroken) { + store.dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'timeline.error', + messageArgs: [error.message], + timeout: 5000 + }) + } }) }