logo

pleroma-fe

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

who_to_follow_panel.js (1990B)


  1. import apiService from '../../services/api/api.service.js'
  2. import generateProfileLink from 'src/services/user_profile_link_generator/user_profile_link_generator'
  3. import { shuffle } from 'lodash'
  4. function showWhoToFollow (panel, reply) {
  5. const shuffled = shuffle(reply)
  6. panel.usersToFollow.forEach((toFollow, index) => {
  7. const user = shuffled[index]
  8. const img = user.avatar || this.$store.state.instance.defaultAvatar
  9. const name = user.acct
  10. toFollow.img = img
  11. toFollow.name = name
  12. panel.$store.state.api.backendInteractor.fetchUser({ id: name })
  13. .then((externalUser) => {
  14. if (!externalUser.error) {
  15. panel.$store.commit('addNewUsers', [externalUser])
  16. toFollow.id = externalUser.id
  17. }
  18. })
  19. })
  20. }
  21. function getWhoToFollow (panel) {
  22. const credentials = panel.$store.state.users.currentUser.credentials
  23. if (credentials) {
  24. panel.usersToFollow.forEach(toFollow => {
  25. toFollow.name = 'Loading...'
  26. })
  27. apiService.suggestions({ credentials })
  28. .then((reply) => {
  29. showWhoToFollow(panel, reply)
  30. })
  31. }
  32. }
  33. const WhoToFollowPanel = {
  34. data: () => ({
  35. usersToFollow: []
  36. }),
  37. computed: {
  38. user: function () {
  39. return this.$store.state.users.currentUser.screen_name
  40. },
  41. suggestionsEnabled () {
  42. return this.$store.state.instance.suggestionsEnabled
  43. }
  44. },
  45. methods: {
  46. userProfileLink (id, name) {
  47. return generateProfileLink(id, name, this.$store.state.instance.restrictedNicknames)
  48. }
  49. },
  50. watch: {
  51. user: function (user, oldUser) {
  52. if (this.suggestionsEnabled) {
  53. getWhoToFollow(this)
  54. }
  55. }
  56. },
  57. mounted:
  58. function () {
  59. this.usersToFollow = new Array(3).fill().map(x => (
  60. {
  61. img: this.$store.state.instance.defaultAvatar,
  62. name: '',
  63. id: 0
  64. }
  65. ))
  66. if (this.suggestionsEnabled) {
  67. getWhoToFollow(this)
  68. }
  69. }
  70. }
  71. export default WhoToFollowPanel