@@ -447,6 +447,7 @@ export default {
447
447
token: this.token,
448
448
id: this.conversation.lastReadMessage,
449
449
})
450
+
450
451
if (this.$store.getters.getFirstKnownMessageId(this.token) === null) {
451
452
// first time load, initialize important properties
452
453
this.$store.dispatch('setFirstKnownMessageId', {
@@ -458,18 +459,31 @@ export default {
458
459
id: this.conversation.lastReadMessage,
459
460
})
460
461
461
- // get history + new messages
462
+ // get history before last read message
462
463
await this.getOldMessages(true)
464
+ // at this stage, the read marker will appear at the bottom of the view port since
465
+ // we haven't fetched the messages that come after it yet
466
+ // TODO: should we still show a spinner at this stage ?
463
467
}
464
468
465
- // focus on next tick to make sure the DOM elements
466
- // for known messages are already rendered
467
- this.$nextTick(() => {
468
- this.scrollToFocussedMessage()
469
- })
469
+ let hasScrolled = false
470
+ // if lookForNewMessages will long poll instead of returning existing messages,
471
+ // scroll right away to avoid delays
472
+ if (this.$store.getters.getLastKnownMessageId(this.token) === this.conversation.lastMessage.id) {
473
+ hasScrolled = true
474
+ await this.$nextTick(() => {
475
+ this.scrollToFocussedMessage()
476
+ })
477
+ }
470
478
471
479
// get new messages
472
480
await this.lookForNewMessages()
481
+
482
+ // don't scroll if lookForNewMessages was polling as we don't want
483
+ // to scroll back to the read marker after receiving new messages later
484
+ if (!hasScrolled) {
485
+ this.scrollToFocussedMessage()
486
+ }
473
487
} else {
474
488
this.$store.dispatch('cancelLookForNewMessages', { requestId: this.chatIdentifier })
475
489
}
@@ -644,6 +658,7 @@ export default {
644
658
* Also see updateReadMarkerPosition() for the backend update.
645
659
*/
646
660
refreshReadMarkerPosition() {
661
+ console.debug('setVisualLastReadMessageId token=' + this.token + ' id=' + this.conversation.lastReadMessage)
647
662
this.$store.dispatch('setVisualLastReadMessageId', {
648
663
token: this.token,
649
664
id: this.conversation.lastReadMessage,
@@ -669,6 +684,7 @@ export default {
669
684
670
685
// to fix issues, this scenario should not happen
671
686
if (this.conversation.lastReadMessage === 0) {
687
+ console.debug('clearLastReadMessage because lastReadMessage was 0 token=' + this.token)
672
688
this.$store.dispatch('clearLastReadMessage', { token: this.token, updateVisually: true })
673
689
return
674
690
}
@@ -685,6 +701,7 @@ export default {
685
701
686
702
// if we're at bottom of the chat, then simply clear the marker
687
703
if (this.isSticky) {
704
+ console.debug('clearLastReadMessage because of isSticky token=' + this.token)
688
705
this.$store.dispatch('clearLastReadMessage', { token: this.token })
689
706
return
690
707
}
@@ -708,6 +725,7 @@ export default {
708
725
709
726
// we don't update visually here, it will update the next time the
710
727
// user focusses back on the conversation. See refreshReadMarkerPosition().
728
+ console.debug('updateLastReadMessage token=' + this.token + ' messageId=' + messageId)
711
729
this.$store.dispatch('updateLastReadMessage', { token: this.token, id: messageId, updateVisually: false })
712
730
},
713
731
0 commit comments