Refetch reports every 60 seconds

This commit is contained in:
Sol Fisher Romanoff 2022-11-05 16:18:28 +02:00
parent 405a60d249
commit bdd970ca68
No known key found for this signature in database
GPG key ID: 9D3F2B64F2341B62
6 changed files with 40 additions and 7 deletions

View file

@ -396,6 +396,7 @@ const afterStoreSetup = async ({ store, i18n }) => {
// Start fetching things that don't need to block the UI
store.dispatch('fetchMutes')
store.dispatch('startFetchingAnnouncements')
store.dispatch('startFetchingReports')
getTOS({ store })
getStickers({ store })

View file

@ -9,9 +9,6 @@ const ReportsTab = {
showClosed: false
}
},
created () {
this.$store.dispatch('getReports')
},
components: {
Checkbox,
ReportCard

View file

@ -163,6 +163,7 @@ const api = {
dispatch('startFetchingTimeline', { timeline: 'friends' })
dispatch('startFetchingNotifications')
dispatch('startFetchingAnnouncements')
dispatch('startFetchingReports')
dispatch('pushGlobalNotice', {
level: 'error',
messageKey: 'timeline.socket_broke',
@ -280,6 +281,19 @@ const api = {
if (!fetcher) return
store.commit('removeFetcher', { fetcherName: 'announcements', fetcher })
},
// Reports
startFetchingReports (store) {
if (store.state.fetchers['reports']) return
const fetcher = store.state.backendInteractor.startFetchingReports({ store })
store.commit('addFetcher', { fetcherName: 'reports', fetcher })
},
stopFetchingReports (store) {
const fetcher = store.state.fetchers.reports
if (!fetcher) return
store.commit('removeFetcher', { fetcherName: 'reports', fetcher })
},
getSupportedTranslationlanguages (store) {
store.state.backendInteractor.getSupportedTranslationlanguages({ store })
.then((data) => {

View file

@ -70,10 +70,6 @@ const reports = {
closeUserReportingModal ({ commit }) {
commit('closeUserReportingModal')
},
getReports ({ rootState, commit }, params) {
return rootState.api.backendInteractor.getReports(params)
.then(reports => forEach(reports, report => commit('setReport', { report })))
},
updateReportStates ({ rootState, commit }, { reports }) {
commit('updateReportStates', { reports })
return rootState.api.backendInteractor.updateReportStates({ reports })

View file

@ -5,6 +5,7 @@ import followRequestFetcher from '../../services/follow_request_fetcher/follow_r
import listsFetcher from '../../services/lists_fetcher/lists_fetcher.service.js'
import announcementsFetcher from '../../services/announcements_fetcher/announcements_fetcher.service.js'
import configFetcher from '../config_fetcher/config_fetcher.service.js'
import reportsFetcher from '../reports_fetcher/reports_fetcher.service.js'
const backendInteractorService = credentials => ({
startFetchingTimeline ({ timeline, store, userId = false, listId = false, tag }) {
@ -39,6 +40,10 @@ const backendInteractorService = credentials => ({
return announcementsFetcher.startFetching({ store, credentials })
},
startFetchingReports ({ store, state, limit, page, pageSize }) {
return reportsFetcher.startFetching({ store, credentials, state, limit, page, pageSize })
},
startUserSocket ({ store }) {
const serv = store.rootState.instance.server.replace('http', 'ws')
const url = serv + getMastodonSocketURI({ credentials, stream: 'user' })

View file

@ -0,0 +1,20 @@
import apiService from '../api/api.service.js'
import { promiseInterval } from '../promise_interval/promise_interval.js'
import { forEach } from 'lodash'
const fetchAndUpdate = ({ store, credentials, state, limit, page, pageSize }) => {
return apiService.getReports({ credentials, state, limit, page, pageSize })
.then(reports => forEach(reports, report => store.commit('setReport', { report })))
}
const startFetching = ({ store, credentials, state, limit, page, pageSize }) => {
const boundFetchAndUpdate = () => fetchAndUpdate({ store, credentials, state, limit, page, pageSize })
boundFetchAndUpdate()
return promiseInterval(boundFetchAndUpdate, 60000)
}
const reportsFetcher = {
startFetching
}
export default reportsFetcher