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_content.js (4152B)


  1. import Attachment from '../attachment/attachment.vue'
  2. import Poll from '../poll/poll.vue'
  3. import Gallery from '../gallery/gallery.vue'
  4. import StatusBody from 'src/components/status_body/status_body.vue'
  5. import LinkPreview from '../link-preview/link-preview.vue'
  6. import { mapGetters, mapState } from 'vuex'
  7. import { library } from '@fortawesome/fontawesome-svg-core'
  8. import {
  9. faCircleNotch,
  10. faFile,
  11. faMusic,
  12. faImage,
  13. faLink,
  14. faPollH
  15. } from '@fortawesome/free-solid-svg-icons'
  16. import { useMediaViewerStore } from 'src/stores/media_viewer'
  17. library.add(
  18. faCircleNotch,
  19. faFile,
  20. faMusic,
  21. faImage,
  22. faLink,
  23. faPollH
  24. )
  25. const camelCase = name => name.charAt(0).toUpperCase() + name.slice(1)
  26. const controlledOrUncontrolledGetters = list => list.reduce((res, name) => {
  27. const camelized = camelCase(name)
  28. const toggle = `controlledToggle${camelized}`
  29. const controlledName = `controlled${camelized}`
  30. const uncontrolledName = `uncontrolled${camelized}`
  31. res[name] = function () {
  32. return ((this.$data[toggle] !== undefined || this.$props[toggle] !== undefined) && this[toggle]) ? this[controlledName] : this[uncontrolledName]
  33. }
  34. return res
  35. }, {})
  36. const controlledOrUncontrolledToggle = (obj, name) => {
  37. const camelized = camelCase(name)
  38. const toggle = `controlledToggle${camelized}`
  39. const uncontrolledName = `uncontrolled${camelized}`
  40. if (obj[toggle]) {
  41. obj[toggle]()
  42. } else {
  43. obj[uncontrolledName] = !obj[uncontrolledName]
  44. }
  45. }
  46. const StatusContent = {
  47. name: 'StatusContent',
  48. props: [
  49. 'status',
  50. 'compact',
  51. 'focused',
  52. 'noHeading',
  53. 'fullContent',
  54. 'singleLine',
  55. 'controlledShowingTall',
  56. 'controlledExpandingSubject',
  57. 'controlledToggleShowingTall',
  58. 'controlledToggleExpandingSubject',
  59. 'controlledShowingLongSubject',
  60. 'controlledToggleShowingLongSubject'
  61. ],
  62. data () {
  63. return {
  64. uncontrolledShowingTall: this.fullContent || (this.inConversation && this.focused),
  65. uncontrolledShowingLongSubject: false,
  66. // not as computed because it sets the initial state which will be changed later
  67. uncontrolledExpandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject
  68. }
  69. },
  70. computed: {
  71. ...controlledOrUncontrolledGetters(['showingTall', 'expandingSubject', 'showingLongSubject']),
  72. statusCard () {
  73. if (!this.status.card) return null
  74. return this.status.card.url === this.status.quote_url ? null : this.status.card
  75. },
  76. hideAttachments () {
  77. return (this.mergedConfig.hideAttachments && !this.inConversation) ||
  78. (this.mergedConfig.hideAttachmentsInConv && this.inConversation)
  79. },
  80. nsfwClickthrough () {
  81. if (!this.status.nsfw) {
  82. return false
  83. }
  84. if (this.status.summary && this.localCollapseSubjectDefault) {
  85. return false
  86. }
  87. return true
  88. },
  89. localCollapseSubjectDefault () {
  90. return this.mergedConfig.collapseMessageWithSubject
  91. },
  92. attachmentSize () {
  93. if (this.compact) {
  94. return 'small'
  95. } else if ((this.mergedConfig.hideAttachments && !this.inConversation) ||
  96. (this.mergedConfig.hideAttachmentsInConv && this.inConversation) ||
  97. (this.status.attachments.length > this.maxThumbnails)) {
  98. return 'hide'
  99. }
  100. return 'normal'
  101. },
  102. maxThumbnails () {
  103. return this.mergedConfig.maxThumbnails
  104. },
  105. ...mapGetters(['mergedConfig']),
  106. ...mapState({
  107. currentUser: state => state.users.currentUser
  108. })
  109. },
  110. components: {
  111. Attachment,
  112. Poll,
  113. Gallery,
  114. LinkPreview,
  115. StatusBody
  116. },
  117. methods: {
  118. toggleShowingTall () {
  119. controlledOrUncontrolledToggle(this, 'showingTall')
  120. },
  121. toggleExpandingSubject () {
  122. controlledOrUncontrolledToggle(this, 'expandingSubject')
  123. },
  124. toggleShowingLongSubject () {
  125. controlledOrUncontrolledToggle(this, 'showingLongSubject')
  126. },
  127. setMedia () {
  128. const attachments = this.attachmentSize === 'hide' ? this.status.attachments : this.galleryAttachments
  129. return () => useMediaViewerStore().setMedia(attachments)
  130. }
  131. }
  132. }
  133. export default StatusContent