Update CommunicationsChat.vue

This commit is contained in:
Troplo 2022-07-30 18:01:18 +10:00
parent 3d7df1c98a
commit 91386b68c0

View file

@ -1115,32 +1115,34 @@ export default {
this.focusInput() this.focusInput()
}, },
autoScroll(smooth = false) { autoScroll(smooth = false) {
if (!this.avoidAutoScroll) { this.$nextTick(() => {
try { if (!this.avoidAutoScroll) {
const lastIndex = this.messages.length - 1 try {
const lastMessage = document.querySelector(`#message-${lastIndex}`) const lastIndex = this.messages.length - 1
if (smooth) { const lastMessage = document.querySelector(`#message-${lastIndex}`)
lastMessage.scrollIntoView({ if (smooth) {
behavior: "smooth", lastMessage.scrollIntoView({
block: "nearest", behavior: "smooth",
inline: "start" block: "nearest",
}) inline: "start"
} else { })
lastMessage.scrollIntoView() } else {
} lastMessage.scrollIntoView()
this.autoScrollRetry = 0 }
} catch (e) { this.autoScrollRetry = 0
console.log("Could not auto scroll, retrying...") } catch (e) {
if (this.autoScrollRetry < 20) { console.log("Could not auto scroll, retrying...")
setTimeout(() => { if (this.autoScrollRetry < 20) {
this.autoScroll() setTimeout(() => {
}, 50) this.autoScroll()
this.autoScrollRetry++ }, 50)
} else { this.autoScrollRetry++
console.log("Could not auto scroll, retry limit reached") } else {
console.log("Could not auto scroll, retry limit reached")
}
} }
} }
} })
}, },
getMessages() { getMessages() {
this.loadingMessages = true this.loadingMessages = true