master
const an teen 2021-12-30 01:15:08 -05:00
parent fc34809733
commit de342c6af8
4 changed files with 26 additions and 10 deletions

View File

@ -10,6 +10,7 @@ const HTML_SERVER_OFFLINE_MARKER = "❌";
let ajaxUrl = document.getElementById("ajaxPath").innerText; let ajaxUrl = document.getElementById("ajaxPath").innerText;
let lastMessageId = document.getElementById("LMId").innerText; let lastMessageId = document.getElementById("LMId").innerText;
let reqIsFailed = false; let reqIsFailed = false;
let firstLoadingWithDisconnectedServer = false;
function appendMessage(nick /* if == "***", then system message */, message) function appendMessage(nick /* if == "***", then system message */, message)
{ {
@ -51,14 +52,19 @@ function changeOnlineList(nicksArray)
function toAJAX() function toAJAX()
{ {
loop();
let xhttp = new XMLHttpRequest(); let xhttp = new XMLHttpRequest();
xhttp.onload = function() { xhttp.onload = function() {
if (reqIsFailed) { if (reqIsFailed) {
reqIsFailed = false; reqIsFailed = false;
objPath.removeAttribute("style"); objPath.removeAttribute("style");
} }
const answer = JSON.parse(xhttp.responseText); const answer = JSON.parse(xhttp.responseText);
if (firstLoadingWithDisconnectedServer && answer.serverStatus) {
firstLoadingWithDisconnectedServer = false;
appendMessage("***", "<b>Connected to the server</b>. New messages will appear below!");
objPath.removeAttribute("style");
}
if (!answer.status) { if (!answer.status) {
appendMessage("***", answer.message); appendMessage("***", answer.message);
return; return;
@ -84,16 +90,14 @@ function toAJAX()
appendMessage(singleMsg.user, singleMsg.text); appendMessage(singleMsg.user, singleMsg.text);
}); });
} }
loop(); setTimeout(toAJAX, 2000); // 2 sec
setTimeout(loop, 2000); // 2 sec
} }
xhttp.onerror = function() { xhttp.onerror = function() {
if (!reqIsFailed) { if (!reqIsFailed) {
reqIsFailed = true; reqIsFailed = true;
objPath.setAttribute("style", "color: red"); objPath.setAttribute("style", "color: red");
} }
loop(); setTimeout(toAJAX, 1000); // 1 sec
setTimeout(loop, 1000); // 1 sec
} }
let currentServerStatus = objCurrentServerStatus.innerText === HTML_SERVER_ONLINE_MARKER; let currentServerStatus = objCurrentServerStatus.innerText === HTML_SERVER_ONLINE_MARKER;
@ -116,7 +120,14 @@ function main()
{ {
objPayload.scrollBy(0,100000); objPayload.scrollBy(0,100000);
let objHr = document.getElementById("hr"); let objHr = document.getElementById("hr");
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 = "<b>New messages will appear below<b>"; hr.innerHTML = "<b>New messages will appear below<b>";
}
toAJAX(); toAJAX();
} }

View File

@ -102,9 +102,15 @@ body {
.main_header__title_airplaine { .main_header__title_airplaine {
background: url(/svg/airplane.svg); background: url(/svg/airplane.svg);
background-repeat: no-repeat; background-repeat: no-repeat;
width: 4%; width: 6%;
height: 50%; height: 50%;
border: none; border: none;
align-items: center;
}
.main_header__title_airplaine:hover {
width: 15%;
height: 60%;
} }
.main_header__search { .main_header__search {

View File

@ -1210,8 +1210,7 @@ void HttpServer::writeRealTimeChatPage(QTcpSocket *socket, QString &urlPath, boo
QString channelNameForUrl {c.first}; QString channelNameForUrl {c.first};
channelNameForUrl.remove('#'); channelNameForUrl.remove('#');
QString channelLink = "/" + global::toLowerAndNoSpaces(s.first) + QString channelLink = "/realtime/" + global::toLowerAndNoSpaces(s.first) + "/" + channelNameForUrl;
"/" + channelNameForUrl + "/" + year + "/" + month + "/" + day;
replaceTag(htmlChannelLine, "CHANNEL_LINK", channelLink); replaceTag(htmlChannelLine, "CHANNEL_LINK", channelLink);
htmlChannelLineS += htmlChannelLine; htmlChannelLineS += htmlChannelLine;

View File

@ -9,7 +9,7 @@
#include <queue> #include <queue>
constexpr int MSECS_TO_AUTOREMOVE_MESSAGES_FROM_BUFFER {10000}; // 10 secs 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 class Message : public QObject
{ {