pleroma-fe/src/components/status_content/status_content.js

154 lines
4.3 KiB
JavaScript
Raw Normal View History

import Attachment from '../attachment/attachment.vue'
import Poll from '../poll/poll.vue'
import Gallery from '../gallery/gallery.vue'
import StatusBody from 'src/components/status_body/status_body.vue'
import LinkPreview from '../link-preview/link-preview.vue'
import { mapGetters, mapState } from 'vuex'
2020-10-21 00:01:28 +03:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faCircleNotch,
faFile,
faMusic,
faImage,
faLink,
2026-01-06 16:22:52 +02:00
faPollH,
2020-10-21 00:01:28 +03:00
} from '@fortawesome/free-solid-svg-icons'
2025-02-03 13:02:14 +02:00
import { useMediaViewerStore } from 'src/stores/media_viewer'
2020-10-21 00:01:28 +03:00
2026-01-06 16:22:52 +02:00
library.add(faCircleNotch, faFile, faMusic, faImage, faLink, faPollH)
2026-01-06 16:22:52 +02:00
const camelCase = (name) => name.charAt(0).toUpperCase() + name.slice(1)
2021-08-07 10:28:45 -04:00
2026-01-06 16:22:52 +02:00
const controlledOrUncontrolledGetters = (list) =>
list.reduce((res, name) => {
const camelized = camelCase(name)
const toggle = `controlledToggle${camelized}`
const controlledName = `controlled${camelized}`
const uncontrolledName = `uncontrolled${camelized}`
res[name] = function () {
return (this.$data[toggle] !== undefined ||
this.$props[toggle] !== undefined) &&
this[toggle]
? this[controlledName]
: this[uncontrolledName]
}
return res
}, {})
2021-08-07 10:28:45 -04:00
const controlledOrUncontrolledToggle = (obj, name) => {
const camelized = camelCase(name)
const toggle = `controlledToggle${camelized}`
const uncontrolledName = `uncontrolled${camelized}`
if (obj[toggle]) {
obj[toggle]()
} else {
obj[uncontrolledName] = !obj[uncontrolledName]
}
}
const StatusContent = {
name: 'StatusContent',
props: [
'status',
2021-06-14 02:52:41 +03:00
'compact',
'collapse',
'focused',
'noHeading',
'fullContent',
2021-08-07 10:28:45 -04:00
'singleLine',
'controlledShowingTall',
'controlledExpandingSubject',
'controlledToggleShowingTall',
'controlledToggleExpandingSubject',
'controlledShowingLongSubject',
2026-01-06 16:22:52 +02:00
'controlledToggleShowingLongSubject',
],
2025-08-19 17:28:19 +03:00
emits: ['parseReady', 'mediaplay', 'mediapause'],
2026-01-06 16:22:52 +02:00
data() {
2021-08-07 10:28:45 -04:00
return {
2026-01-06 16:22:52 +02:00
uncontrolledShowingTall:
this.fullContent || (this.inConversation && this.focused),
2021-08-07 10:28:45 -04:00
uncontrolledShowingLongSubject: false,
// not as computed because it sets the initial state which will be changed later
2026-01-06 16:22:52 +02:00
uncontrolledExpandingSubject:
!this.$store.getters.mergedConfig.collapseMessageWithSubject,
2021-08-07 10:28:45 -04:00
}
},
computed: {
2026-01-06 16:22:52 +02:00
...controlledOrUncontrolledGetters([
'showingTall',
'expandingSubject',
'showingLongSubject',
]),
statusCard() {
if (!this.status.card) return null
2026-01-06 16:22:52 +02:00
return this.status.card.url === this.status.quote_url
? null
: this.status.card
},
2026-01-06 16:22:52 +02:00
hideAttachments() {
return (
(this.mergedConfig.hideAttachments && !this.inConversation) ||
(this.mergedConfig.hideAttachmentsInConv && this.inConversation)
2026-01-06 16:22:52 +02:00
)
},
2026-01-06 16:22:52 +02:00
nsfwClickthrough() {
if (!this.status.nsfw) {
return false
}
if (this.status.summary && this.localCollapseSubjectDefault) {
return false
}
return true
},
2026-01-06 16:22:52 +02:00
localCollapseSubjectDefault() {
return this.mergedConfig.collapseMessageWithSubject
},
2026-01-06 16:22:52 +02:00
attachmentSize() {
if (this.compact) {
return 'small'
2026-01-06 16:22:52 +02:00
} else if (
(this.mergedConfig.hideAttachments && !this.inConversation) ||
(this.mergedConfig.hideAttachmentsInConv && this.inConversation) ||
2026-01-06 16:22:52 +02:00
this.status.attachments.length > this.maxThumbnails
) {
return 'hide'
}
return 'normal'
},
2026-01-06 16:22:52 +02:00
maxThumbnails() {
return this.mergedConfig.maxThumbnails
},
...mapGetters(['mergedConfig']),
...mapState({
2026-01-06 16:22:52 +02:00
currentUser: (state) => state.users.currentUser,
}),
},
components: {
Attachment,
Poll,
Gallery,
LinkPreview,
2026-01-06 16:22:52 +02:00
StatusBody,
2021-08-07 10:28:45 -04:00
},
methods: {
2026-01-06 16:22:52 +02:00
toggleShowingTall() {
2021-08-07 10:28:45 -04:00
controlledOrUncontrolledToggle(this, 'showingTall')
},
2026-01-06 16:22:52 +02:00
toggleExpandingSubject() {
2021-08-07 10:28:45 -04:00
controlledOrUncontrolledToggle(this, 'expandingSubject')
},
2026-01-06 16:22:52 +02:00
toggleShowingLongSubject() {
2021-09-09 00:03:10 -04:00
controlledOrUncontrolledToggle(this, 'showingLongSubject')
2021-08-07 10:28:45 -04:00
},
2026-01-06 16:22:52 +02:00
setMedia() {
const attachments =
this.attachmentSize === 'hide'
? this.status.attachments
: this.galleryAttachments
2023-04-05 13:55:38 -06:00
return () => useMediaViewerStore().setMedia(attachments)
2026-01-06 16:22:52 +02:00
},
},
}
export default StatusContent