Page MenuHomePhorge

No OneTemporary

Size
8 KB
Referenced Files
None
Subscribers
None
diff --git a/src/modules/api.js b/src/modules/api.js
index 7ed3edacfb..96b0093b17 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -1,77 +1,80 @@
import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js'
import { Socket } from 'phoenix'
const api = {
state: {
backendInteractor: backendInteractorService(),
fetchers: {},
socket: null,
chatDisabled: false,
followRequests: []
},
mutations: {
setBackendInteractor (state, backendInteractor) {
state.backendInteractor = backendInteractor
},
addFetcher (state, { fetcherName, fetcher }) {
state.fetchers[fetcherName] = fetcher
},
removeFetcher (state, { fetcherName }) {
delete state.fetchers[fetcherName]
},
setWsToken (state, token) {
state.wsToken = token
},
setSocket (state, socket) {
state.socket = socket
},
setChatDisabled (state, value) {
state.chatDisabled = value
},
setFollowRequests (state, value) {
state.followRequests = value
}
},
actions: {
startFetchingTimeline (store, { timeline = 'friends', tag = false, userId = false }) {
// Don't start fetching if we already are.
if (store.state.fetchers[timeline]) return
const fetcher = store.state.backendInteractor.startFetchingTimeline({ timeline, store, userId, tag })
store.commit('addFetcher', { fetcherName: timeline, fetcher })
},
startFetchingNotifications (store) {
// Don't start fetching if we already are.
if (store.state.fetchers['notifications']) return
const fetcher = store.state.backendInteractor.startFetchingNotifications({ store })
store.commit('addFetcher', { fetcherName: 'notifications', fetcher })
},
stopFetching (store, fetcherName) {
const fetcher = store.state.fetchers[fetcherName]
- window.clearInterval(fetcher)
- store.commit('removeFetcher', { fetcherName })
+ if (fetcher) {
+ fetcher.stop()
+ store.commit('removeFetcher', { fetcherName })
+ }
+ // window.clearInterval(fetcher)
},
setWsToken (store, token) {
store.commit('setWsToken', token)
},
initializeSocket (store) {
// Set up websocket connection
if (!store.state.chatDisabled) {
const token = store.state.wsToken
const socket = new Socket('/socket', {params: {token}})
socket.connect()
store.dispatch('initializeChat', socket)
}
},
disableChat (store) {
store.commit('setChatDisabled', true)
},
removeFollowRequest (store, request) {
let requests = store.state.followRequests.filter((it) => it !== request)
store.commit('setFollowRequests', requests)
}
}
}
export default api
diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js
index 3ecdae6a78..d42c35a333 100644
--- a/src/services/notifications_fetcher/notifications_fetcher.service.js
+++ b/src/services/notifications_fetcher/notifications_fetcher.service.js
@@ -1,57 +1,77 @@
import apiService from '../api/api.service.js'
const update = ({store, notifications, older}) => {
store.dispatch('setNotificationsError', { value: false })
store.dispatch('addNewNotifications', { notifications, older })
}
const fetchAndUpdate = ({store, credentials, older = false}) => {
+ let stopFetcher = false
const args = { credentials }
const rootState = store.rootState || store.state
const timelineData = rootState.statuses.notifications
if (older) {
if (timelineData.minId !== Number.POSITIVE_INFINITY) {
args['until'] = timelineData.minId
}
} else {
// load unread notifications repeadedly to provide consistency between browser tabs
const notifications = timelineData.data
const unread = notifications.filter(n => !n.seen).map(n => n.id)
if (!unread.length) {
args['since'] = timelineData.maxId
} else {
args['since'] = Math.min(...unread) - 1
if (timelineData.maxId !== Math.max(...unread)) {
args['until'] = Math.max(...unread, args['since'] + 20)
}
}
}
args['timeline'] = 'notifications'
- return apiService.fetchTimeline(args)
+ apiService.fetchTimeline(args)
.then((notifications) => {
+ if (stopFetcher) { return false }
update({store, notifications, older})
return notifications
}, () => store.dispatch('setNotificationsError', { value: true }))
.catch(() => store.dispatch('setNotificationsError', { value: true }))
+
+ const stop = () => {
+ stopFetcher = true
+ }
+
+ return {
+ stop
+ }
}
const startFetching = ({credentials, store}) => {
- fetchAndUpdate({ credentials, store })
- const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
+ let fetchRequest = fetchAndUpdate({ credentials, store })
+ const boundFetchAndUpdate = () => {
+ fetchRequest.stop()
+ fetchRequest = fetchAndUpdate({ credentials, store })
+ }
// Initially there's set flag to silence all desktop notifications so
// that there won't spam of them when user just opened up the FE we
// reset that flag after a while to show new notifications once again.
setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
- return setInterval(boundFetchAndUpdate, 10000)
+ const fetcher = setInterval(boundFetchAndUpdate, 10000)
+ const stop = () => {
+ window.clearInterval(fetcher)
+ fetchRequest.stop()
+ }
+ return {
+ stop
+ }
}
const notificationsFetcher = {
fetchAndUpdate,
startFetching
}
export default notificationsFetcher
diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js
index 8e954cdf4e..48606d2b89 100644
--- a/src/services/timeline_fetcher/timeline_fetcher.service.js
+++ b/src/services/timeline_fetcher/timeline_fetcher.service.js
@@ -1,62 +1,82 @@
import { camelCase } from 'lodash'
import apiService from '../api/api.service.js'
const update = ({store, statuses, timeline, showImmediately, userId}) => {
const ccTimeline = camelCase(timeline)
store.dispatch('setError', { value: false })
store.dispatch('addNewStatuses', {
timeline: ccTimeline,
userId,
statuses,
showImmediately
})
}
const fetchAndUpdate = ({store, credentials, timeline = 'friends', older = false, showImmediately = false, userId = false, tag = false, until}) => {
+ let stopFetcher = false
const args = { timeline, credentials }
const rootState = store.rootState || store.state
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
const hideMutedPosts = typeof rootState.config.hideMutedPosts === 'undefined'
? rootState.instance.hideMutedPosts
: rootState.config.hideMutedPosts
if (older) {
args['until'] = until || timelineData.minId
} else {
args['since'] = timelineData.maxId
}
args['userId'] = userId
args['tag'] = tag
args['withMuted'] = !hideMutedPosts
const numStatusesBeforeFetch = timelineData.statuses.length
- return apiService.fetchTimeline(args)
+ apiService.fetchTimeline(args)
.then((statuses) => {
+ if (stopFetcher) { return false }
if (!older && statuses.length >= 20 && !timelineData.loading && numStatusesBeforeFetch > 0) {
store.dispatch('queueFlush', { timeline: timeline, id: timelineData.maxId })
}
update({store, statuses, timeline, showImmediately, userId})
return statuses
}, () => store.dispatch('setError', { value: true }))
+
+ const stop = () => {
+ stopFetcher = true
+ }
+
+ return {
+ stop
+ }
}
const startFetching = ({timeline = 'friends', credentials, store, userId = false, tag = false}) => {
const rootState = store.rootState || store.state
const timelineData = rootState.statuses.timelines[camelCase(timeline)]
const showImmediately = timelineData.visibleStatuses.length === 0
timelineData.userId = userId
- fetchAndUpdate({timeline, credentials, store, showImmediately, userId, tag})
- const boundFetchAndUpdate = () => fetchAndUpdate({ timeline, credentials, store, userId, tag })
- return setInterval(boundFetchAndUpdate, 10000)
+ let fetchRequest = fetchAndUpdate({timeline, credentials, store, showImmediately, userId, tag})
+ const boundFetchAndUpdate = () => {
+ fetchRequest.stop()
+ fetchRequest = fetchAndUpdate({ timeline, credentials, store, userId, tag })
+ }
+ const fetcher = setInterval(boundFetchAndUpdate, 10000)
+ const stop = () => {
+ window.clearInterval(fetcher)
+ fetchRequest.stop()
+ }
+ return {
+ stop
+ }
}
const timelineFetcher = {
fetchAndUpdate,
startFetching
}
export default timelineFetcher

File Metadata

Mime Type
text/x-diff
Expires
Sat, Aug 29, 1:57 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1737113
Default Alt Text
(8 KB)

Event Timeline