remaining backend interactor removals
This commit is contained in:
parent
28efd7ebd2
commit
0d9709825f
45 changed files with 1118 additions and 856 deletions
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue