diff options
| author | Henry Jameson <spam@hjkos.com> | 2021-01-13 21:31:57 +0200 |
|---|---|---|
| committer | Henry Jameson <spam@hjkos.com> | 2021-01-13 21:32:25 +0200 |
| commit | 64fa662644dd385dd746f2b309eef6287f5eae04 (patch) | |
| tree | bf5a90350159205d9d810e4164032724c491942e /src/modules/api.js | |
| parent | adc3b17fe0ba149386d83ee85f908578609bd676 (diff) | |
added notices for ws events
Diffstat (limited to 'src/modules/api.js')
| -rw-r--r-- | src/modules/api.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/modules/api.js b/src/modules/api.js index 08485a30..01c65e49 100644 --- a/src/modules/api.js +++ b/src/modules/api.js @@ -91,12 +91,29 @@ const api = { } ) state.mastoUserSocket.addEventListener('open', () => { + // Do not show notification when we just opened up the page + if (state.mastoUserSocketStatus !== null) { + dispatch('pushGlobalNotice', { + level: 'success', + messageKey: 'timeline.socket_reconnected', + timeout: 5000 + }) + } commit('setMastoUserSocketStatus', WSConnectionStatus.JOINED) }) state.mastoUserSocket.addEventListener('error', ({ detail: error }) => { 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([ @@ -112,6 +129,12 @@ const api = { dispatch('startFetchingNotifications') dispatch('startFetchingChats') dispatch('restartMastoUserSocket') + dispatch('pushGlobalNotice', { + level: 'error', + messageKey: 'timeline.socket_broke', + messageArgs: [code], + timeout: 5000 + }) } commit('setMastoUserSocketStatus', WSConnectionStatus.CLOSED) dispatch('clearOpenedChats') |
