2019-12-08 18:18:38 +01:00
|
|
|
import apiService, { getMastodonSocketURI, ProcessedWS } from '../api/api.service.js'
|
2021-01-13 21:17:10 +01:00
|
|
|
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'
|
2019-11-19 15:07:15 +01:00
|
|
|
import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service'
|
2016-11-26 18:57:08 +01:00
|
|
|
|
2019-11-24 12:57:46 +01:00
|
|
|
const backendInteractorService = credentials => ({
|
|
|
|
startFetchingTimeline ({ timeline, store, userId = false, tag }) {
|
2021-01-13 21:17:10 +01:00
|
|
|
return timelineFetcher.startFetching({ timeline, store, credentials, userId, tag })
|
|
|
|
},
|
|
|
|
|
|
|
|
fetchTimeline (args) {
|
|
|
|
return timelineFetcher.fetchAndUpdate({ ...args, credentials })
|
2019-11-24 12:57:46 +01:00
|
|
|
},
|
2019-04-04 18:03:56 +02:00
|
|
|
|
2019-11-24 12:57:46 +01:00
|
|
|
startFetchingNotifications ({ store }) {
|
2019-04-04 18:03:56 +02:00
|
|
|
return notificationsFetcher.startFetching({ store, credentials })
|
2019-11-24 12:57:46 +01:00
|
|
|
},
|
2017-02-16 11:17:47 +01:00
|
|
|
|
2021-01-13 21:17:10 +01:00
|
|
|
fetchNotifications (args) {
|
|
|
|
return notificationsFetcher.fetchAndUpdate({ ...args, credentials })
|
|
|
|
},
|
|
|
|
|
2020-01-21 16:51:49 +01:00
|
|
|
startFetchingFollowRequests ({ store }) {
|
2019-11-19 15:07:15 +01:00
|
|
|
return followRequestFetcher.startFetching({ store, credentials })
|
2019-11-24 12:57:46 +01:00
|
|
|
},
|
2019-05-08 05:36:35 +02:00
|
|
|
|
2019-12-08 18:18:38 +01:00
|
|
|
startUserSocket ({ store }) {
|
2019-11-24 21:01:12 +01:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2019-11-24 12:57:46 +01:00
|
|
|
...Object.entries(apiService).reduce((acc, [key, func]) => {
|
|
|
|
return {
|
|
|
|
...acc,
|
|
|
|
[key]: (args) => func({ credentials, ...args })
|
|
|
|
}
|
|
|
|
}, {}),
|
2016-11-26 18:57:08 +01:00
|
|
|
|
2019-11-24 12:57:46 +01:00
|
|
|
verifyCredentials: apiService.verifyCredentials
|
|
|
|
})
|
2016-11-26 18:57:08 +01:00
|
|
|
|
|
|
|
export default backendInteractorService
|