remaining backend interactor removals
This commit is contained in:
parent
28efd7ebd2
commit
0d9709825f
45 changed files with 1118 additions and 856 deletions
|
|
@ -126,6 +126,10 @@ const PLEROMA_USER_FAVORITES_TIMELINE_URL = (id) =>
|
|||
const PLEROMA_BOOKMARK_FOLDERS_URL = '/api/v1/pleroma/bookmark_folders'
|
||||
const PLEROMA_BOOKMARK_FOLDER_URL = (id) =>
|
||||
`/api/v1/pleroma/bookmark_folders/${id}`
|
||||
|
||||
const EMOJI_PACKS_URL = (page, pageSize) =>
|
||||
`/api/v1/pleroma/emoji/packs?page=${page}&page_size=${pageSize}`
|
||||
|
||||
export const updateNotificationSettings = ({ credentials, settings }) => {
|
||||
const form = new FormData()
|
||||
|
||||
|
|
@ -682,6 +686,11 @@ export const fetchTimeline = ({
|
|||
})
|
||||
}
|
||||
|
||||
export const listEmojiPacks = ({ page, pageSize, credentials }) =>
|
||||
promisedRequest({
|
||||
url: EMOJI_PACKS_URL(page, pageSize),
|
||||
})
|
||||
|
||||
export const fetchPinnedStatuses = ({ id, credentials }) =>
|
||||
promisedRequest({
|
||||
url: MASTODON_USER_TIMELINE_URL(id) + '?pinned=true',
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
import bookmarkFoldersFetcher from '../../services/bookmark_folders_fetcher/bookmark_folders_fetcher.service.js'
|
||||
import followRequestFetcher from '../../services/follow_request_fetcher/follow_request_fetcher.service'
|
||||
import listsFetcher from '../../services/lists_fetcher/lists_fetcher.service.js'
|
||||
import * as apiService from '../api/api.service.js'
|
||||
import notificationsFetcher from '../notifications_fetcher/notifications_fetcher.service.js'
|
||||
import timelineFetcher from '../timeline_fetcher/timeline_fetcher.service.js'
|
||||
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
|
||||
const backendInteractorService = (credentials) => ({
|
||||
startFetchingTimeline({
|
||||
timeline,
|
||||
store,
|
||||
userId = false,
|
||||
listId = false,
|
||||
statusId = false,
|
||||
bookmarkFolderId = false,
|
||||
tag,
|
||||
}) {
|
||||
return timelineFetcher.startFetching({
|
||||
timeline,
|
||||
store,
|
||||
credentials,
|
||||
userId,
|
||||
listId,
|
||||
statusId,
|
||||
bookmarkFolderId,
|
||||
tag,
|
||||
})
|
||||
},
|
||||
|
||||
fetchTimeline(args) {
|
||||
return timelineFetcher.fetchAndUpdate({ ...args, credentials })
|
||||
},
|
||||
|
||||
startFetchingNotifications({ store }) {
|
||||
return notificationsFetcher.startFetching({ store, credentials })
|
||||
},
|
||||
|
||||
fetchNotifications(args) {
|
||||
return notificationsFetcher.fetchAndUpdate({ ...args, credentials })
|
||||
},
|
||||
|
||||
startFetchingFollowRequests({ store }) {
|
||||
return followRequestFetcher.startFetching({ store, credentials })
|
||||
},
|
||||
|
||||
startFetchingLists({ store }) {
|
||||
return listsFetcher.startFetching({ store, credentials })
|
||||
},
|
||||
|
||||
startFetchingBookmarkFolders({ store }) {
|
||||
return bookmarkFoldersFetcher.startFetching({ store, credentials })
|
||||
},
|
||||
|
||||
startUserSocket({ store }) {
|
||||
const serv = useInstanceStore().server.replace('http', 'ws')
|
||||
const url = apiService.getMastodonSocketURI({}, serv)
|
||||
return apiService.ProcessedWS({ url, id: 'Unified', credentials })
|
||||
},
|
||||
|
||||
...Object.entries(apiService).reduce((acc, [key, func]) => {
|
||||
return {
|
||||
...acc,
|
||||
[key]: (args) => func({ credentials, ...args }),
|
||||
}
|
||||
}, {}),
|
||||
|
||||
verifyCredentials: apiService.verifyCredentials,
|
||||
})
|
||||
|
||||
export default backendInteractorService
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import { fetchBookmarkFolders } from '../api/api.service.js'
|
||||
import { promiseInterval } from '../promise_interval/promise_interval.js'
|
||||
|
||||
import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders.js'
|
||||
|
||||
const fetchAndUpdate = ({ credentials }) => {
|
||||
return fetchBookmarkFolders({ credentials })
|
||||
.then(
|
||||
(bookmarkFolders) => {
|
||||
useBookmarkFoldersStore().setBookmarkFolders(bookmarkFolders)
|
||||
},
|
||||
(rej) => {
|
||||
console.error(rej)
|
||||
},
|
||||
)
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
})
|
||||
}
|
||||
|
||||
const startFetching = ({ credentials, store }) => {
|
||||
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
|
||||
boundFetchAndUpdate()
|
||||
return promiseInterval(boundFetchAndUpdate, 240000)
|
||||
}
|
||||
|
||||
const bookmarkFoldersFetcher = {
|
||||
startFetching,
|
||||
}
|
||||
|
||||
export default bookmarkFoldersFetcher
|
||||
|
|
@ -1,8 +1,18 @@
|
|||
import { useCredentialsStore } from 'src/stores/credentials.js'
|
||||
|
||||
import {
|
||||
fetchUserRelationship,
|
||||
followUser,
|
||||
unfollowUser,
|
||||
} from 'src/services/api/api.service.js'
|
||||
|
||||
const fetchRelationship = (attempt, userId, store) =>
|
||||
new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
store.state.api.backendInteractor
|
||||
.fetchUserRelationship({ id: userId })
|
||||
fetchUserRelationship({
|
||||
id: userId,
|
||||
credentials: useCredentialsStore().current,
|
||||
})
|
||||
.then((relationship) => {
|
||||
store.commit('updateUserRelationship', [relationship])
|
||||
return relationship
|
||||
|
|
@ -27,38 +37,40 @@ const fetchRelationship = (attempt, userId, store) =>
|
|||
|
||||
export const requestFollow = (userId, store) =>
|
||||
new Promise((resolve) => {
|
||||
store.state.api.backendInteractor
|
||||
.followUser({ id: userId })
|
||||
.then((updated) => {
|
||||
store.commit('updateUserRelationship', [updated])
|
||||
followUser({
|
||||
id: userId,
|
||||
credentials: useCredentialsStore().current,
|
||||
}).then((updated) => {
|
||||
store.commit('updateUserRelationship', [updated])
|
||||
|
||||
if (updated.following || (updated.locked && updated.requested)) {
|
||||
// If we get result immediately or the account is locked, just stop.
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
if (updated.following || (updated.locked && updated.requested)) {
|
||||
// If we get result immediately or the account is locked, just stop.
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
|
||||
// But usually we don't get result immediately, so we ask server
|
||||
// for updated user profile to confirm if we are following them
|
||||
// Sometimes it takes several tries. Sometimes we end up not following
|
||||
// user anyway, probably because they locked themselves and we
|
||||
// don't know that yet.
|
||||
// Recursive Promise, it will call itself up to 3 times.
|
||||
// But usually we don't get result immediately, so we ask server
|
||||
// for updated user profile to confirm if we are following them
|
||||
// Sometimes it takes several tries. Sometimes we end up not following
|
||||
// user anyway, probably because they locked themselves and we
|
||||
// don't know that yet.
|
||||
// Recursive Promise, it will call itself up to 3 times.
|
||||
|
||||
return fetchRelationship(1, updated, store).then(() => {
|
||||
resolve()
|
||||
})
|
||||
return fetchRelationship(1, updated, store).then(() => {
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export const requestUnfollow = (userId, store) =>
|
||||
new Promise((resolve) => {
|
||||
store.state.api.backendInteractor
|
||||
.unfollowUser({ id: userId })
|
||||
.then((updated) => {
|
||||
store.commit('updateUserRelationship', [updated])
|
||||
resolve({
|
||||
updated,
|
||||
})
|
||||
unfollowUser({
|
||||
id: userId,
|
||||
credentials: useCredentialsStore().current,
|
||||
}).then((updated) => {
|
||||
store.commit('updateUserRelationship', [updated])
|
||||
resolve({
|
||||
updated,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
import { fetchLists } from '../api/api.service.js'
|
||||
import { promiseInterval } from '../promise_interval/promise_interval.js'
|
||||
|
||||
import { useListsStore } from 'src/stores/lists.js'
|
||||
|
||||
const fetchAndUpdate = ({ credentials }) => {
|
||||
return fetchLists({ credentials })
|
||||
.then(
|
||||
(lists) => {
|
||||
useListsStore().setLists(lists)
|
||||
},
|
||||
(rej) => {
|
||||
console.error(rej)
|
||||
},
|
||||
)
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
})
|
||||
}
|
||||
|
||||
const startFetching = ({ credentials, store }) => {
|
||||
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
|
||||
boundFetchAndUpdate()
|
||||
return promiseInterval(boundFetchAndUpdate, 240000)
|
||||
}
|
||||
|
||||
const listsFetcher = {
|
||||
startFetching,
|
||||
}
|
||||
|
||||
export default listsFetcher
|
||||
Loading…
Add table
Add a link
Reference in a new issue