diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index 427fb48..bdad62b 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -58,11 +58,12 @@ class Channel extends SnowFlake { set lastreadmessageid(id: string | undefined) { const cur = this.lastreadmessageidint; this.lastreadmessageidint = id; - const m = this.messages.get(this.idToPrev.get(cur as string) as string); + const m = this.messages.get(this.idToNext.get(cur as string) as string); if (m) { + console.log(m); m.generateMessage(); } - const m2 = this.messages.get(this.idToPrev.get(id as string) as string); + const m2 = this.messages.get(this.idToNext.get(id as string) as string); if (m2) { m2.generateMessage(); } @@ -1268,6 +1269,7 @@ class Channel extends SnowFlake { if (next) { next.generateMessage(); } + this.infinite.toBottom(); } static lastDragDiv = document.createElement("div"); coatDropDiv(div: HTMLDivElement, container: HTMLElement | false = false) { diff --git a/src/webpage/infiniteScroller.ts b/src/webpage/infiniteScroller.ts index c51703f..86eee42 100644 --- a/src/webpage/infiniteScroller.ts +++ b/src/webpage/infiniteScroller.ts @@ -128,7 +128,7 @@ class InfiniteScroller { const nh = elm.target.getBoundingClientRect().height; const height = heights.get(elm.target); if (height && nh) { - root.scrollTop -= height - nh; + if (!this.atBottom()) root.scrollTop -= height - nh; } heights.set(elm.target, nh); } @@ -233,12 +233,15 @@ class InfiniteScroller { if (this.backElm.get(last) || !this.backElm.has(last)) return false; return this.scrollBottom < 4; } + toBottom() { + if (this.div) this.div.scrollTop = this.div.scrollHeight; + } snapBottom(): () => void { if (this.div && this.atBottom()) { const trigger = this.scrollBottom < 4; return () => { - if (this.div && trigger) this.div.scrollTop = this.div.scrollHeight; + if (this.div && trigger) this.toBottom; }; } else { return () => {};