diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js
index dfb27836f..d6ab361d7 100644
--- a/src/components/conversation/conversation.js
+++ b/src/components/conversation/conversation.js
@@ -1,3 +1,4 @@
+import { get } from 'lodash-es'
import { storeToRefs } from 'pinia'
import {
computed,
@@ -19,6 +20,8 @@ import ThreadTree from 'src/components/thread_tree/thread_tree.vue'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
+import { useStatusesStore } from 'src/stores/statuses.js'
+import { useStreamingStore } from 'src/stores/streaming.js'
import { useConversation } from 'src/composables/useConversation.js'
import { useInterfaceSizes } from 'src/composables/useInterfaceSizes.js'
@@ -26,6 +29,8 @@ import { useScrollPosition } from 'src/composables/useScrollPosition.js'
import { useTreeConversationTopology } from 'src/composables/useTreeConversationTopology.js'
import { useVirtualScrolling } from 'src/composables/useVirtualScrolling.js'
+import { WSConnectionStatus } from 'src/api/websocket.js'
+
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faAngleDoubleDown,
@@ -67,6 +72,17 @@ export default {
},
emits: ['heightChange', 'suspendableStateChange'],
setup(props, { emit }) {
+ // # Helpers
+ const getStatusObject = (id) => useStatusesStore().allStatuses.get(id)
+ const getConversationId = (statusId) => {
+ const status = getStatusObject(statusId)
+ return get(
+ status,
+ 'retweeted_status.statusnet_conversation_id',
+ get(status, 'statusnet_conversation_id'),
+ )
+ }
+
const scroller = useScrollPosition()
const tryScrollTo = async (id) => {
if (!id) {
@@ -84,30 +100,15 @@ export default {
const router = useRouter()
- const onReset = () => {
- resetThreadDisplay()
- }
-
- // # Main things
- const {
- currentStatus,
- mainStatus,
- fullConversation,
- replies,
- getReplies,
- fetchConversation,
- loadError,
- focusedId,
- setFocused,
- reset,
- } = useConversation({
- statusId,
- onReset,
- })
-
// # Main Configuration / global state
const { mergedConfig } = storeToRefs(useMergedConfigStore())
+ const { mastoUserSocketStatus } = storeToRefs(useStreamingStore())
const displayStyle = computed(() => mergedConfig.value.conversationDisplay)
+ const streamingEnabled = computed(
+ () =>
+ mergedConfig.value.useStreamingApi &&
+ mastoUserSocketStatus === WSConnectionStatus.JOINED,
+ )
const { layoutType } = storeToRefs(useInterfaceStore())
const mobileLayout = computed(() => layoutType.value === 'mobile')
@@ -122,11 +123,32 @@ export default {
provide('isPage', isPage)
provide('expandable', true)
+ // # Focus
+ const focusedId = ref(statusId.value)
const focused = computed(() => (isExpanded.value ? focusedId.value : null))
+ const setFocused = (id) => {
+ if (!id) return
+ focusedId.value = id
+
+ if (!streamingEnabled.value) {
+ useStatusesStore().fetchStatus(id)
+ }
+
+ useStatusesStore().fetchFavsAndRepeats(id)
+ useStatusesStore().fetchEmojiReactions(id)
+ }
provide('focused', focused)
- const conversation = computed(() =>
- !expanded.value ? [currentStatus.value] : fullConversation.value,
- )
+
+ // # Main things
+ const {
+ currentStatus,
+ mainStatus,
+ conversation,
+ replies,
+ getReplies,
+ fetchConversation,
+ loadError,
+ } = useConversation(focusedId, isExpanded)
watch(
expanded,
@@ -134,13 +156,32 @@ export default {
if (value) {
await fetchConversation()
} else {
- reset()
+ resetDisplayState()
}
if (isPage.value) return
},
{ flush: 'post' },
)
+ const resetDisplayState = () => {
+ setFocused(statusId.value)
+ resetThreadDisplay()
+ }
+ watch(statusId, (newVal, oldVal) => {
+ const newConversationId = getConversationId(newVal)
+ const oldConversationId = getConversationId(oldVal)
+ if (
+ newConversationId &&
+ oldConversationId &&
+ newConversationId === oldConversationId
+ ) {
+ setFocused(newVal)
+ } else {
+ resetDisplayState()
+ fetchConversation()
+ }
+ })
+
// Component created
if (isPage.value) {
fetchConversation()
@@ -151,17 +192,10 @@ export default {
const lastStatus = computed(
() => conversation.value[conversation.value.legnth - 1],
)
- const getStatusClasses = (status, ancestor) => {
- const result = {
- '-first': status.id === firstStatus.value?.id,
- '-last': status.id === lastStatus.value?.id,
- }
- if (ancestor) {
- result['-ancestor'] = true
- result['-fade'] = mergedConfig.value.conversationTreeFadeAncestors
- }
- return result
- }
+ const getStatusClasses = (status, active) => ({
+ '-first': status.id === firstStatus.value?.id,
+ '-last': status.id === lastStatus.value?.id,
+ })
const { fontSize } = useInterfaceSizes()
@@ -194,9 +228,6 @@ export default {
? mutedStatusHeight
: normalStatusHeight
- const anchorIds = computed(
- () => new Set([mainStatus.value?.id, currentStatus.value?.id]),
- )
// # Linear style stuff
const isLinearView = computed(() => displayStyle.value !== 'tree')
const linearElement = useTemplateRef('linear')
@@ -210,7 +241,8 @@ export default {
body: linearElement,
scrollPositionInstance: scroller,
scrollCompensation: linearScrollCompensation,
- anchorIds,
+ anchorId: mainStatus.value?.id,
+ anchorRepeatId: currentStatus.value?.id,
getPlaceholderHeight,
})
const changeSuspendStateLinearLocal = (e) => {
@@ -245,7 +277,6 @@ export default {
body: ancestorsElement,
scrollPositionInstance: scroller,
scrollCompensation: treeScrollCompensation,
- collapseMode: 'height',
getPlaceholderHeight,
})
const changeSuspendStateAncestorsLocal = (e) => {
@@ -276,6 +307,9 @@ export default {
const shouldShowAncestors = computed(
() => isExpanded.value && heightChartAncestors.value.length > 0,
)
+ const shouldFadeAncestors = computed(
+ () => mergedConfig.value.conversationTreeFadeAncestors,
+ )
// # Scrolling
const diveIntoStatus = (id) => tryScrollTo(id)
@@ -333,6 +367,7 @@ export default {
treeViewIsSimple,
shouldShowAllConversationButton,
shouldShowAncestors,
+ shouldFadeAncestors,
// # Scrolling
diveToTopLevel,
diff --git a/src/components/conversation/conversation.vue b/src/components/conversation/conversation.vue
index 4e10bdcd0..1c0d459f3 100644
--- a/src/components/conversation/conversation.vue
+++ b/src/components/conversation/conversation.vue
@@ -91,14 +91,15 @@
ref="ancestors"
class="thread-ancestors"
>
-
-
+
-
-
+
diff --git a/src/components/status/status.js b/src/components/status/status.js
index ec685b0d2..277421c6e 100644
--- a/src/components/status/status.js
+++ b/src/components/status/status.js
@@ -592,7 +592,7 @@ const Status = {
const [entry] = e
this.$emit('heightChange', {
id: this.status.id,
- height: entry.contentRect.height + 1,
+ height: entry.contentRect.height,
element: this.$el,
})
},
@@ -600,18 +600,13 @@ const Status = {
mounted() {
if (this.$refs.root) {
this.resizeObserver.observe(this.$refs.root)
- this.updateVirtualHeight([
- {
- contentRect: this.$refs.root.getBoundingClientRect(),
- },
- ])
}
},
unmounted() {
this.resizeObserver.disconnect()
},
watch: {
- hideStatus: function () {
+ hideStatus: function (element) {
if (this.$refs.root) {
this.resizeObserver.observe(this.$refs.root)
} else {
diff --git a/src/components/status/status.vue b/src/components/status/status.vue
index fa288145f..c0a1b0238 100644
--- a/src/components/status/status.vue
+++ b/src/components/status/status.vue
@@ -1,5 +1,5 @@
-
-
+
diff --git a/src/composables/useConversation.js b/src/composables/useConversation.js
index f6ba3a4e3..9bec1e160 100644
--- a/src/composables/useConversation.js
+++ b/src/composables/useConversation.js
@@ -1,26 +1,15 @@
import { get } from 'lodash-es'
-import { storeToRefs } from 'pinia'
-import { computed, provide, ref, watch } from 'vue'
+import { computed, provide, ref } from 'vue'
-import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useOAuthStore } from 'src/stores/oauth.js'
import { useStatusesStore } from 'src/stores/statuses.js'
-import { useStreamingStore } from 'src/stores/streaming.js'
import {
fetchConversation as apiFetchConversation,
fetchStatus as apiFetchStatus,
} from 'src/api/public.js'
-export function useConversation({ statusId, onReset }) {
- const { mastoUserSocketStatus } = storeToRefs(useStreamingStore())
- const { mergedConfig } = storeToRefs(useMergedConfigStore())
- const streamingEnabled = computed(
- () =>
- mergedConfig.value.useStreamingApi &&
- mastoUserSocketStatus === WSConnectionStatus.JOINED,
- )
-
+export function useConversation(statusId, expanded) {
const getStatusObject = (id) => useStatusesStore().allStatuses.get(id)
const getConversationId = (statusId) => {
const status = getStatusObject(statusId)
@@ -30,37 +19,6 @@ export function useConversation({ statusId, onReset }) {
get(status, 'statusnet_conversation_id'),
)
}
- // # Focus
- const focusedId = ref(statusId.value)
- const setFocused = (id) => {
- if (!id) return
- focusedId.value = id
-
- if (!streamingEnabled.value) {
- useStatusesStore().fetchStatus(id)
- }
-
- useStatusesStore().fetchFavsAndRepeats(id)
- useStatusesStore().fetchEmojiReactions(id)
- }
- const reset = () => {
- onReset?.()
- setFocused(statusId.value)
- }
- watch(statusId, (newVal, oldVal) => {
- const newConversationId = getConversationId(newVal)
- const oldConversationId = getConversationId(oldVal)
- if (
- newConversationId &&
- oldConversationId &&
- newConversationId === oldConversationId
- ) {
- setFocused(newVal)
- } else {
- resetDisplayState()
- fetchConversation()
- }
- })
const loadError = ref(null)
const currentStatus = computed(() => getStatusObject(statusId.value))
@@ -91,6 +49,10 @@ export function useConversation({ statusId, onReset }) {
return []
}
+ if (!expanded.value) {
+ return [currentStatus.value]
+ }
+
const conversation = useStatusesStore().conversations.get(
conversationId.value,
)
@@ -157,13 +119,10 @@ export function useConversation({ statusId, onReset }) {
return {
currentStatus,
mainStatus,
- fullConversation: conversation,
- focusedId,
- setFocused,
+ conversation,
replies,
getReplies,
fetchConversation,
- reset,
loadError,
}
}
diff --git a/src/composables/useVirtualScrolling.js b/src/composables/useVirtualScrolling.js
index d466fc059..07e0cae8c 100644
--- a/src/composables/useVirtualScrolling.js
+++ b/src/composables/useVirtualScrolling.js
@@ -1,4 +1,3 @@
-import { last } from 'lodash-es'
import { computed, nextTick, ref, toValue, watch } from 'vue'
import { useWindowSize } from 'src/composables/useWindowSize.js'
@@ -10,18 +9,12 @@ export function useVirtualScrolling({
body,
// useScrollPosition composable, used to prevent dupicating instances
scrollPositionInstance,
- // buffer zone, the amount of placeholder heights to include
- buffer,
+ // ID of anchor element, used for scroll compensation.
+ // Omitting it makes last element the anchor
+ anchorId,
+ anchorRepeatId,
// whether to use scroll compensation when elements above anchor change
- // set to 'positive' to only compensate for positive increase (useful when
- // combined with infinite scroll)
scrollCompensation,
- // How to handle collapse/expansion (going from 0 elements to full and back)
- // - false - don't do scroll compensation at all
- // - 'height' - compensate scroll according to list's height
- collapseMode,
- // Anchor. Set of IDs of element relative to which do scroll compensation
- anchorIds,
// Placeholder height specification. Must be a function.
// function will be called either:
// - without arguments (for generic placeholder, i.e. buffer zone size)
@@ -45,13 +38,14 @@ export function useVirtualScrolling({
// Map every height and suspendable state
const chart = list.value.map((item) => {
const { id } = item
- const height = (() => {
- if (heights.value.has(id)) {
- return heights.value.get(id)
- } else {
- return getPlaceholderHeight(id).value
- }
- })()
+ const height =
+ (() => {
+ if (heights.value.has(id)) {
+ return heights.value.get(id)
+ } else {
+ return getPlaceholderHeight(id).value
+ }
+ })() + 1 //including border
const suspendable = !unsuspendibleIds.value.has(id)
return { id, height, suspendable, item }
})
@@ -75,41 +69,41 @@ export function useVirtualScrolling({
if (newVal.length === 0 && oldVal.length === 0) return
pauseWatchers()
- const expansion = oldVal.length === 0 && newVal.length !== 0
- const collapse = oldVal.length !== 0 && newVal.length === 0
+ // If we're not given an achor, treat last element as one
+ const getAnchoredEl = (list) =>
+ toValue(anchorId)
+ ? list.find(
+ ({ id }) =>
+ id === toValue(anchorId) || id === toValue(anchorRepeatId),
+ )
+ : list[list.length - 1]
+
+ const oldElement = getAnchoredEl(oldVal)
+ const newElement = getAnchoredEl(newVal)
const diff = (() => {
- if (expansion || collapse) {
- if (toValue(collapseMode) === 'height') {
- const oldBottomElement = last(oldVal)
- const newBottomElement = last(newVal)
-
- if (expansion) {
- return newBottomElement.top + newBottomElement.height
- } else if (collapse) {
- return 0 - oldBottomElement.top - oldBottomElement.height
- }
- }
- return 0
- } else if (toValue(anchorIds) != null) {
- const anchorOld = oldVal.find(({ id }) => toValue(anchorIds).has(id))
- const anchorNew = newVal.find(({ id }) => toValue(anchorIds).has(id))
- if (anchorOld == null) {
- throw new Error('Anchor not found!')
- }
-
- const disappeared = anchorOld != null && anchorNew == null
- if (disappeared) {
- throw new Error('Anchor disappeared!')
- }
-
- return anchorNew.top - anchorOld.top
+ if (oldElement && newElement) {
+ // Generic shifting
+ const oldOffset = toValue(anchorId)
+ ? oldElement.top
+ : oldElement.top + oldElement.height
+ const newOffset = toValue(anchorId)
+ ? newElement.top
+ : newElement.top + newElement.height
+ return newOffset - oldOffset
+ } else if (!oldElement && newElement) {
+ // Expansion
+ return newElement.top + newElement.height
+ } else if (oldElement && !newElement) {
+ // Collapsing
+ return 0 - oldElement.top - oldElement.height
} else {
- return 0
+ throw new Error(
+ "Somehow both new and old elements are missing, this shouldn't happen",
+ )
}
})()
- console.log(diff)
if (diff !== 0) {
// Scroll by amount offset changed to keep it in view
topScrollBoundary.value += diff
@@ -166,9 +160,7 @@ export function useVirtualScrolling({
// # Visiblity
// Add buffer zone to boundary, equal to approx 3 items heights
- const bufferZone = computed(
- () => getPlaceholderHeight().value * (toValue(buffer) ?? 3),
- )
+ const buffer = computed(() => getPlaceholderHeight().value * 3)
const heightChartGrouped = computed(() => {
// Determine visibility state
@@ -177,9 +169,9 @@ export function useVirtualScrolling({
const itemBottomBoundary = heightChartItem.top + heightChartItem.height
// Include buffer zone
- const finalTopScrollBoundary = topScrollBoundary.value - bufferZone.value
+ const finalTopScrollBoundary = topScrollBoundary.value - buffer.value
const finalBottomScrollBoundary =
- bottomScrollBoundary.value + bufferZone.value
+ bottomScrollBoundary.value + buffer.value
// To be visible, item's bottom boundary shoud be below top scroll boundary)
const isBelowTopBoundary = itemBottomBoundary > finalTopScrollBoundary