Skip to content

Commit baa09a1

Browse files
Antreesybackportbot[bot]
authored andcommitted
feat(conversation): adjust scroll to unread mentions
- previous 'unreadMentionIndices' was accounting only for sortedConversationsList, but we render ConversationsListVirtual#listItems and should compute indexes directly from it Assisted-by: ClaudeCode:claude-sonnet-5 Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent 9c7d5bf commit baa09a1

2 files changed

Lines changed: 34 additions & 26 deletions

File tree

src/components/LeftSidebar/ConversationsList/ConversationsListVirtual.vue

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ConversationItem from './ConversationItem.vue'
1414
import ConversationTagHeader from './ConversationTagHeader.vue'
1515
import { AVATAR, CONVERSATION } from '../../../constants.ts'
1616
import { useConversationTagsStore } from '../../../stores/conversationTags.ts'
17-
import { hasCall, hasUnreadMessages } from '../../../utils/conversation.ts'
17+
import { hasCall, hasUnreadMentions, hasUnreadMessages } from '../../../utils/conversation.ts'
1818
1919
export type VirtualListItem = (Conversation | TagHeaderItem) & { _key?: string }
2020
@@ -349,11 +349,35 @@ function scrollToConversation(token: string) {
349349
}
350350
}
351351
352+
/**
353+
* Get the indices (in the flattened virtual-list, i.e. tag-header- and
354+
* collapsed-section-aware) of conversations with unread mentions.
355+
*/
356+
function getUnreadMentionIndices(): number[] {
357+
const indices: number[] = []
358+
listItems.value.forEach((item, index) => {
359+
if (!isTagHeader(item) && hasUnreadMentions(item)) {
360+
indices.push(index)
361+
}
362+
})
363+
return indices
364+
}
365+
366+
/**
367+
* Get the index (in the flattened virtual-list) of the last unread-mention
368+
* conversation currently below the viewport, or null if there is none.
369+
*/
370+
function getLastUnreadMentionBelowViewportIndex(): number | null {
371+
const lastInViewport = getLastItemInViewportIndex()
372+
return getUnreadMentionIndices().findLast((idx) => idx > lastInViewport) ?? null
373+
}
374+
352375
defineExpose({
353376
getFirstItemInViewportIndex,
354377
getLastItemInViewportIndex,
355378
scrollToItem,
356379
scrollToConversation,
380+
getLastUnreadMentionBelowViewportIndex,
357381
})
358382
</script>
359383

src/components/LeftSidebar/LeftSidebar.vue

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,8 @@ export default {
696696
return sortConversationsList(this.filteredConversationsList, this.groupMode, this.sortOrder)
697697
},
698698
699-
unreadMentionIndices() {
700-
const indices = []
701-
for (const i in this.sortedConversationsList) {
702-
if (hasUnreadMentions(this.sortedConversationsList[i])) {
703-
indices.push(i)
704-
}
705-
}
706-
return indices
699+
hasUnreadMentionsInList() {
700+
return this.sortedConversationsList.filter(hasUnreadMentions).length
707701
},
708702
709703
emptyContentLabel() {
@@ -816,7 +810,7 @@ export default {
816810
}
817811
},
818812
819-
unreadMentionIndices() {
813+
hasUnreadMentionsInList() {
820814
this.debounceHandleScroll()
821815
},
822816
},
@@ -1143,22 +1137,12 @@ export default {
11431137
},
11441138
11451139
handleScroll() {
1146-
this.computeLastUnreadMention()
1147-
},
1148-
1149-
/**
1150-
* Find position of the last unread conversation below viewport.
1151-
* Iterates only over indices with unread mentions (cached via the
1152-
* unreadMentionIndices computed) instead of the full list.
1153-
*/
1154-
computeLastUnreadMention() {
1155-
if (!this.$refs.scroller) {
1156-
this.lastUnreadMentionBelowViewportIndex = null
1157-
return
1158-
}
1159-
const lastInViewport = this.$refs.scroller.getLastItemInViewportIndex()
1160-
this.lastUnreadMentionBelowViewportIndex = this.unreadMentionIndices
1161-
.findLast((idx) => idx > lastInViewport) ?? null
1140+
/**
1141+
* Find position of the last unread conversation below viewport.
1142+
* Delegates to the scroller, which owns the flattened list (tag
1143+
* headers and sections) and its indexes.
1144+
*/
1145+
this.lastUnreadMentionBelowViewportIndex = this.$refs.scroller?.getLastUnreadMentionBelowViewportIndex() ?? null
11621146
},
11631147
11641148
async scrollToConversation(token) {

0 commit comments

Comments
 (0)