2021-08-07 18:53:23 -04:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
|
import {
|
|
|
|
|
faAngleDoubleDown,
|
2026-01-06 16:22:52 +02:00
|
|
|
faAngleDoubleRight,
|
2021-08-07 18:53:23 -04:00
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
2026-09-08 03:01:22 +03:00
|
|
|
import { useMergedConfigStore } from 'src/stores/merged_config.js'
|
|
|
|
|
|
2026-01-06 16:22:52 +02:00
|
|
|
library.add(faAngleDoubleDown, faAngleDoubleRight)
|
2021-08-07 18:53:23 -04:00
|
|
|
|
2021-08-06 20:18:27 -04:00
|
|
|
const ThreadTree = {
|
2026-06-04 21:59:09 +03:00
|
|
|
components: {},
|
2021-08-06 20:18:27 -04:00
|
|
|
name: 'ThreadTree',
|
|
|
|
|
props: {
|
2026-08-18 18:00:36 +03:00
|
|
|
statusId: String,
|
2021-08-06 20:18:27 -04:00
|
|
|
inProfile: Boolean,
|
|
|
|
|
collapsable: Boolean,
|
|
|
|
|
isExpanded: Boolean,
|
|
|
|
|
pinnedStatusIdsObject: Object,
|
|
|
|
|
profileUserId: String,
|
|
|
|
|
|
2026-09-08 03:01:22 +03:00
|
|
|
depth: Number,
|
|
|
|
|
conversation: Array,
|
2026-07-06 19:43:08 +03:00
|
|
|
focused: String,
|
2026-09-08 03:01:22 +03:00
|
|
|
replies: Map,
|
2021-08-07 00:33:06 -04:00
|
|
|
|
2026-06-30 06:00:41 +03:00
|
|
|
canDive: Boolean,
|
2026-09-08 03:01:22 +03:00
|
|
|
threadDisplay: Map,
|
|
|
|
|
threadDisplayDefault: Map,
|
2021-08-06 20:18:27 -04:00
|
|
|
},
|
2026-09-08 03:01:22 +03:00
|
|
|
emits: [
|
|
|
|
|
'suspendableStateChange',
|
|
|
|
|
'goto',
|
|
|
|
|
'dive',
|
|
|
|
|
'heightChange',
|
|
|
|
|
'toggleExpanded',
|
|
|
|
|
'showThreadRecursively',
|
|
|
|
|
],
|
2021-08-06 20:18:27 -04:00
|
|
|
computed: {
|
2026-01-06 16:22:52 +02:00
|
|
|
currentReplies() {
|
2026-09-08 03:01:22 +03:00
|
|
|
return [...this.getReplies(this.statusId)].map(({ id }) => id)
|
|
|
|
|
},
|
|
|
|
|
simple() {
|
|
|
|
|
return !useMergedConfigStore().mergedConfig.conversationTreeAdvanced
|
2021-08-06 20:18:27 -04:00
|
|
|
},
|
2026-01-06 16:22:52 +02:00
|
|
|
threadShowing() {
|
2026-09-08 03:01:22 +03:00
|
|
|
const result = this.threadDisplay.get(this.statusId) ?? this.threadDisplayDefault.get(this.statusId)
|
|
|
|
|
return result === 'showing'
|
|
|
|
|
},
|
|
|
|
|
totalReplyCount() {
|
|
|
|
|
const sizes = {}
|
|
|
|
|
const subTreeSizeFor = (id) => {
|
|
|
|
|
if (sizes[id]) {
|
|
|
|
|
return sizes[id]
|
|
|
|
|
}
|
|
|
|
|
sizes[id] =
|
|
|
|
|
1 +
|
|
|
|
|
[...this.getReplies(id)]
|
|
|
|
|
.map(({ id }) => id)
|
|
|
|
|
.map((cid) => subTreeSizeFor(cid))
|
|
|
|
|
.reduce((a, b) => a + b, 0)
|
|
|
|
|
return sizes[id]
|
|
|
|
|
}
|
|
|
|
|
this.conversation.map((k) => k.id).forEach(subTreeSizeFor)
|
|
|
|
|
return Object.keys(sizes).reduce((res, id) => {
|
|
|
|
|
res[id] = sizes[id] - 1 // exclude itself
|
|
|
|
|
return res
|
|
|
|
|
}, {})
|
|
|
|
|
},
|
|
|
|
|
totalReplyDepth() {
|
|
|
|
|
const depths = {}
|
|
|
|
|
const subTreeDepthFor = (id) => {
|
|
|
|
|
if (depths[id]) {
|
|
|
|
|
return depths[id]
|
|
|
|
|
}
|
|
|
|
|
depths[id] =
|
|
|
|
|
1 +
|
|
|
|
|
[...this.getReplies(id)]
|
|
|
|
|
.map(({ id }) => id)
|
|
|
|
|
.map((cid) => subTreeDepthFor(cid))
|
|
|
|
|
.reduce((a, b) => (a > b ? a : b), 0)
|
|
|
|
|
return depths[id]
|
|
|
|
|
}
|
|
|
|
|
this.conversation.map((k) => k.id).forEach(subTreeDepthFor)
|
|
|
|
|
return Object.keys(depths).reduce((res, id) => {
|
|
|
|
|
res[id] = depths[id] - 1 // exclude itself
|
|
|
|
|
return res
|
|
|
|
|
}, {})
|
2021-08-07 10:28:45 -04:00
|
|
|
},
|
2021-08-06 20:18:27 -04:00
|
|
|
},
|
2026-09-08 03:01:22 +03:00
|
|
|
methods: {
|
|
|
|
|
getReplies(id) {
|
|
|
|
|
return this.replies.get(id) ?? new Set()
|
|
|
|
|
},
|
|
|
|
|
}
|
2021-08-06 20:18:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ThreadTree
|