fix snapping to new messages

This commit is contained in:
MathMan05 2024-09-09 11:24:02 -05:00
parent 7dd6082f24
commit 7cf4e40a5f
3 changed files with 22 additions and 28 deletions

View file

@ -89,7 +89,6 @@ class InfiniteScroller {
this.div.appendChild(html);
this.HTMLElements.push([html, id]);
}
currrunning = false;
async addedBottom() {
await this.updatestuff();
const func = this.snapBottom();
@ -98,9 +97,11 @@ class InfiniteScroller {
}
snapBottom() {
const scrollBottom = this.scrollBottom;
console.log(scrollBottom);
return () => {
if (this.div && scrollBottom < 4) {
this.div.scrollTop = this.div.scrollHeight + 20;
console.log("snap");
this.div.scrollTop = this.div.scrollHeight;
}
};
}
@ -154,6 +155,9 @@ class InfiniteScroller {
}
}
async watchForBottom(already = false, fragement = new DocumentFragment()) {
let func;
if (!already)
func = this.snapBottom();
if (!this.div)
return false;
try {
@ -192,8 +196,8 @@ class InfiniteScroller {
finally {
if (!already) {
this.div.append(fragement);
if (this.scrollBottom < 30) {
this.div.scrollTop = this.div.scrollHeight;
if (func) {
func();
}
}
}
@ -201,18 +205,12 @@ class InfiniteScroller {
watchtime = false;
changePromise;
async watchForChange() {
if (this.currrunning) {
if (this.changePromise) {
this.watchtime = true;
if (this.changePromise) {
return await this.changePromise;
}
else {
return false;
}
return await this.changePromise;
}
else {
this.watchtime = false;
this.currrunning = true;
}
this.changePromise = new Promise(async (res) => {
try {
@ -226,7 +224,7 @@ class InfiniteScroller {
if (this.timeout === null && changed) {
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
}
if (!this.currrunning) {
if (!this.changePromise) {
console.error("something really bad happened");
}
res(Boolean(changed));
@ -244,7 +242,6 @@ class InfiniteScroller {
finally {
setTimeout(_ => {
this.changePromise = undefined;
this.currrunning = false;
if (this.watchtime) {
this.watchForChange();
}

View file

@ -1099,7 +1099,7 @@ class Channel extends SnowFlake{
if(!this.infinitefocus){
this.tryfocusinfinate();
}
this.infinite.addedBottom();
this.infinite.addedBottom()
}
if(messagez.author===this.localuser.user){
return;

View file

@ -90,7 +90,6 @@ class InfiniteScroller{
this.div.appendChild(html);
this.HTMLElements.push([html,id]);
}
currrunning:boolean=false;
async addedBottom(){
await this.updatestuff();
const func=this.snapBottom();
@ -99,9 +98,11 @@ class InfiniteScroller{
}
snapBottom(){
const scrollBottom=this.scrollBottom;
console.log(scrollBottom);
return()=>{
if(this.div&&scrollBottom<4){
this.div.scrollTop=this.div.scrollHeight+20;
console.log("snap");
this.div.scrollTop=this.div.scrollHeight;
}
};
}
@ -155,6 +156,8 @@ class InfiniteScroller{
}
}
async watchForBottom(already=false,fragement=new DocumentFragment()):Promise<boolean>{
let func:Function|undefined;
if(!already) func=this.snapBottom();
if(!this.div)return false;
try{
let again=false;
@ -190,8 +193,8 @@ class InfiniteScroller{
}finally{
if(!already){
this.div.append(fragement);
if(this.scrollBottom<30){
this.div.scrollTop=this.div.scrollHeight;
if(func){
func();
}
}
}
@ -199,16 +202,11 @@ class InfiniteScroller{
watchtime:boolean=false;
changePromise:Promise<boolean>|undefined;
async watchForChange():Promise<boolean>{
if(this.currrunning){
if(this.changePromise){
this.watchtime=true;
if(this.changePromise){
return await this.changePromise;
}else{
return false;
}
return await this.changePromise;
}else{
this.watchtime=false;
this.currrunning=true;
}
this.changePromise=new Promise<boolean>(async res=>{
try{
@ -221,7 +219,7 @@ class InfiniteScroller{
if(this.timeout===null&&changed){
this.timeout=setTimeout(this.updatestuff.bind(this),300);
}
if(!this.currrunning){
if(!this.changePromise){
console.error("something really bad happened");
}
@ -237,7 +235,6 @@ class InfiniteScroller{
}finally{
setTimeout(_=>{
this.changePromise=undefined;
this.currrunning=false;
if(this.watchtime){
this.watchForChange();
}