From 6813c6249d9e9c28277bf7d71b94731323a34972 Mon Sep 17 00:00:00 2001 From: Andreev Gregory Date: Sat, 7 Sep 2024 10:48:15 +0300 Subject: [PATCH] Added cumping to chat widget --- README.md | 4 ++++ assets/css/chat.css | 3 ++- assets/js/chat.js | 28 ++++++++++++++++++---------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 395552e..550f010 100644 --- a/README.md +++ b/README.md @@ -76,13 +76,17 @@ iu9-ca-web-chat-admin-cli [ ` - зарегистрировать пользователя сайта +`8` - остановить сервис + Если нужно ввести пробел или символ `\ ` в любое из этих полей, перед ними нужно поставить `\ `; +Если указать меньше полей, чем нужно, незаполненные поля станут пустыми строками. Параметры конфигурации `config.lang.whitelist` и `config.lang.force-order` определяют на какие языки будет локализован сервер, и какие переводы приоритетнее каких. На данный момент поддерживаются - `ru-RU` - `en-US` + Все переводы хранятся в папке `assets/lang`. # Список участников diff --git a/assets/css/chat.css b/assets/css/chat.css index 448e434..3317915 100644 --- a/assets/css/chat.css +++ b/assets/css/chat.css @@ -13,7 +13,8 @@ body, html { position: absolute; width: 100%; left: 0; - background-color: rgba(150, 0, 100, 50); + /*background-color: rgba(150, 0, 100, 50);*/ + background-color: rgba(0, 0, 0, 0); /*display: flex;*/ /*flex-direction: row;*/ /*justify-content: center;*/ diff --git a/assets/js/chat.js b/assets/js/chat.js index 4db63de..249fcb5 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -18,7 +18,7 @@ let lastMsgId = -1; let myRoleHere = null; // Dung local state updates should be updated first // Would start with true if opened `/chat/<>` -let bumpedAtTheBottom = false; +let bumpedAtBottom = false; // Hidden variable. When deletion window popup is active // Persists from popup activation until popup deactivation @@ -27,6 +27,7 @@ let storeHiddenMsgIdForDeletionWin = -1; // Positive in production, negative for debug let softZoneSz = -150; let chatPadding = 300; +let msgGap = 5; const msgErased = pres.chat.msgErased; function genSentBase(){ @@ -75,16 +76,16 @@ function updateOffsetsUpToTop(){ for (let curMsg = anchoredMsg; curMsg >= visibleMsgSegStart; curMsg--){ updateOffsetOfVisibleMsg(curMsg, offset); let height = visibleMessages.get(curMsg).container.offsetHeight; - offset += height + 5; + offset += height + msgGap; } - return offset; + return offset - msgGap; } function updateOffsetsDown(){ let offset = offsetOfAnchor; for (let curMsg = anchoredMsg + 1; curMsg <= visibleMsgSegEnd; curMsg++){ let height = visibleMessages.get(curMsg).container.offsetHeight; - offset -= (height + 5); + offset -= (height + msgGap); updateOffsetOfVisibleMsg(curMsg, offset); } return offset; @@ -115,8 +116,9 @@ function updateOffsets(){ let [W, H] = getChatWgSz(); let lowestLowestPoint = isMissingBottomMsgHeap() ? lowestPoint - heightOfPreloadGhost(): lowestPoint; let highestHighestPoint = isMissingTopMsgHeap() ? highestPoint + heightOfPreloadGhost() : highestPoint; - if (lowestLowestPoint > chatPadding || (highestHighestPoint - lowestLowestPoint) <= H - chatPadding * 2) { - bumpedAtTheBottom = true; + if (lowestLowestPoint > chatPadding || (highestHighestPoint - lowestLowestPoint) <= H - chatPadding * 2 || + (!isMissingBottomMsgHeap() && bumpedAtBottom)) { + offsetOfAnchor += (-lowestLowestPoint + chatPadding); updateOffsetsSane(); } else if (highestHighestPoint < H - chatPadding) { @@ -357,7 +359,7 @@ async function loadWhitespaceMultitry(){ do { try { await tryLoadWhitespaceSingle(); - await sleep(100); + await sleep(1100); } catch (e) { console.error(e); await sleep(1500); @@ -410,9 +412,13 @@ window.onload = function (){ console.log("Page was loaded"); document.body.addEventListener("wheel", function (event) { - // event.preventDefault(); - bumpedAtTheBottom = false; - offsetOfAnchor += event.deltaY / 3; + let offset = event.deltaY / 3; + if (offset < 0){ + bumpedAtBottom = false; + } else if (offset > 0 && !isMissingBottomMsgHeap() && lowestPoint + offset > chatPadding){ + bumpedAtBottom = true; + } + offsetOfAnchor += offset; updateOffsets(); loadWhitespaceMultitry().then(dopDopYesYes); }); @@ -430,6 +436,8 @@ window.onload = function (){ } }); + bumpedAtBottom = (openedchat.selectedMessageId < 0); + let chatWg = document.getElementById("chat-widget"); let chatWgDebugLinesFnc = function (){ let H = chatWg.offsetHeight;