pleroma-fe/src/services/backend_interactor_service/backend_interactor_service.js

44 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-12-08 18:18:38 +01:00
import apiService, { getMastodonSocketURI, ProcessedWS } from '../api/api.service.js'
import timelineFetcher from '../timeline_fetcher/timeline_fetcher.service.js'
2019-04-03 18:04:46 +02:00
import notificationsFetcher from '../notifications_fetcher/notifications_fetcher.service.js'
import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service'
const backendInteractorService = credentials => ({
startFetchingTimeline ({ timeline, store, userId = false, tag }) {
return timelineFetcher.startFetching({ timeline, store, credentials, userId, tag })
},
fetchTimeline (args) {
return timelineFetcher.fetchAndUpdate({ ...args, credentials })
},
2019-04-04 18:03:56 +02:00
startFetchingNotifications ({ store }) {
2019-04-04 18:03:56 +02:00
return notificationsFetcher.startFetching({ store, credentials })
},
fetchNotifications (args) {
return notificationsFetcher.fetchAndUpdate({ ...args, credentials })
},
2020-01-21 16:51:49 +01:00
startFetchingFollowRequests ({ store }) {
return followRequestFetcher.startFetching({ store, credentials })
},
2019-05-08 05:36:35 +02:00
2019-12-08 18:18:38 +01:00
startUserSocket ({ store }) {
const serv = store.rootState.instance.server.replace('http', 'ws')
2019-11-24 17:50:28 +01:00
const url = serv + getMastodonSocketURI({ credentials, stream: 'user' })
2019-12-08 18:18:38 +01:00
return ProcessedWS({ url, id: 'User' })
2019-11-24 17:50:28 +01:00
},
...Object.entries(apiService).reduce((acc, [key, func]) => {
return {
...acc,
[key]: (args) => func({ credentials, ...args })
}
}, {}),
verifyCredentials: apiService.verifyCredentials
})
export default backendInteractorService