logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

follow_manipulate.js (1941B)


  1. const fetchRelationship = (attempt, userId, store) => new Promise((resolve, reject) => {
  2. setTimeout(() => {
  3. store.state.api.backendInteractor.fetchUserRelationship({ id: userId })
  4. .then((relationship) => {
  5. store.commit('updateUserRelationship', [relationship])
  6. return relationship
  7. })
  8. .then((relationship) => resolve([relationship.following, relationship.requested, relationship.locked, attempt]))
  9. .catch((e) => reject(e))
  10. }, 500)
  11. }).then(([following, sent, locked, attempt]) => {
  12. if (!following && !(locked && sent) && attempt <= 3) {
  13. // If we BE reports that we still not following that user - retry,
  14. // increment attempts by one
  15. fetchRelationship(++attempt, userId, store)
  16. }
  17. })
  18. export const requestFollow = (userId, store) => new Promise((resolve, reject) => {
  19. store.state.api.backendInteractor.followUser({ id: userId })
  20. .then((updated) => {
  21. store.commit('updateUserRelationship', [updated])
  22. if (updated.following || (updated.locked && updated.requested)) {
  23. // If we get result immediately or the account is locked, just stop.
  24. resolve()
  25. return
  26. }
  27. // But usually we don't get result immediately, so we ask server
  28. // for updated user profile to confirm if we are following them
  29. // Sometimes it takes several tries. Sometimes we end up not following
  30. // user anyway, probably because they locked themselves and we
  31. // don't know that yet.
  32. // Recursive Promise, it will call itself up to 3 times.
  33. return fetchRelationship(1, updated, store)
  34. .then(() => {
  35. resolve()
  36. })
  37. })
  38. })
  39. export const requestUnfollow = (userId, store) => new Promise((resolve, reject) => {
  40. store.state.api.backendInteractor.unfollowUser({ id: userId })
  41. .then((updated) => {
  42. store.commit('updateUserRelationship', [updated])
  43. resolve({
  44. updated
  45. })
  46. })
  47. })