From c062ae66e3eeb04909a584cbc13503392202e1e2 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 16 Jun 2026 22:32:17 +0300 Subject: [PATCH] fix follows --- src/services/api/api.service.js | 8 +-- .../follow_manipulate/follow_manipulate.js | 63 ++++++++----------- 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 1aeeaa603..692bf19fd 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -245,19 +245,19 @@ export const getCaptcha = () => }) export const followUser = ({ id, credentials, ...options }) => { - const form = {} + const payload = {} if (options.reblogs !== undefined) { - form.reblogs = options.reblogs + payload.reblogs = options.reblogs } if (options.notify !== undefined) { - form.notify = options.notify + payload.notify = options.notify } return promisedRequest({ url: MASTODON_FOLLOW_URL(id), - formData: form, + payload, credentials, method: 'POST', }) diff --git a/src/services/follow_manipulate/follow_manipulate.js b/src/services/follow_manipulate/follow_manipulate.js index c754c7316..1a3b2395c 100644 --- a/src/services/follow_manipulate/follow_manipulate.js +++ b/src/services/follow_manipulate/follow_manipulate.js @@ -35,42 +35,33 @@ const fetchRelationship = (attempt, userId, store) => } }) -export const requestFollow = (userId, store) => - new Promise((resolve) => { - followUser({ - id: userId, - credentials: useOAuthStore().token, - }).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 - } - - // 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() - }) - }) +export const requestFollow = async (userId, store) => { + const updated = await followUser({ + id: userId, + credentials: useOAuthStore().token, }) -export const requestUnfollow = (userId, store) => - new Promise((resolve) => { - unfollowUser({ - id: userId, - credentials: useOAuthStore().token, - }).then((updated) => { - store.commit('updateUserRelationship', [updated]) - resolve({ - updated, - }) - }) + store.commit('updateUserRelationship', [updated]) + + if (updated.following || (updated.locked && updated.requested)) { + // If we get result immediately or the account is locked, just stop. + 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. + return await fetchRelationship(1, updated, store) +} + +export const requestUnfollow = async (userId, store) => { + const updated = await unfollowUser({ + id: userId, + credentials: useOAuthStore().token, }) + + return await store.commit('updateUserRelationship', [updated]) +}