From 766bcc2a72bc9e6966c0ce174d1887ac6b8cc5c4 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 9 Aug 2019 14:18:46 +0300 Subject: [PATCH 1/4] 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. --- .../entity_normalizer.service.js | 1 + .../follow_manipulate/follow_manipulate.js | 30 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index c8474302..6cc1851d 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -65,6 +65,7 @@ export const parseUser = (data) => { if (relationship) { output.follows_you = relationship.followed_by + output.requested = relationship.requested output.following = relationship.following output.statusnet_blocking = relationship.blocking output.muted = relationship.muting diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index b2486e7c..3a953ab3 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -2,17 +2,17 @@ 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 && 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 + return sent } }) @@ -21,14 +21,10 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => { .then((updated) => { store.commit('updateUserRelationship', [updated]) - // For locked users we just mark it that we sent the follow request - if (updated.locked) { - resolve({ sent: true }) - } - - if (updated.following) { - // If we get result immediately, just stop. - resolve({ sent: false }) + if (updated.following || user.locked) { + // If we get result immediately or the account is locked, just stop. + resolve({ sent: updated.requested }) + return } // 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. return fetchUser(1, user, store) - .then((following) => { - if (following) { - // 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 }) - } + .then((sent) => { + resolve({ sent: sent }) }) }) }) From e83b321ff296dc7c3d8eba52a416ecc13a54e141 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 9 Aug 2019 12:01:57 +0000 Subject: [PATCH 2/4] Apply suggestion to src/services/follow_manipulate/follow_manipulate.js --- src/services/follow_manipulate/follow_manipulate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index 3a953ab3..bd8ae979 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -36,7 +36,7 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => { return fetchUser(1, user, store) .then((sent) => { - resolve({ sent: sent }) + resolve({ sent }) }) }) }) From 5f3ac6625fef52adbb1cda5e1bd03863ed128580 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 9 Aug 2019 12:25:58 +0000 Subject: [PATCH 3/4] Apply suggestion to src/services/follow_manipulate/follow_manipulate.js --- src/services/follow_manipulate/follow_manipulate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index bd8ae979..26733e26 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -21,7 +21,7 @@ export const requestFollow = (user, store) => new Promise((resolve, reject) => { .then((updated) => { store.commit('updateUserRelationship', [updated]) - if (updated.following || user.locked) { + if (updated.following || (user.locked && user.requested)) { // If we get result immediately or the account is locked, just stop. resolve({ sent: updated.requested }) return From 114b5f6effa3de813e047ee6b702a674e6ad07d5 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 9 Aug 2019 12:26:58 +0000 Subject: [PATCH 4/4] Apply suggestion to src/services/follow_manipulate/follow_manipulate.js --- src/services/follow_manipulate/follow_manipulate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index 26733e26..529fdb9b 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -6,7 +6,7 @@ const fetchUser = (attempt, user, store) => new Promise((resolve, reject) => { .catch((e) => reject(e)) }, 500) }).then(([following, sent, locked, attempt]) => { - if (!following && !locked && attempt <= 3) { + 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)