aboutsummaryrefslogtreecommitdiff
path: root/src/components/extra_buttons/extra_buttons.js
blob: 71f5946d46da93780fe436ba8d1f5442edaa807a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Popper from 'vue-popperjs/src/component/popper.js.vue'

const ExtraButtons = {
  props: [ 'status' ],
  components: {
    Popper
  },
  data () {
    return {
      showDropDown: false,
      showPopper: true
    }
  },
  methods: {
    deleteStatus () {
      this.refreshPopper()
      const confirmed = window.confirm(this.$t('status.delete_confirm'))
      if (confirmed) {
        this.$store.dispatch('deleteStatus', { id: this.status.id })
      }
    },
    toggleMenu () {
      this.showDropDown = !this.showDropDown
    },
    pinStatus () {
      this.refreshPopper()
      this.$store.state.api.backendInteractor.pinOwnStatus(this.status.id).then((status) => {
        if (status.error) {
          this.$emit('onError', status.error)
        } else {
          this.$store.dispatch('updatePinned', status)
        }
      })
    },
    unpinStatus () {
      this.refreshPopper()
      this.$store.state.api.backendInteractor.unpinOwnStatus(this.status.id).then((status) => {
        this.$store.dispatch('updatePinned', status)
      })
    },
    refreshPopper () {
      this.showPopper = false
      this.showDropDown = false
      setTimeout(() => {
        this.showPopper = true
      })
    }
  },
  computed: {
    currentUser () { return this.$store.state.users.currentUser },
    canDelete () {
      if (!this.currentUser) { return }
      const superuser = this.currentUser.rights.moderator || this.currentUser.rights.admin
      return superuser || this.status.user.id === this.currentUser.id
    },
    ownStatus () {
      return this.status.user.id === this.currentUser.id
    },
    canPin () {
      return this.ownStatus && (this.status.visibility === 'public' || this.status.visibility === 'unlisted')
    }
  }
}

export default ExtraButtons