logo

pleroma-fe

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

mute_confirm.js (2904B)


  1. import { unitToSeconds } from 'src/services/date_utils/date_utils.js'
  2. import { mapGetters } from 'vuex'
  3. import ConfirmModal from './confirm_modal.vue'
  4. import Select from 'src/components/select/select.vue'
  5. export default {
  6. props: ['type', 'user', 'status'],
  7. emits: ['hide', 'show', 'muted'],
  8. data: () => ({
  9. showing: false,
  10. muteExpiryAmount: 2,
  11. muteExpiryUnit: 'hours'
  12. }),
  13. components: {
  14. ConfirmModal,
  15. Select
  16. },
  17. computed: {
  18. muteExpiryValue () {
  19. unitToSeconds(this.muteExpiryUnit, this.muteExpiryAmount)
  20. },
  21. muteExpiryUnits () {
  22. return ['minutes', 'hours', 'days']
  23. },
  24. domain () {
  25. return this.user.fqn.split('@')[1]
  26. },
  27. keypath () {
  28. if (this.type === 'domain') {
  29. return 'status.mute_domain_confirm'
  30. } else if (this.type === 'conversation') {
  31. return 'status.mute_conversation_confirm'
  32. } else {
  33. return 'user_card.mute_confirm'
  34. }
  35. },
  36. userIsMuted () {
  37. return this.$store.getters.relationship(this.user.id).muting
  38. },
  39. conversationIsMuted () {
  40. return this.status.conversation_muted
  41. },
  42. domainIsMuted () {
  43. return new Set(this.$store.state.users.currentUser.domainMutes).has(this.domain)
  44. },
  45. shouldConfirm () {
  46. switch (this.type) {
  47. case 'domain': {
  48. return this.mergedConfig.modalOnMuteDomain
  49. }
  50. case 'conversation': {
  51. return this.mergedConfig.modalOnMuteConversation
  52. }
  53. default: {
  54. return this.mergedConfig.modalOnMute
  55. }
  56. }
  57. },
  58. ...mapGetters(['mergedConfig'])
  59. },
  60. methods: {
  61. optionallyPrompt () {
  62. if (this.shouldConfirm) {
  63. this.show()
  64. } else {
  65. this.doMute()
  66. }
  67. },
  68. show () {
  69. this.showing = true
  70. this.$emit('show')
  71. },
  72. hide () {
  73. this.showing = false
  74. this.$emit('hide')
  75. },
  76. doMute () {
  77. switch (this.type) {
  78. case 'domain': {
  79. if (!this.domainIsMuted) {
  80. this.$store.dispatch('muteDomain', { id: this.domain, expiresIn: this.muteExpiryValue })
  81. } else {
  82. this.$store.dispatch('unmuteDomain', { id: this.domain })
  83. }
  84. break
  85. }
  86. case 'conversation': {
  87. if (!this.conversationIsMuted) {
  88. this.$store.dispatch('muteConversation', { id: this.status.id, expiresIn: this.muteExpiryValue })
  89. } else {
  90. this.$store.dispatch('unmuteConversation', { id: this.status.id })
  91. }
  92. break
  93. }
  94. default: {
  95. if (!this.userIsMuted) {
  96. this.$store.dispatch('muteUser', { id: this.user.id, expiresIn: this.muteExpiryValue })
  97. } else {
  98. this.$store.dispatch('unmuteUser', { id: this.user.id })
  99. }
  100. break
  101. }
  102. }
  103. this.$emit('muted')
  104. this.hide()
  105. }
  106. }
  107. }