diff --git a/README.md b/README.md index 550f010..d38d611 100644 --- a/README.md +++ b/README.md @@ -39,11 +39,11 @@ regexis024_build_system.sh Помимо самого бинарника нужен файл с настройками сервиса. Формат настроек: JSON. Комментарии не поддерживаются. Пример такого файла находится в example/config.json. Вместе с бинарным фалом так же распространяются ассеты, необходимые для работы сайта. -Их можно найти в папке assets. В настроках (поле `["assets"]`) указывается путь до +Их можно найти в папке assets. В настроках (поле `config.assets`) указывается путь до папки с ассетами. Путь может быть как абсолютным, так и относительным к рабочей директории. -Поле настроек `["database"]` указывает как соединиться с базой данных. +Поле настроек `config.database` указывает как соединиться с базой данных. Поддерживается только база данных sqlite3. Поддерживается только хранение в файле. -Поле `["database"]["file"]` указывает путь где хранится sqlite база данных. +Поле `config.database.file` указывает путь где хранится sqlite база данных. Перед тем как использовать сервис нужно его проинициализировать (а точнее проинициализировать базу данных): @@ -87,7 +87,8 @@ iu9-ca-web-chat-admin-cli [ chatPadding || (highestHighestPoint - lowestLowestPoint) <= H - chatPadding * 2 || - (!isMissingBottomMsgHeap() && bumpedAtBottom)) { + (!isMissingBottomMsgHeap() && bumpedAtBottom)) { offsetOfAnchor += (-lowestLowestPoint + chatPadding); updateOffsetsSane(); @@ -131,6 +133,22 @@ function updateOffsets(){ setElementVisibility(spinnerTop, isMissingTopMsgHeap()); elSetOffsetInChat(spinnerBottom, lowestPoint - SbH); setElementVisibility(spinnerBottom, isMissingBottomMsgHeap()); + /* Fix anchor */ + let oldAnchor = anchoredMsg; + while (true){ + let h = visibleMessages.get(anchoredMsg).container.offsetHeight; + if (!(offsetOfAnchor + h < chatPadding && visibleMsgSegStart < anchoredMsg)) + break + offsetOfAnchor += (msgGap + h); + anchoredMsg--; + } + while (offsetOfAnchor > H - chatPadding && anchoredMsg < visibleMsgSegEnd){ + anchoredMsg++; + let h = visibleMessages.get(anchoredMsg).container.offsetHeight; + offsetOfAnchor -= (msgGap + h); + } + if (oldAnchor !== anchoredMsg) + console.log("anchoredMsg: " + String(oldAnchor) + " -> " + String(anchoredMsg)) } } @@ -256,7 +274,7 @@ function convertMessageStToSupercontainer(messageSt){ } else msgPart.innerText = msgErased; - return {'container': container, 'box': box, 'offset': 0}; + return {'container': container, 'box': box}; } function makeVisible(msgId){ @@ -303,7 +321,6 @@ function canISendMessages(){ } function updateLocalStateFromChatUpdRespBlind(chatUpdResp){ - console.log(anchoredMsg, offsetOfAnchor, chatUpdResp); LocalHistoryId = chatUpdResp.HistoryId; for (let memberSt of chatUpdResp.members){ let id = memberSt.userId; @@ -343,7 +360,6 @@ function needToLoadWhitespace(){ } async function tryLoadWhitespaceSingle(){ - console.log('tryLoadWhitespaceSingle'); if (isMissingPrimaryMsgHeap()){ await requestMessageNeighbours(-1, "backward"); } else if (isMissingTopMsgHeap()){ @@ -359,7 +375,8 @@ async function loadWhitespaceMultitry(){ do { try { await tryLoadWhitespaceSingle(); - await sleep(1100); + if (debugMode) + await sleep(900); } catch (e) { console.error(e); await sleep(1500); @@ -427,7 +444,6 @@ window.onload = function (){ if (event.ctrlKey && event.key === 'Enter'){ let textarea = document.getElementById("message-input"); let text = String(textarea.innerText); - console.log(text); textarea.innerText = ""; let Sent = genSentBase(); Sent.content = {}; @@ -446,8 +462,10 @@ window.onload = function (){ elSetOffsetInChat(document.getElementById("debug-line-top-padding"), H - chatPadding); elSetOffsetInChat(document.getElementById("debug-line-bottom-padding"), chatPadding) }; - window.addEventListener("resize", chatWgDebugLinesFnc); - chatWgDebugLinesFnc(); + if (debugMode){ + window.addEventListener("resize", chatWgDebugLinesFnc); + chatWgDebugLinesFnc(); + } configureMsgDeletionPopupButtons(); diff --git a/assets/js/common.js b/assets/js/common.js index 16fb935..637b0b6 100644 --- a/assets/js/common.js +++ b/assets/js/common.js @@ -18,13 +18,20 @@ let __mainloopDelayMs = 3000; let mainloopTimeout = null; let __guestMainloopPollerAction = null; function setMainloopTimeout(){ + if (mainloopTimeout !== null) + return; mainloopTimeout = setTimeout(mainloopPoller, __mainloopDelayMs); } function cancelMainloopTimeout(){ + if (mainloopTimeout === null){ + console.log("cancelling nothing") + return; + } clearTimeout(mainloopTimeout); mainloopTimeout = null; } function mainloopPoller(){ + mainloopTimeout = null; try { if (__guestMainloopPollerAction) __guestMainloopPollerAction(); diff --git a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_deletemessage.cpp b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_deletemessage.cpp index 507a7c5..1aaf62e 100644 --- a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_deletemessage.cpp +++ b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_deletemessage.cpp @@ -4,7 +4,6 @@ namespace iu9cawebchat { json::JSON internalapi_deleteMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) { - // debug_print_json(Sent); int64_t chatId = Sent["chatUpdReq"]["chatId"].asInteger().get_int(); int64_t my_role_here = get_role_of_user_in_chat(conn, uid, chatId); if (my_role_here == user_chat_role_deleted) diff --git a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_sendmessage.cpp b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_sendmessage.cpp index 63c0902..59246c6 100644 --- a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_sendmessage.cpp +++ b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/api_sendmessage.cpp @@ -31,7 +31,6 @@ namespace iu9cawebchat { } json::JSON internalapi_sendMessage(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) { - debug_print_json(Sent); int64_t chatId = Sent["chatUpdReq"]["chatId"].asInteger().get_int(); int64_t my_role_here = get_role_of_user_in_chat(conn, uid, chatId); if (my_role_here == user_chat_role_deleted) @@ -46,7 +45,6 @@ namespace iu9cawebchat { json::JSON Recv; poll_update_chat(conn, Sent, Recv); - debug_print_json(Recv); return Recv; } } diff --git a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/polling.cpp b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/polling.cpp index 861c747..9fff9fb 100644 --- a/src/web_chat/iu9_ca_web_chat_lib/backend_logic/polling.cpp +++ b/src/web_chat/iu9_ca_web_chat_lib/backend_logic/polling.cpp @@ -166,7 +166,6 @@ namespace iu9cawebchat { /* Reznya */ json::JSON internalapi_getMessageNeighbours(SqliteConnection& conn, int64_t uid, const json::JSON& Sent) { - debug_print_json(Sent); int64_t chatId = Sent["chatUpdReq"]["chatId"].asInteger().get_int(); if (get_role_of_user_in_chat(conn, uid, chatId) == user_chat_role_deleted) een9_THROW("Authentication failure"); @@ -194,7 +193,6 @@ namespace iu9cawebchat { } } poll_update_chat_important_segment(conn, Sent, Recv, qBeg, qEnd); - debug_print_json(Recv); return Recv; } } diff --git a/src/web_chat/iu9_ca_web_chat_service/service.cpp b/src/web_chat/iu9_ca_web_chat_service/service.cpp index fea961a..6374748 100644 --- a/src/web_chat/iu9_ca_web_chat_service/service.cpp +++ b/src/web_chat/iu9_ca_web_chat_service/service.cpp @@ -34,6 +34,8 @@ int main(int argc, char** argv){ iu9cawebchat::initialize_website(config, root_pw); } else if (cmd == "run") { iu9cawebchat::run_website(config); + } else if (cmd == "version") { + printf("IU9 Collarbone Annihilation Web Chat (service) V 1.0\n"); } else een9_THROW("unknown action (known are 'run', 'initialize')"); } catch (std::exception& e) {