aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-11-24 22:01:12 +0200
committerHenry Jameson <me@hjkos.com>2019-11-24 22:01:12 +0200
commit172ebaf4e67358852bfaafd8f069763ca5e602b1 (patch)
tree0f7112dfb973809a201413dc24fcc4f855002295 /src/modules
parent319bb4ac2895b8eb62da42e3f95addc9bb67b1a0 (diff)
improved initial notifications fetching
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/api.js23
-rw-r--r--src/modules/users.js2
2 files changed, 21 insertions, 4 deletions
diff --git a/src/modules/api.js b/src/modules/api.js
index 1bf65db5..0e7e5e19 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -31,18 +31,32 @@ const api = {
},
actions: {
startMastoSocket (store) {
- store.state.mastoSocket = store.state.backendInteractor
+ const { state, dispatch } = store
+ state.mastoSocket = state.backendInteractor
.startUserSocket({
store,
onMessage: (message) => {
if (!message) return
if (message.event === 'notification') {
- store.dispatch('addNewNotifications', { notifications: [message.notification], older: false })
+ dispatch('addNewNotifications', {
+ notifications: [message.notification],
+ older: false
+ })
} else if (message.event === 'update') {
- store.dispatch('addNewStatuses', { statuses: [message.status], userId: false, showImmediately: false, timeline: 'friends' })
+ dispatch('addNewStatuses', {
+ statuses: [message.status],
+ userId: false,
+ showImmediately: false,
+ timeline: 'friends'
+ })
}
}
})
+ state.mastoSocket.addEventListener('error', error => {
+ console.error('Error with MastoAPI websocket:', error)
+ dispatch('startFetchingTimeline', { timeline: 'friends' })
+ dispatch('startFetchingNotifications')
+ })
},
startFetchingTimeline (store, { timeline = 'friends', tag = false, userId = false }) {
// Don't start fetching if we already are.
@@ -58,6 +72,9 @@ const api = {
const fetcher = store.state.backendInteractor.startFetchingNotifications({ store })
store.commit('addFetcher', { fetcherName: 'notifications', fetcher })
},
+ fetchAndUpdateNotifications (store) {
+ store.state.backendInteractor.fetchAndUpdateNotifications({ store })
+ },
startFetchingFollowRequest (store) {
// Don't start fetching if we already are.
if (store.state.fetchers['followRequest']) return
diff --git a/src/modules/users.js b/src/modules/users.js
index 861a2f4f..eff0c5d5 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -470,7 +470,7 @@ const users = {
}
store.dispatch('startMastoSocket').catch((error) => {
- console.error(error)
+ console.error('Failed initializing MastoAPI Streaming socket', error)
// Start getting fresh posts.
store.dispatch('startFetchingTimeline', { timeline: 'friends' })