Fix sent follow request detection

This fixes `requestFollow` using the relationship instead of user object,
resulting in `sent` always being false for locked users, and also removes
assumptions about follow request being sent, instead relying on
`requested` from user relationship.
This commit is contained in:
rinpatch 2019-08-09 14:18:46 +03:00
parent a45f258a2c
commit 766bcc2a72
2 changed files with 11 additions and 20 deletions

View file

@ -65,6 +65,7 @@ export const parseUser = (data) => {
if (relationship) { if (relationship) {
output.follows_you = relationship.followed_by output.follows_you = relationship.followed_by
output.requested = relationship.requested
output.following = relationship.following output.following = relationship.following
output.statusnet_blocking = relationship.blocking output.statusnet_blocking = relationship.blocking
output.muted = relationship.muting output.muted = relationship.muting

View file

@ -2,17 +2,17 @@ const fetchUser = (attempt, user, store) => new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
store.state.api.backendInteractor.fetchUser({ id: user.id }) store.state.api.backendInteractor.fetchUser({ id: user.id })
.then((user) => store.commit('addNewUsers', [user])) .then((user) => store.commit('addNewUsers', [user]))
.then(() => resolve([user.following, attempt])) .then(() => resolve([user.following, user.requested, user.locked, attempt]))
.catch((e) => reject(e)) .catch((e) => reject(e))
}, 500) }, 500)
}).then(([following, attempt]) => { }).then(([following, sent, locked, attempt]) => {
if (!following && attempt <= 3) { if (!following && !locked && attempt <= 3) {
// If we BE reports that we still not following that user - retry, // If we BE reports that we still not following that user - retry,
// increment attempts by one // increment attempts by one
return fetchUser(++attempt, user, store) return fetchUser(++attempt, user, store)
} else { } else {
// If we run out of attempts, just return whatever status is. // If we run out of attempts, just return whatever status is.
return following return sent
} }
}) })
@ -21,14 +21,10 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => {
.then((updated) => { .then((updated) => {
store.commit('updateUserRelationship', [updated]) store.commit('updateUserRelationship', [updated])
// For locked users we just mark it that we sent the follow request if (updated.following || user.locked) {
if (updated.locked) { // If we get result immediately or the account is locked, just stop.
resolve({ sent: true }) resolve({ sent: updated.requested })
} return
if (updated.following) {
// If we get result immediately, just stop.
resolve({ sent: false })
} }
// But usually we don't get result immediately, so we ask server // But usually we don't get result immediately, so we ask server
@ -39,14 +35,8 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => {
// Recursive Promise, it will call itself up to 3 times. // Recursive Promise, it will call itself up to 3 times.
return fetchUser(1, user, store) return fetchUser(1, user, store)
.then((following) => { .then((sent) => {
if (following) { resolve({ sent: sent })
// We confirmed and everything's good.
resolve({ sent: false })
} else {
// If after all the tries, just treat it as if user is locked
resolve({ sent: false })
}
}) })
}) })
}) })