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

44 lines
1.5 KiB
JavaScript
Raw Normal View History

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