From de342c6af83ef4389a5bd4fbda370bb5628882f6 Mon Sep 17 00:00:00 2001 From: acetone Date: Thu, 30 Dec 2021 01:15:08 -0500 Subject: [PATCH] ... --- html/realtimechat.js | 23 +++++++++++++++++------ html/style.css | 8 +++++++- httpserver.cpp | 3 +-- httpserver.h | 2 +- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/html/realtimechat.js b/html/realtimechat.js index 9e204a1..2c09a40 100644 --- a/html/realtimechat.js +++ b/html/realtimechat.js @@ -10,6 +10,7 @@ const HTML_SERVER_OFFLINE_MARKER = "❌"; let ajaxUrl = document.getElementById("ajaxPath").innerText; let lastMessageId = document.getElementById("LMId").innerText; let reqIsFailed = false; +let firstLoadingWithDisconnectedServer = false; function appendMessage(nick /* if == "***", then system message */, message) { @@ -51,14 +52,19 @@ function changeOnlineList(nicksArray) function toAJAX() { + loop(); let xhttp = new XMLHttpRequest(); xhttp.onload = function() { if (reqIsFailed) { reqIsFailed = false; objPath.removeAttribute("style"); } - const answer = JSON.parse(xhttp.responseText); + if (firstLoadingWithDisconnectedServer && answer.serverStatus) { + firstLoadingWithDisconnectedServer = false; + appendMessage("***", "Connected to the server. New messages will appear below!"); + objPath.removeAttribute("style"); + } if (!answer.status) { appendMessage("***", answer.message); return; @@ -84,16 +90,14 @@ function toAJAX() appendMessage(singleMsg.user, singleMsg.text); }); } - loop(); - setTimeout(loop, 2000); // 2 sec + setTimeout(toAJAX, 2000); // 2 sec } xhttp.onerror = function() { if (!reqIsFailed) { reqIsFailed = true; objPath.setAttribute("style", "color: red"); } - loop(); - setTimeout(loop, 1000); // 1 sec + setTimeout(toAJAX, 1000); // 1 sec } let currentServerStatus = objCurrentServerStatus.innerText === HTML_SERVER_ONLINE_MARKER; @@ -116,7 +120,14 @@ function main() { objPayload.scrollBy(0,100000); let objHr = document.getElementById("hr"); - hr.innerHTML = "New messages will appear below"; + if (objCurrentServerStatus.innerText === HTML_SERVER_OFFLINE_MARKER) { + firstLoadingWithDisconnectedServer = true; + objPath.setAttribute("style", "color: red"); + hr.innerHTML = "Now the logger is disconnected from the server, so there will be no new messages."; + } else { + hr.innerHTML = "New messages will appear below"; + } + toAJAX(); } diff --git a/html/style.css b/html/style.css index aa462f1..6d0c37a 100644 --- a/html/style.css +++ b/html/style.css @@ -102,9 +102,15 @@ body { .main_header__title_airplaine { background: url(/svg/airplane.svg); background-repeat: no-repeat; - width: 4%; + width: 6%; height: 50%; border: none; + align-items: center; +} + +.main_header__title_airplaine:hover { + width: 15%; + height: 60%; } .main_header__search { diff --git a/httpserver.cpp b/httpserver.cpp index 738dba2..cac6466 100644 --- a/httpserver.cpp +++ b/httpserver.cpp @@ -1210,8 +1210,7 @@ void HttpServer::writeRealTimeChatPage(QTcpSocket *socket, QString &urlPath, boo QString channelNameForUrl {c.first}; channelNameForUrl.remove('#'); - QString channelLink = "/" + global::toLowerAndNoSpaces(s.first) + - "/" + channelNameForUrl + "/" + year + "/" + month + "/" + day; + QString channelLink = "/realtime/" + global::toLowerAndNoSpaces(s.first) + "/" + channelNameForUrl; replaceTag(htmlChannelLine, "CHANNEL_LINK", channelLink); htmlChannelLineS += htmlChannelLine; diff --git a/httpserver.h b/httpserver.h index ced3780..05b2761 100644 --- a/httpserver.h +++ b/httpserver.h @@ -9,7 +9,7 @@ #include constexpr int MSECS_TO_AUTOREMOVE_MESSAGES_FROM_BUFFER {10000}; // 10 secs -const QString HTTP_ACTUAL_ETAG {"2021-12-29"}; // Change it if svg, css or ico was modified +const QString HTTP_ACTUAL_ETAG {"2021-12-30"}; // Change it if svg, css or ico was modified class Message : public QObject {