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 }) => {
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',
})

View file

@ -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])
}