From fda133486aed09fb450a920d8e9a67944960940f Mon Sep 17 00:00:00 2001 From: adb Date: Wed, 7 Apr 2021 23:14:38 +0200 Subject: [PATCH] simplify loadEvents and load on mounted --- src/views/chat.vue | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/views/chat.vue b/src/views/chat.vue index 7080789..df6c343 100644 --- a/src/views/chat.vue +++ b/src/views/chat.vue @@ -45,8 +45,8 @@ export default { }, methods:{ onScroll(){ - if (this.$refs.timelineContainer.scrollTop === 0) this.loadEvents(); - this.showScrollBtn = this.scroll.getScrollBottom() > 400; + if (this.$refs.timelineContainer.scrollTop < 400 && this.loadingStatus !== 'loading') this.loadEvents(); + this.showScrollBtn = this.scroll.getScrollBottom() > 500; }, resize(height = this.$refs.newMessage.clientHeight){ this.$refs.chatContainer.style.height = `calc(100% - ${height}px - 3.5rem)`; @@ -56,10 +56,10 @@ export default { }, async loadEvents(){ let scrollBottom = this.scroll.getScrollBottom(); - this.loadingStatus = 'loading ...'; - await matrix.client.paginateEventTimeline(this.room.getLiveTimeline(), {backwards: true}) - .then(state => this.loadingStatus = state?'load more':false); - if (this.loadingStatus) this.scroll.setScrollBottom(scrollBottom); + this.loadingStatus = 'loading'; + await matrix.client.scrollback(this.room, 30); + this.loadingStatus = 'load more'; + this.scroll.setScrollBottom(scrollBottom) }, getUser(userId){ return matrix.client.getUser(userId); @@ -76,11 +76,12 @@ export default { } }, updated(){ - if(this.scroll.getScrollBottom() < 350) this.scroll.scrollToBottom(); + if(this.scroll.getScrollBottom() < 400 && this.loadingStatus !== 'loading') this.scroll.scrollToBottom(); }, mounted(){ this.scroll = new scrollHandler(this.$refs.timelineContainer); this.scroll.scrollToBottom(); + this.onScroll(); }, watch: { '$route'(){