logo

pleroma-fe

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

status_body.js (4366B)


  1. import fileType from 'src/services/file_type/file_type.service'
  2. import RichContent from 'src/components/rich_content/rich_content.jsx'
  3. import { mapGetters } from 'vuex'
  4. import { library } from '@fortawesome/fontawesome-svg-core'
  5. import {
  6. faFile,
  7. faMusic,
  8. faImage,
  9. faLink,
  10. faPollH
  11. } from '@fortawesome/free-solid-svg-icons'
  12. library.add(
  13. faFile,
  14. faMusic,
  15. faImage,
  16. faLink,
  17. faPollH
  18. )
  19. const StatusContent = {
  20. name: 'StatusContent',
  21. props: [
  22. 'compact',
  23. 'status',
  24. 'focused',
  25. 'noHeading',
  26. 'fullContent',
  27. 'singleLine',
  28. 'showingTall',
  29. 'expandingSubject',
  30. 'showingLongSubject',
  31. 'toggleShowingTall',
  32. 'toggleExpandingSubject',
  33. 'toggleShowingLongSubject'
  34. ],
  35. data () {
  36. return {
  37. postLength: this.status.text.length,
  38. parseReadyDone: false
  39. }
  40. },
  41. computed: {
  42. localCollapseSubjectDefault () {
  43. return this.mergedConfig.collapseMessageWithSubject
  44. },
  45. // This is a bit hacky, but we want to approximate post height before rendering
  46. // so we count newlines (masto uses <p> for paragraphs, GS uses <br> between them)
  47. // as well as approximate line count by counting characters and approximating ~80
  48. // per line.
  49. //
  50. // Using max-height + overflow: auto for status components resulted in false positives
  51. // very often with japanese characters, and it was very annoying.
  52. tallStatus () {
  53. if (this.singleLine || this.compact) return false
  54. const lengthScore = this.status.raw_html.split(/<p|<br/).length + this.postLength / 80
  55. return lengthScore > 20
  56. },
  57. longSubject () {
  58. return this.status.summary.length > 240
  59. },
  60. // When a status has a subject and is also tall, we should only have one show more/less button. If the default is to collapse statuses with subjects, we just treat it like a status with a subject; otherwise, we just treat it like a tall status.
  61. mightHideBecauseSubject () {
  62. return !!this.status.summary && this.localCollapseSubjectDefault
  63. },
  64. mightHideBecauseTall () {
  65. return this.tallStatus && !(this.status.summary && this.localCollapseSubjectDefault)
  66. },
  67. hideSubjectStatus () {
  68. return this.mightHideBecauseSubject && !this.expandingSubject
  69. },
  70. hideTallStatus () {
  71. return this.mightHideBecauseTall && !this.showingTall
  72. },
  73. showingMore () {
  74. return (this.mightHideBecauseTall && this.showingTall) || (this.mightHideBecauseSubject && this.expandingSubject)
  75. },
  76. attachmentTypes () {
  77. return this.status.attachments.map(file => fileType.fileType(file.mimetype))
  78. },
  79. ...mapGetters(['mergedConfig'])
  80. },
  81. components: {
  82. RichContent
  83. },
  84. mounted () {
  85. this.status.attentions && this.status.attentions.forEach(attn => {
  86. const { id } = attn
  87. this.$store.dispatch('fetchUserIfMissing', id)
  88. })
  89. },
  90. methods: {
  91. onParseReady (event) {
  92. if (this.parseReadyDone) return
  93. this.parseReadyDone = true
  94. this.$emit('parseReady', event)
  95. const { writtenMentions, invisibleMentions } = event
  96. writtenMentions
  97. .filter(mention => !mention.notifying)
  98. .forEach(mention => {
  99. const { content, url } = mention
  100. const cleanedString = content.replace(/<[^>]+?>/gi, '') // remove all tags
  101. if (!cleanedString.startsWith('@')) return
  102. const handle = cleanedString.slice(1)
  103. const host = url.replace(/^https?:\/\//, '').replace(/\/.+?$/, '')
  104. this.$store.dispatch('fetchUserIfMissing', `${handle}@${host}`)
  105. })
  106. /* This is a bit of a hack to make current tall status detector work
  107. * with rich mentions. Invisible mentions are detected at RichContent level
  108. * and also we generate plaintext version of mentions by stripping tags
  109. * so here we subtract from post length by each mention that became invisible
  110. * via MentionsLine
  111. */
  112. this.postLength = invisibleMentions.reduce((acc, mention) => {
  113. return acc - mention.textContent.length - 1
  114. }, this.postLength)
  115. },
  116. toggleShowMore () {
  117. if (this.mightHideBecauseTall) {
  118. this.toggleShowingTall()
  119. } else if (this.mightHideBecauseSubject) {
  120. this.toggleExpandingSubject()
  121. }
  122. },
  123. generateTagLink (tag) {
  124. return `/tag/${tag}`
  125. }
  126. }
  127. }
  128. export default StatusContent