mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe
synced 2025-05-11 06:59: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('startFetchingTimeline', { timeline: 'friends' })
|
||||||
dispatch('startFetchingNotifications')
|
dispatch('startFetchingNotifications')
|
||||||
dispatch('startFetchingChats')
|
dispatch('startFetchingChats')
|
||||||
|
dispatch('startFetchingAnnouncements')
|
||||||
dispatch('pushGlobalNotice', {
|
dispatch('pushGlobalNotice', {
|
||||||
level: 'error',
|
level: 'error',
|
||||||
messageKey: 'timeline.socket_broke',
|
messageKey: 'timeline.socket_broke',
|
||||||
|
@ -261,6 +262,18 @@ const api = {
|
||||||
store.commit('removeFetcher', { fetcherName: 'lists', fetcher })
|
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
|
// Pleroma websocket
|
||||||
setWsToken (store, token) {
|
setWsToken (store, token) {
|
||||||
store.commit('setWsToken', 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 notificationsFetcher from '../notifications_fetcher/notifications_fetcher.service.js'
|
||||||
import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service'
|
import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service'
|
||||||
import listsFetcher from '../../services/lists_fetcher/lists_fetcher.service.js'
|
import listsFetcher from '../../services/lists_fetcher/lists_fetcher.service.js'
|
||||||
|
import announcementsFetcher from '../../services/announcements_fetcher/announcements_fetcher.service.js'
|
||||||
|
|
||||||
const backendInteractorService = credentials => ({
|
const backendInteractorService = credentials => ({
|
||||||
startFetchingTimeline ({ timeline, store, userId = false, listId = false, tag }) {
|
startFetchingTimeline ({ timeline, store, userId = false, listId = false, tag }) {
|
||||||
|
@ -29,6 +30,10 @@ const backendInteractorService = credentials => ({
|
||||||
return listsFetcher.startFetching({ store, credentials })
|
return listsFetcher.startFetching({ store, credentials })
|
||||||
},
|
},
|
||||||
|
|
||||||
|
startFetchingAnnouncements ({ store }) {
|
||||||
|
return announcementsFetcher.startFetching({ store, credentials })
|
||||||
|
},
|
||||||
|
|
||||||
startUserSocket ({ store }) {
|
startUserSocket ({ store }) {
|
||||||
const serv = store.rootState.instance.server.replace('http', 'ws')
|
const serv = store.rootState.instance.server.replace('http', 'ws')
|
||||||
const url = serv + getMastodonSocketURI({ credentials, stream: 'user' })
|
const url = serv + getMastodonSocketURI({ credentials, stream: 'user' })
|
||||||
|
|
Loading…
Reference in a new issue