aboutsummaryrefslogtreecommitdiff
path: root/src/components/attachment/attachment.js
blob: d16e5086111eb718a09b1cdd49ab951464c6dfa1 (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
66
import StillImage from '../still-image/still-image.vue'
import nsfwImage from '../../assets/nsfw.png'
import fileTypeService from '../../services/file_type/file_type.service.js'

const Attachment = {
  props: [
    'attachment',
    'nsfw',
    'statusId',
    'size',
    'setMedia'
  ],
  data () {
    return {
      nsfwImage: this.$store.state.config.nsfwCensorImage || nsfwImage,
      hideNsfwLocal: this.$store.state.config.hideNsfw,
      preloadImage: this.$store.state.config.preloadImage,
      loading: false,
      modalOpen: false
    }
  },
  components: {
    StillImage
  },
  computed: {
    usePlaceHolder () {
      return this.size === 'hide' || this.type === 'unknown'
    },
    referrerpolicy () {
      return this.$store.state.instance.mediaProxyAvailable ? '' : 'no-referrer'
    },
    type () {
      return fileTypeService.fileType(this.attachment.mimetype)
    },
    hidden () {
      return this.nsfw && this.hideNsfwLocal
    },
    isEmpty () {
      return (this.type === 'html' && !this.attachment.oembed) || this.type === 'unknown'
    },
    isSmall () {
      return this.size === 'small'
    },
    fullwidth () {
      return this.type === 'html' || this.type === 'audio'
    }
  },
  methods: {
    linkClicked ({target}) {
      if (target.tagName === 'A') {
        window.open(target.href, '_blank')
      }
    },
    toggleModal (event) {
      if (this.type !== 'image' && this.type !== 'video') {
        return
      }
      event.stopPropagation()
      event.preventDefault()
      this.setMedia()
      this.$store.dispatch('setCurrent', this.attachment)
    }
  }
}

export default Attachment