Regression: Fix scroll to bottom (#21731)

pull/21270/head^2
Guilherme Gazzo 4 years ago committed by GitHub
parent 7f33b8a2d1
commit 47a61f2523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      app/ui/client/views/app/room.js
  2. 16
      client/lib/RoomManager.ts

@ -782,6 +782,10 @@ Meteor.startup(() => {
callbacks.remove('streamNewMessage', this.data._id);
});
const isAtBottom = function(element, scrollThreshold = 0) {
return element.scrollTop + scrollThreshold >= element.scrollHeight - element.clientHeight;
};
Template.roomOld.onRendered(function() {
const { _id: rid } = this.data;
@ -794,7 +798,7 @@ Meteor.startup(() => {
const store = NewRoomManager.getStore(rid);
const afterMessageGroup = () => {
if (store.scroll) {
if (store.scroll && !store.atBottom) {
wrapper.scrollTop = store.scroll;
} else {
this.sendToBottom();
@ -802,8 +806,8 @@ Meteor.startup(() => {
wrapper.removeEventListener('MessageGroup', afterMessageGroup);
wrapper.addEventListener('scroll', _.throttle(() => {
store.update({ scroll: wrapper.scrollTop });
}, 100));
store.update({ scroll: wrapper.scrollTop, atBottom: isAtBottom(wrapper, 50) });
}, 30));
};
wrapper.addEventListener('MessageGroup', afterMessageGroup);
@ -820,7 +824,7 @@ Meteor.startup(() => {
const messageBox = $('.messages-box');
template.isAtBottom = function(scrollThreshold = 0) {
if (wrapper.scrollTop + scrollThreshold >= wrapper.scrollHeight - wrapper.clientHeight) {
if (isAtBottom(wrapper, scrollThreshold)) {
newMessage.className = 'new-message background-primary-action-color color-content-background-color not';
return true;
}
@ -857,7 +861,6 @@ Meteor.startup(() => {
});
Tracker.afterFlush(() => {
template.sendToBottomIfNecessary();
wrapper.addEventListener('scroll', wheelHandler);
});

@ -17,19 +17,33 @@ export class RoomStore extends Emitter<{
scroll?: number;
atBottom = true;
constructor(readonly rid: string) {
super();
debug && this.on('changed', () => console.log(`RoomStore ${this.rid} changed`, this));
}
update({ scroll, lastTime }: { scroll?: number; lastTime?: Date }): void {
update({
scroll,
lastTime,
atBottom,
}: {
scroll?: number;
lastTime?: Date;
atBottom?: boolean;
}): void {
if (scroll !== undefined) {
this.scroll = scroll;
}
if (lastTime !== undefined) {
this.lastTime = lastTime;
}
if (atBottom !== undefined) {
this.atBottom = atBottom;
}
if (scroll || lastTime) {
this.emit('changed');
}

Loading…
Cancel
Save