2020-11-12 14:16:41 +11:00
|
|
|
import { mapGetters } from 'vuex'
|
|
|
|
|
2019-01-28 00:47:30 +11:00
|
|
|
const LinkPreview = {
|
|
|
|
name: 'LinkPreview',
|
|
|
|
props: [
|
2019-01-28 07:33:36 +11:00
|
|
|
'card',
|
|
|
|
'size',
|
|
|
|
'nsfw'
|
|
|
|
],
|
2019-08-05 04:15:43 +10:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
imageLoaded: false
|
|
|
|
}
|
|
|
|
},
|
2019-01-28 07:33:36 +11:00
|
|
|
computed: {
|
|
|
|
useImage () {
|
|
|
|
// Currently BE shoudn't give cards if tagged NSFW, this is a bit paranoid
|
|
|
|
// as it makes sure to hide the image if somehow NSFW tagged preview can
|
|
|
|
// exist.
|
2020-11-12 14:16:41 +11:00
|
|
|
return this.card.image && !this.censored && this.size !== 'hide'
|
|
|
|
},
|
|
|
|
censored () {
|
|
|
|
return this.nsfw && this.hideNsfwConfig
|
2019-01-28 07:33:36 +11:00
|
|
|
},
|
|
|
|
useDescription () {
|
|
|
|
return this.card.description && /\S/.test(this.card.description)
|
2020-11-12 14:16:41 +11:00
|
|
|
},
|
|
|
|
hideNsfwConfig () {
|
|
|
|
return this.mergedConfig.hideNsfw
|
|
|
|
},
|
|
|
|
...mapGetters([
|
|
|
|
'mergedConfig'
|
|
|
|
])
|
2019-08-05 04:15:43 +10:00
|
|
|
},
|
|
|
|
created () {
|
|
|
|
if (this.useImage) {
|
|
|
|
const newImg = new Image()
|
|
|
|
newImg.onload = () => {
|
|
|
|
this.imageLoaded = true
|
|
|
|
}
|
|
|
|
newImg.src = this.card.image
|
|
|
|
}
|
2019-01-28 07:33:36 +11:00
|
|
|
}
|
2019-01-28 00:47:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
export default LinkPreview
|