logo

pleroma-fe

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

link-preview.js (993B)


  1. import { mapGetters } from 'vuex'
  2. const LinkPreview = {
  3. name: 'LinkPreview',
  4. props: [
  5. 'card',
  6. 'size',
  7. 'nsfw'
  8. ],
  9. data () {
  10. return {
  11. imageLoaded: false
  12. }
  13. },
  14. computed: {
  15. useImage () {
  16. // Currently BE shoudn't give cards if tagged NSFW, this is a bit paranoid
  17. // as it makes sure to hide the image if somehow NSFW tagged preview can
  18. // exist.
  19. return this.card.image && !this.censored && this.size !== 'hide'
  20. },
  21. censored () {
  22. return this.nsfw && this.hideNsfwConfig
  23. },
  24. useDescription () {
  25. return this.card.description && /\S/.test(this.card.description)
  26. },
  27. hideNsfwConfig () {
  28. return this.mergedConfig.hideNsfw
  29. },
  30. ...mapGetters([
  31. 'mergedConfig'
  32. ])
  33. },
  34. created () {
  35. if (this.useImage) {
  36. const newImg = new Image()
  37. newImg.onload = () => {
  38. this.imageLoaded = true
  39. }
  40. newImg.src = this.card.image
  41. }
  42. }
  43. }
  44. export default LinkPreview