From 1f56e635b9cccbcd4199af1a2c1eb7ed7cd3dd43 Mon Sep 17 00:00:00 2001 From: n9k Date: Wed, 15 Jun 2022 20:39:02 +0000 Subject: [PATCH] Ensure chat stays at bottom if names/tripcodes change --- anonstream/static/anonstream.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/anonstream/static/anonstream.js b/anonstream/static/anonstream.js index 37de345..2392443 100644 --- a/anonstream/static/anonstream.js +++ b/anonstream/static/anonstream.js @@ -648,6 +648,10 @@ const on_websocket_message = (event) => { default_name = receipt.default; max_chat_scrollback = receipt.scrollback; + // if the chat is scrolled all the way to the bottom, make sure this is + // still the case after updating user names and tripcodes + at_bottom = chat_messages.scrollTop === chat_messages.scrollTopMax; + // update users users = receipt.users; update_user_names(); @@ -655,6 +659,15 @@ const on_websocket_message = (event) => { update_user_tripcodes(); update_users_list() + // ensure chat scroll (see above) + if (at_bottom) { + chat_messages.scrollTo({ + left: 0, + top: chat_messages.scrollTopMax, + behavior: "instant", + }); + } + // appearance form default values const user = users[TOKEN_HASH]; if (user.name !== null) { @@ -739,10 +752,26 @@ const on_websocket_message = (event) => { for (const token_hash of Object.keys(receipt.users)) { users[token_hash] = receipt.users[token_hash]; } + + // if the chat is scrolled all the way to the bottom, make sure this is + // still the case after updating user names and tripcodes + at_bottom = chat_messages.scrollTop === chat_messages.scrollTopMax; + + // update users update_user_names(); update_user_colors(); update_user_tripcodes(); update_users_list() + + // ensure chat scroll (see above) + if (at_bottom) { + chat_messages.scrollTo({ + left: 0, + top: chat_messages.scrollTopMax, + behavior: "instant", + }); + } + break; case "rem-users":