logo

pleroma-fe

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

mutes_and_blocks_tab.js (4382B)


  1. import get from 'lodash/get'
  2. import map from 'lodash/map'
  3. import reject from 'lodash/reject'
  4. import Autosuggest from 'src/components/autosuggest/autosuggest.vue'
  5. import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx'
  6. import BlockCard from 'src/components/block_card/block_card.vue'
  7. import MuteCard from 'src/components/mute_card/mute_card.vue'
  8. import DomainMuteCard from 'src/components/domain_mute_card/domain_mute_card.vue'
  9. import SelectableList from 'src/components/selectable_list/selectable_list.vue'
  10. import ProgressButton from 'src/components/progress_button/progress_button.vue'
  11. import withSubscription from 'src/components/../hocs/with_subscription/with_subscription'
  12. import withLoadMore from 'src/components/../hocs/with_load_more/with_load_more'
  13. import Checkbox from 'src/components/checkbox/checkbox.vue'
  14. const BlockList = withLoadMore({
  15. fetch: (props, $store) => $store.dispatch('fetchBlocks'),
  16. select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []),
  17. destroy: () => {},
  18. childPropName: 'items'
  19. })(SelectableList)
  20. const MuteList = withLoadMore({
  21. fetch: (props, $store) => $store.dispatch('fetchMutes'),
  22. select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []),
  23. destroy: () => {},
  24. childPropName: 'items'
  25. })(SelectableList)
  26. const DomainMuteList = withSubscription({
  27. fetch: (props, $store) => $store.dispatch('fetchDomainMutes'),
  28. select: (props, $store) => get($store.state.users.currentUser, 'domainMutes', []),
  29. childPropName: 'items'
  30. })(SelectableList)
  31. const MutesAndBlocks = {
  32. data () {
  33. return {
  34. activeTab: 'profile'
  35. }
  36. },
  37. created () {
  38. this.$store.dispatch('fetchTokens')
  39. this.$store.dispatch('getKnownDomains')
  40. },
  41. components: {
  42. TabSwitcher,
  43. BlockList,
  44. MuteList,
  45. DomainMuteList,
  46. BlockCard,
  47. MuteCard,
  48. DomainMuteCard,
  49. ProgressButton,
  50. Autosuggest,
  51. Checkbox
  52. },
  53. computed: {
  54. knownDomains () {
  55. return this.$store.state.instance.knownDomains
  56. },
  57. user () {
  58. return this.$store.state.users.currentUser
  59. }
  60. },
  61. methods: {
  62. importFollows (file) {
  63. return this.$store.state.api.backendInteractor.importFollows({ file })
  64. .then((status) => {
  65. if (!status) {
  66. throw new Error('failed')
  67. }
  68. })
  69. },
  70. importBlocks (file) {
  71. return this.$store.state.api.backendInteractor.importBlocks({ file })
  72. .then((status) => {
  73. if (!status) {
  74. throw new Error('failed')
  75. }
  76. })
  77. },
  78. generateExportableUsersContent (users) {
  79. // Get addresses
  80. return users.map((user) => {
  81. // check is it's a local user
  82. if (user && user.is_local) {
  83. // append the instance address
  84. // eslint-disable-next-line no-undef
  85. return user.screen_name + '@' + location.hostname
  86. }
  87. return user.screen_name
  88. }).join('\n')
  89. },
  90. activateTab (tabName) {
  91. this.activeTab = tabName
  92. },
  93. filterUnblockedUsers (userIds) {
  94. return reject(userIds, (userId) => {
  95. const relationship = this.$store.getters.relationship(this.userId)
  96. return relationship.blocking || userId === this.user.id
  97. })
  98. },
  99. filterUnMutedUsers (userIds) {
  100. return reject(userIds, (userId) => {
  101. const relationship = this.$store.getters.relationship(this.userId)
  102. return relationship.muting || userId === this.user.id
  103. })
  104. },
  105. queryUserIds (query) {
  106. return this.$store.dispatch('searchUsers', { query })
  107. .then((users) => map(users, 'id'))
  108. },
  109. blockUsers (ids) {
  110. return this.$store.dispatch('blockUsers', ids)
  111. },
  112. unblockUsers (ids) {
  113. return this.$store.dispatch('unblockUsers', ids)
  114. },
  115. muteUsers (ids) {
  116. return this.$store.dispatch('muteUsers', ids)
  117. },
  118. unmuteUsers (ids) {
  119. return this.$store.dispatch('unmuteUsers', ids)
  120. },
  121. filterUnMutedDomains (urls) {
  122. return urls.filter(url => !this.user.domainMutes.includes(url))
  123. },
  124. queryKnownDomains (query) {
  125. return new Promise((resolve, reject) => {
  126. resolve(this.knownDomains.filter(url => url.toLowerCase().includes(query)))
  127. })
  128. },
  129. unmuteDomains (domains) {
  130. return this.$store.dispatch('unmuteDomains', domains)
  131. }
  132. }
  133. }
  134. export default MutesAndBlocks