diff options
-rw-r--r-- | src/main.ts | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/main.ts b/src/main.ts index bc300c2..3317fb2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -107,7 +107,7 @@ function delete_message(id: number) { old_msg.deleted = true; messages.set(id, old_msg); - chatwindow(null).then(); + chatwindow(); } else { throw new Error("Could not find message") } @@ -191,7 +191,7 @@ function get_newest_cache_id() { } } -function get_newest_messages() { +function get_newest_messages(): void { xhttp_request("get_message_id_newest").then(async (newest_id) => { let new_messages: HTMLSpanElement = getelementbyid("new_messages") let newest_cache_id = get_newest_cache_id(); @@ -227,7 +227,6 @@ function get_newest_messages() { let oldest = newest_id - 25; let newest = delta; - let list = await get_message_list(oldest, newest); for (let x of list.values()) { final_array.push(x) @@ -253,11 +252,12 @@ function get_newest_messages() { } if (initial) { - chatwindow(newest_id).then() + chatwindow(newest_id) initial = false } else { + console.log("new messages") + chatwindow() new_messages.style.display = "unset" - chatwindow().then() } }); } @@ -351,6 +351,7 @@ function to_dom(x: string): Node { async function chatwindow(hash: any = undefined, hl = false) { let window: HTMLDivElement = getelementbyid("chatwindow"); let pre_scroll = window.scrollHeight - window.clientHeight; + let scrolltop = window.scrollTop; window.innerHTML = ""; let array: Message[] = []; @@ -365,6 +366,7 @@ async function chatwindow(hash: any = undefined, hl = false) { } ); + console.log("before") let old_date = new Date(0); let latest_v; for (let v of array) { @@ -378,25 +380,25 @@ async function chatwindow(hash: any = undefined, hl = false) { if (v.reply_to != undefined) { let r = await get_message(v.reply_to); if (r != undefined) { - let reply = await format_reply(r).then(); + let reply = await format_reply(r); window.append(to_dom(reply)) } } - let data = await format_message(v).then() + let data = await format_message(v); let dom: Node = to_dom(data); window.appendChild(dom); } - - if (hash == null) { - return - } - if (window.scrollTop == pre_scroll) { + // if (hash == null) { + // console.log(hash) + // return + // } + + if (scrolltop == pre_scroll) { if (latest_v != undefined && hash == undefined) { getelementbyid(latest_v.id).scrollIntoView(); - // highlight(latest_v.id); } } |