forked from AkkomaGang/akkoma-fe
Fetch list of lists from the API
This commit is contained in:
parent
d5d464a289
commit
e18e179a59
4 changed files with 52 additions and 1 deletions
|
@ -13,7 +13,8 @@ const api = {
|
||||||
socket: null,
|
socket: null,
|
||||||
mastoUserSocket: null,
|
mastoUserSocket: null,
|
||||||
mastoUserSocketStatus: null,
|
mastoUserSocketStatus: null,
|
||||||
followRequests: []
|
followRequests: [],
|
||||||
|
lists: []
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setBackendInteractor (state, backendInteractor) {
|
setBackendInteractor (state, backendInteractor) {
|
||||||
|
@ -35,6 +36,9 @@ const api = {
|
||||||
setFollowRequests (state, value) {
|
setFollowRequests (state, value) {
|
||||||
state.followRequests = value
|
state.followRequests = value
|
||||||
},
|
},
|
||||||
|
setLists (state, value) {
|
||||||
|
state.lists = value
|
||||||
|
},
|
||||||
setMastoUserSocketStatus (state, value) {
|
setMastoUserSocketStatus (state, value) {
|
||||||
state.mastoUserSocketStatus = value
|
state.mastoUserSocketStatus = value
|
||||||
},
|
},
|
||||||
|
@ -249,6 +253,18 @@ const api = {
|
||||||
store.commit('setFollowRequests', requests)
|
store.commit('setFollowRequests', requests)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Lists
|
||||||
|
startFetchingLists (store) {
|
||||||
|
if (store.state.fetchers['lists']) return
|
||||||
|
const fetcher = store.state.backendInteractor.startFetchingLists({ store })
|
||||||
|
store.commit('addFetcher', { fetcherName: 'lists', fetcher })
|
||||||
|
},
|
||||||
|
stopFetchingLists (store) {
|
||||||
|
const fetcher = store.state.fetchers.lists
|
||||||
|
if (!fetcher) return
|
||||||
|
store.commit('removeFetcher', { fetcherName: 'lists', fetcher })
|
||||||
|
},
|
||||||
|
|
||||||
// Pleroma websocket
|
// Pleroma websocket
|
||||||
setWsToken (store, token) {
|
setWsToken (store, token) {
|
||||||
store.commit('setWsToken', token)
|
store.commit('setWsToken', token)
|
||||||
|
|
|
@ -79,6 +79,7 @@ const MASTODON_SEARCH_2 = `/api/v2/search`
|
||||||
const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search'
|
const MASTODON_USER_SEARCH_URL = '/api/v1/accounts/search'
|
||||||
const MASTODON_MASCOT_URL = '/api/v1/pleroma/mascot'
|
const MASTODON_MASCOT_URL = '/api/v1/pleroma/mascot'
|
||||||
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
|
const MASTODON_DOMAIN_BLOCKS_URL = '/api/v1/domain_blocks'
|
||||||
|
const MASTODON_LISTS_URL = '/api/v1/lists'
|
||||||
const MASTODON_STREAMING = '/api/v1/streaming'
|
const MASTODON_STREAMING = '/api/v1/streaming'
|
||||||
const MASTODON_KNOWN_DOMAIN_LIST_URL = '/api/v1/instance/peers'
|
const MASTODON_KNOWN_DOMAIN_LIST_URL = '/api/v1/instance/peers'
|
||||||
const PLEROMA_EMOJI_REACTIONS_URL = id => `/api/v1/pleroma/statuses/${id}/reactions`
|
const PLEROMA_EMOJI_REACTIONS_URL = id => `/api/v1/pleroma/statuses/${id}/reactions`
|
||||||
|
@ -383,6 +384,12 @@ const fetchFollowRequests = ({ credentials }) => {
|
||||||
.then((data) => data.map(parseUser))
|
.then((data) => data.map(parseUser))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fetchLists = ({ credentials }) => {
|
||||||
|
const url = MASTODON_LISTS_URL
|
||||||
|
return fetch(url, { headers: authHeaders(credentials) })
|
||||||
|
.then((data) => data.json())
|
||||||
|
}
|
||||||
|
|
||||||
const fetchConversation = ({ id, credentials }) => {
|
const fetchConversation = ({ id, credentials }) => {
|
||||||
let urlContext = MASTODON_STATUS_CONTEXT_URL(id)
|
let urlContext = MASTODON_STATUS_CONTEXT_URL(id)
|
||||||
return fetch(urlContext, { headers: authHeaders(credentials) })
|
return fetch(urlContext, { headers: authHeaders(credentials) })
|
||||||
|
@ -1355,6 +1362,7 @@ const apiService = {
|
||||||
mfaSetupOTP,
|
mfaSetupOTP,
|
||||||
mfaConfirmOTP,
|
mfaConfirmOTP,
|
||||||
fetchFollowRequests,
|
fetchFollowRequests,
|
||||||
|
fetchLists,
|
||||||
approveUser,
|
approveUser,
|
||||||
denyUser,
|
denyUser,
|
||||||
suggestions,
|
suggestions,
|
||||||
|
|
|
@ -2,6 +2,7 @@ import apiService, { getMastodonSocketURI, ProcessedWS } from '../api/api.servic
|
||||||
import timelineFetcher from '../timeline_fetcher/timeline_fetcher.service.js'
|
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'
|
||||||
|
|
||||||
const backendInteractorService = credentials => ({
|
const backendInteractorService = credentials => ({
|
||||||
startFetchingTimeline ({ timeline, store, userId = false, listId = false, tag }) {
|
startFetchingTimeline ({ timeline, store, userId = false, listId = false, tag }) {
|
||||||
|
@ -24,6 +25,10 @@ const backendInteractorService = credentials => ({
|
||||||
return followRequestFetcher.startFetching({ store, credentials })
|
return followRequestFetcher.startFetching({ store, credentials })
|
||||||
},
|
},
|
||||||
|
|
||||||
|
startFetchingLists ({ store }) {
|
||||||
|
return listsFetcher.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' })
|
||||||
|
|
22
src/services/lists_fetcher/lists_fetcher.service.js
Normal file
22
src/services/lists_fetcher/lists_fetcher.service.js
Normal file
|
@ -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.fetchLists({ credentials })
|
||||||
|
.then(lists => {
|
||||||
|
store.commit('setLists', lists)
|
||||||
|
}, () => {})
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
const startFetching = ({ credentials, store }) => {
|
||||||
|
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
|
||||||
|
boundFetchAndUpdate()
|
||||||
|
return promiseInterval(boundFetchAndUpdate, 240000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const listsFetcher = {
|
||||||
|
startFetching
|
||||||
|
}
|
||||||
|
|
||||||
|
export default listsFetcher
|
Loading…
Reference in a new issue