@@ -1027,19 +1027,58 @@ export default defineComponent({
1027
1027
this .scrollToBottom ();
1028
1028
}, 150 );
1029
1029
},
1030
- scrollToBottom () {
1030
+ /**
1031
+ * This method does a couple of things:
1032
+ * - first round:
1033
+ * - tries to scroll down
1034
+ * - in the next tick it triggers it again
1035
+ * (during testing it seemed that the first trigger still had some space left to scroll)
1036
+ * - 2nd round:
1037
+ * - tries to scroll down
1038
+ * - in the next tick it checks if the scrollTop is to most it can scroll down,
1039
+ * if it is, it stops from doing that again
1040
+ * if not, it goes into the next round
1041
+ * - if we reach round 6 it stops completely,
1042
+ * no need to have a endless loop of just scrolling down
1043
+ */
1044
+ scrollToBottom (callCount = 0 ) {
1045
+ if (callCount > 5 ) {
1046
+ return ;
1047
+ }
1048
+
1031
1049
if (! this .$refs .chatscroll ) {
1050
+ // if the message list component not loaded yet, but scrollToBottom was called
1051
+ // just try again at a later time
1052
+ setTimeout (() => {
1053
+ this .scrollToBottom (callCount + 1 );
1054
+ }, 125 );
1032
1055
return ;
1033
1056
}
1034
- const chatscrollBeforeTick = this .$refs .chatscroll .$el ;
1035
- chatscrollBeforeTick .scrollTop = chatscrollBeforeTick .scrollHeight ;
1057
+
1058
+ const chatscrollEl = this .$refs .chatscroll .$el ;
1059
+ // chatscrollBeforeTick.scrollTop = chatscrollBeforeTick.scrollHeight;
1060
+ chatscrollEl .scrollTo (0 , chatscrollEl .scrollHeight );
1036
1061
1037
1062
Vue .nextTick (() => {
1038
1063
if (! this .$refs .chatscroll ) {
1039
1064
return ;
1040
1065
}
1041
- const chatscroll = this .$refs .chatscroll .$el ;
1042
- chatscroll .scrollTop = chatscroll .scrollHeight ;
1066
+
1067
+ let shouldRetrigger = true ;
1068
+
1069
+ if (callCount > 1 ) {
1070
+ const maxPossibleScrollPos = chatscrollEl .scrollHeight - chatscrollEl .clientHeight ;
1071
+
1072
+ if (chatscrollEl .scrollTop === maxPossibleScrollPos) {
1073
+ shouldRetrigger = false ;
1074
+ }
1075
+ }
1076
+
1077
+ if (shouldRetrigger) {
1078
+ setTimeout (() => {
1079
+ this .scrollToBottom (callCount + 1 );
1080
+ }, 125 );
1081
+ }
1043
1082
});
1044
1083
},
1045
1084
infiniteScrollTrigger () {
0 commit comments