mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe
synced 2025-05-10 22:49:14 +08:00
poll for announcements
This commit is contained in:
parent
fd4eadf851
commit
ff5e35132a
3 changed files with 40 additions and 0 deletions
|
@ -163,6 +163,7 @@ const api = {
|
|||
dispatch('startFetchingTimeline', { timeline: 'friends' })
|
||||
dispatch('startFetchingNotifications')
|
||||
dispatch('startFetchingChats')
|
||||
dispatch('startFetchingAnnouncements')
|
||||
dispatch('pushGlobalNotice', {
|
||||
level: 'error',
|
||||
messageKey: 'timeline.socket_broke',
|
||||
|
@ -261,6 +262,18 @@ const api = {
|
|||
store.commit('removeFetcher', { fetcherName: 'lists', fetcher })
|
||||
},
|
||||
|
||||
// Lists
|
||||
startFetchingAnnouncements (store) {
|
||||
if (store.state.fetchers['announcements']) return
|
||||
const fetcher = store.state.backendInteractor.startFetchingAnnouncements({ store })
|
||||
store.commit('addFetcher', { fetcherName: 'announcements', fetcher })
|
||||
},
|
||||
stopFetchingAnnouncements (store) {
|
||||
const fetcher = store.state.fetchers.announcements
|
||||
if (!fetcher) return
|
||||
store.commit('removeFetcher', { fetcherName: 'announcements', fetcher })
|
||||
},
|
||||
|
||||
// Pleroma websocket
|
||||
setWsToken (store, token) {
|
||||
store.commit('setWsToken', token)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import apiService from '../api/api.service.js'
|
||||
import { promiseInterval } from '../promise_interval/promise_interval.js'
|
||||
|
||||
const fetchAndUpdate = ({ store, credentials }) => {
|
||||
return apiService.fetchAnnouncements({ credentials })
|
||||
.then(announcements => {
|
||||
store.commit('setAnnouncements', announcements)
|
||||
}, () => {})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
const startFetching = ({ credentials, store }) => {
|
||||
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
|
||||
boundFetchAndUpdate()
|
||||
return promiseInterval(boundFetchAndUpdate, 60000)
|
||||
}
|
||||
|
||||
const announcementsFetcher = {
|
||||
startFetching
|
||||
}
|
||||
|
||||
export default announcementsFetcher
|
|
@ -3,6 +3,7 @@ import timelineFetcher from '../timeline_fetcher/timeline_fetcher.service.js'
|
|||
import notificationsFetcher from '../notifications_fetcher/notifications_fetcher.service.js'
|
||||
import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service'
|
||||
import listsFetcher from '../../services/lists_fetcher/lists_fetcher.service.js'
|
||||
import announcementsFetcher from '../../services/announcements_fetcher/announcements_fetcher.service.js'
|
||||
|
||||
const backendInteractorService = credentials => ({
|
||||
startFetchingTimeline ({ timeline, store, userId = false, listId = false, tag }) {
|
||||
|
@ -29,6 +30,10 @@ const backendInteractorService = credentials => ({
|
|||
return listsFetcher.startFetching({ store, credentials })
|
||||
},
|
||||
|
||||
startFetchingAnnouncements ({ store }) {
|
||||
return announcementsFetcher.startFetching({ store, credentials })
|
||||
},
|
||||
|
||||
startUserSocket ({ store }) {
|
||||
const serv = store.rootState.instance.server.replace('http', 'ws')
|
||||
const url = serv + getMastodonSocketURI({ credentials, stream: 'user' })
|
||||
|
|
Loading…
Reference in a new issue