Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ConversationItem from './ConversationItem.vue'
import ConversationTagHeader from './ConversationTagHeader.vue'
import { AVATAR, CONVERSATION } from '../../../constants.ts'
import { useConversationTagsStore } from '../../../stores/conversationTags.ts'
import { hasCall, hasUnreadMessages } from '../../../utils/conversation.ts'
import { hasCall, hasUnreadMentions, hasUnreadMessages } from '../../../utils/conversation.ts'

export type VirtualListItem = (Conversation | TagHeaderItem) & { _key?: string }

Expand Down Expand Up @@ -347,11 +347,35 @@ function scrollToConversation(token: string) {
}
}

/**
* Get the indices (in the flattened virtual-list, i.e. tag-header- and
* collapsed-section-aware) of conversations with unread mentions.
*/
function getUnreadMentionIndices(): number[] {
const indices: number[] = []
listItems.value.forEach((item, index) => {
if (!isTagHeader(item) && hasUnreadMentions(item)) {
indices.push(index)
}
})
return indices
}

/**
* Get the index (in the flattened virtual-list) of the last unread-mention
* conversation currently below the viewport, or null if there is none.
*/
function getLastUnreadMentionBelowViewportIndex(): number | null {
const lastInViewport = getLastItemInViewportIndex()
return getUnreadMentionIndices().findLast((idx) => idx > lastInViewport) ?? null
}

defineExpose({
getFirstItemInViewportIndex,
getLastItemInViewportIndex,
scrollToItem,
scrollToConversation,
getLastUnreadMentionBelowViewportIndex,
})
</script>

Expand Down
34 changes: 9 additions & 25 deletions src/components/LeftSidebar/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,8 @@ export default {
return sortConversationsList(this.filteredConversationsList, this.groupMode, this.sortOrder)
},

unreadMentionIndices() {
const indices = []
for (const i in this.sortedConversationsList) {
if (hasUnreadMentions(this.sortedConversationsList[i])) {
indices.push(i)
}
}
return indices
hasUnreadMentionsInList() {
return this.sortedConversationsList.filter(hasUnreadMentions).length
},

emptyContentLabel() {
Expand Down Expand Up @@ -780,7 +774,7 @@ export default {
}
},

unreadMentionIndices() {
hasUnreadMentionsInList() {
this.debounceHandleScroll()
},
},
Expand Down Expand Up @@ -1155,22 +1149,12 @@ export default {
},

handleScroll() {
this.computeLastUnreadMention()
},

/**
* Find position of the last unread conversation below viewport.
* Iterates only over indices with unread mentions (cached via the
* unreadMentionIndices computed) instead of the full list.
*/
computeLastUnreadMention() {
if (!this.$refs.scroller) {
this.lastUnreadMentionBelowViewportIndex = null
return
}
const lastInViewport = this.$refs.scroller.getLastItemInViewportIndex()
this.lastUnreadMentionBelowViewportIndex = this.unreadMentionIndices
.findLast((idx) => idx > lastInViewport) ?? null
/**
* Find position of the last unread conversation below viewport.
* Delegates to the scroller, which owns the flattened list (tag
* headers and sections) and its indexes.
*/
this.lastUnreadMentionBelowViewportIndex = this.$refs.scroller?.getLastUnreadMentionBelowViewportIndex() ?? null
},

async scrollToConversation(token) {
Expand Down
Loading