fix follows

This commit is contained in:
Henry Jameson 2026-06-16 22:32:17 +03:00
commit c062ae66e3
2 changed files with 31 additions and 40 deletions

View file

@ -245,19 +245,19 @@ export const getCaptcha = () =>
}) })
export const followUser = ({ id, credentials, ...options }) => { export const followUser = ({ id, credentials, ...options }) => {
const form = {} const payload = {}
if (options.reblogs !== undefined) { if (options.reblogs !== undefined) {
form.reblogs = options.reblogs payload.reblogs = options.reblogs
} }
if (options.notify !== undefined) { if (options.notify !== undefined) {
form.notify = options.notify payload.notify = options.notify
} }
return promisedRequest({ return promisedRequest({
url: MASTODON_FOLLOW_URL(id), url: MASTODON_FOLLOW_URL(id),
formData: form, payload,
credentials, credentials,
method: 'POST', method: 'POST',
}) })

View file

@ -35,42 +35,33 @@ const fetchRelationship = (attempt, userId, store) =>
} }
}) })
export const requestFollow = (userId, store) => export const requestFollow = async (userId, store) => {
new Promise((resolve) => { const updated = await followUser({
followUser({ id: userId,
id: userId, credentials: useOAuthStore().token,
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 requestUnfollow = (userId, store) => store.commit('updateUserRelationship', [updated])
new Promise((resolve) => {
unfollowUser({ if (updated.following || (updated.locked && updated.requested)) {
id: userId, // If we get result immediately or the account is locked, just stop.
credentials: useOAuthStore().token, return
}).then((updated) => { }
store.commit('updateUserRelationship', [updated])
resolve({ // But usually we don't get result immediately, so we ask server
updated, // 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])
}