@@ -782,6 +782,10 @@ Meteor.startup(() => {
782782 callbacks . remove ( 'streamNewMessage' , this . data . _id ) ;
783783 } ) ;
784784
785+ const isAtBottom = function ( element , scrollThreshold = 0 ) {
786+ return element . scrollTop + scrollThreshold >= element . scrollHeight - element . clientHeight ;
787+ } ;
788+
785789 Template . roomOld . onRendered ( function ( ) {
786790 const { _id : rid } = this . data ;
787791
@@ -794,16 +798,16 @@ Meteor.startup(() => {
794798 const store = NewRoomManager . getStore ( rid ) ;
795799
796800 const afterMessageGroup = ( ) => {
797- if ( store . scroll ) {
801+ if ( store . scroll && ! store . atBottom ) {
798802 wrapper . scrollTop = store . scroll ;
799803 } else {
800804 this . sendToBottom ( ) ;
801805 }
802806 wrapper . removeEventListener ( 'MessageGroup' , afterMessageGroup ) ;
803807
804808 wrapper . addEventListener ( 'scroll' , _ . throttle ( ( ) => {
805- store . update ( { scroll : wrapper . scrollTop } ) ;
806- } , 100 ) ) ;
809+ store . update ( { scroll : wrapper . scrollTop , atBottom : isAtBottom ( wrapper , 50 ) } ) ;
810+ } , 30 ) ) ;
807811 } ;
808812
809813 wrapper . addEventListener ( 'MessageGroup' , afterMessageGroup ) ;
@@ -820,7 +824,7 @@ Meteor.startup(() => {
820824 const messageBox = $ ( '.messages-box' ) ;
821825
822826 template . isAtBottom = function ( scrollThreshold = 0 ) {
823- if ( wrapper . scrollTop + scrollThreshold >= wrapper . scrollHeight - wrapper . clientHeight ) {
827+ if ( isAtBottom ( wrapper , scrollThreshold ) ) {
824828 newMessage . className = 'new-message background-primary-action-color color-content-background-color not' ;
825829 return true ;
826830 }
@@ -857,7 +861,6 @@ Meteor.startup(() => {
857861 } ) ;
858862
859863 Tracker . afterFlush ( ( ) => {
860- template . sendToBottomIfNecessary ( ) ;
861864 wrapper . addEventListener ( 'scroll' , wheelHandler ) ;
862865 } ) ;
863866
0 commit comments