Skip to content

Commit

Permalink
Merge pull request #9785 from nextcloud/backport/9706/stable26
Browse files Browse the repository at this point in the history
[stable26] Don't scroll conversation list for visible conversations
  • Loading branch information
Antreesy committed Jun 15, 2023
2 parents 8edd9aa + 7cb35d3 commit a28b431
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/components/LeftSidebar/LeftSidebar.vue
Expand Up @@ -41,6 +41,7 @@
:title="t('spreed', 'Conversations')" />
<Conversation v-for="item of conversationsList"
:key="item.id"
ref="conversations"
:item="item" />
<template v-if="!initialisedConversations">
<LoadingPlaceholder type="conversations" />
Expand Down Expand Up @@ -515,8 +516,11 @@ export default {
handleScroll() {
this.isScrolledToTop = this.$refs.container.scrollTop === 0
},
elementIsAboveViewpoint(container, element) {
return element.offsetTop < container.scrollTop
},
elementIsBelowViewpoint(container, element) {
return element.offsetTop > container.scrollTop + container.clientHeight
return element.offsetTop + element.offsetHeight > container.scrollTop + container.clientHeight
},
handleUnreadMention() {
this.unreadNum = 0
Expand Down Expand Up @@ -544,22 +548,24 @@ export default {
},
scrollToConversation(token) {
// FIXME: not sure why we can't scroll earlier even when the element exists already
// when too early, Firefox only scrolls a few pixels towards the element but
// not enough to make it visible
setTimeout(() => {
const conversation = document.getElementById(`conversation_${token}`)
this.$nextTick(() => {
const conversation = this.$refs.conversations[this.conversationsList.findIndex(item => item.token === token)].$el
if (!conversation) {
return
}
this.$nextTick(() => {
conversation.scrollIntoView({
if (this.elementIsBelowViewpoint(this.$refs.container, conversation)) {
this.$refs.container.scrollTo({
top: conversation.offsetTop + conversation.offsetHeight * 2 - this.$refs.container.clientHeight,
behavior: 'smooth',
block: 'start',
inline: 'nearest',
})
})
}, 500)
} else if (this.elementIsAboveViewpoint(this.$refs.container, conversation)) {
this.$refs.container.scrollTo({
top: conversation.offsetTop - conversation.offsetHeight,
behavior: 'smooth',
})
}
})
},
onRouteChange({ from, to }) {
Expand Down

0 comments on commit a28b431

Please sign in to comment.