aboutsummaryrefslogtreecommitdiff
path: root/src/services/follow_manipulate/follow_manipulate.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/follow_manipulate/follow_manipulate.js')
-rw-r--r--src/services/follow_manipulate/follow_manipulate.js49
1 files changed, 12 insertions, 37 deletions
diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js
index 1e9bd679..d82ce593 100644
--- a/src/services/follow_manipulate/follow_manipulate.js
+++ b/src/services/follow_manipulate/follow_manipulate.js
@@ -2,39 +2,26 @@ const fetchUser = (attempt, user, store) => new Promise((resolve, reject) => {
setTimeout(() => {
store.state.api.backendInteractor.fetchUser({ id: user.id })
.then((user) => store.commit('addNewUsers', [user]))
- .then(() => resolve([user.following, attempt]))
+ .then(() => resolve([user.following, user.requested, user.locked, attempt]))
.catch((e) => reject(e))
}, 500)
-}).then(([following, attempt]) => {
- if (!following && attempt <= 3) {
+}).then(([following, sent, locked, attempt]) => {
+ if (!following && !(locked && sent) && attempt <= 3) {
// If we BE reports that we still not following that user - retry,
// increment attempts by one
- return fetchUser(++attempt, user, store)
- } else {
- // If we run out of attempts, just return whatever status is.
- return following
+ fetchUser(++attempt, user, store)
}
})
export const requestFollow = (user, store) => new Promise((resolve, reject) => {
store.state.api.backendInteractor.followUser(user.id)
.then((updated) => {
- store.commit('addNewUsers', [updated])
+ store.commit('updateUserRelationship', [updated])
- // For locked users we just mark it that we sent the follow request
- if (updated.locked) {
- resolve({
- sent: true,
- updated
- })
- }
-
- if (updated.following) {
- // If we get result immediately, just stop.
- resolve({
- sent: false,
- updated
- })
+ if (updated.following || (user.locked && user.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
@@ -45,20 +32,8 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => {
// Recursive Promise, it will call itself up to 3 times.
return fetchUser(1, user, store)
- .then((following) => {
- if (following) {
- // We confirmed and everything's good.
- resolve({
- sent: false,
- updated
- })
- } else {
- // If after all the tries, just treat it as if user is locked
- resolve({
- sent: false,
- updated
- })
- }
+ .then(() => {
+ resolve()
})
})
})
@@ -66,7 +41,7 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => {
export const requestUnfollow = (user, store) => new Promise((resolve, reject) => {
store.state.api.backendInteractor.unfollowUser(user.id)
.then((updated) => {
- store.commit('addNewUsers', [updated])
+ store.commit('updateUserRelationship', [updated])
resolve({
updated
})