way to 2.1.0

master
const an teen 2021-12-29 13:34:08 -05:00
parent f35847d1c7
commit 308cadd9b0
7 changed files with 52 additions and 14 deletions

View File

@ -9,8 +9,9 @@ const HTML_SERVER_OFFLINE_MARKER = "❌";
let ajaxUrl = document.getElementById("ajaxPath").innerText;
let lastMessageId = document.getElementById("LMId").innerText;
let reqIsFailed = false;
function appendMessage(nick /* if == "***", then error */, message)
function appendMessage(nick /* if == "***", then system message */, message)
{
let messageObject = document.createElement("div");
messageObject.setAttribute("class", "main_payload__chat");
@ -52,6 +53,11 @@ function toAJAX()
{
let xhttp = new XMLHttpRequest();
xhttp.onload = function() {
if (reqIsFailed) {
reqIsFailed = false;
appendMessage("", "<b style=\"color: green\">Fine: you are online again</b>")
}
const answer = JSON.parse(xhttp.responseText);
if (!answer.status) {
appendMessage("***", answer.message);
@ -72,8 +78,6 @@ function toAJAX()
changeOnlineList(onlineInfo.list);
}
if (answer.LMIdChanged) {
console.log("old", lastMessageId);
console.log("new", answer.LMId);
lastMessageId = answer.LMId;
let msgArray = answer.newMessages;
msgArray.forEach(function(singleMsg) {
@ -81,6 +85,13 @@ function toAJAX()
});
}
}
xhttp.onerror = function() {
if (!reqIsFailed) {
reqIsFailed = true;
appendMessage("", "<b style=\"color: red\">Request is failed: no response from server</b>")
}
}
let currentServerStatus = objCurrentServerStatus.innerText === HTML_SERVER_ONLINE_MARKER;
xhttp.open("GET", "/ajax/"+ajaxUrl+"?onlineCounter="+objOnlineCounter.innerText+"&messageId="+lastMessageId+"&serverStatus="+currentServerStatus);
xhttp.send();

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<style type="text/css">
.st0{fill:#6493BC;}
</style>
<polygon class="st0" points="161.3,287.2 161.3,445 288.4,350.3 415.5,508.1 510.8,3.2 2.4,255.7 "/>
</svg>

After

Width:  |  Height:  |  Size: 422 B

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<style type="text/css">

Before

Width:  |  Height:  |  Size: 915 B

After

Width:  |  Height:  |  Size: 819 B

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Glyph" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="32px" height="32px" viewBox="0 0 32 32" style="enable-background:new 0 0 32 32;" xml:space="preserve">
<style type="text/css">

Before

Width:  |  Height:  |  Size: 706 B

After

Width:  |  Height:  |  Size: 610 B

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Слой_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="48px" height="48px" viewBox="0 0 48 48" style="enable-background:new 0 0 48 48;" xml:space="preserve">
<style type="text/css">

Before

Width:  |  Height:  |  Size: 765 B

After

Width:  |  Height:  |  Size: 669 B

View File

@ -142,7 +142,7 @@ std::pair<QString, QString> HttpServer::splitUserNameAndMessage(const QString &r
void HttpServer::consoleLog(const QString &message)
{
qInfo().noquote() << "[WEBINTERFACE]" << message;
qInfo().noquote() << "[WEB_UI]" << message;
}
void HttpServer::debugLog(const QString &req)
@ -357,7 +357,17 @@ void HttpServer::ircMessageCache(QString server, QString channel, QString nick,
{
QString channelId {server+channel};
if (not m_messageCache.contains(channelId)) return;
else m_messageCache[channelId]->saveNewMessage(nick, text);
// remove timed out session
if (QDateTime::currentMSecsSinceEpoch() - MSECS_TO_AUTOREMOVE_MESSAGES_FROM_BUFFER >
m_messageCache[channelId]->getLastPing())
{
consoleLog("Message caching disabled for "+server+"/#"+channel+". No active reader.");
m_messageCache.remove(channelId);
return;
}
else {
m_messageCache[channelId]->saveNewMessage(nick, text);
}
}
QString HttpServer::getRequestPath(const QString &req)
@ -1173,6 +1183,10 @@ void HttpServer::writeRealTimeChatPage(QTcpSocket *socket, QString &urlPath, boo
}
}
QString year {QDateTime::currentDateTime().toString("yyyy")};
QString month {QDateTime::currentDateTime().toString("MM")};
QString day {QDateTime::currentDateTime().toString("dd")};
//// Left menu compilation
QString htmlServersSectionS;
for (const auto &s: m_onlineUsers) {
@ -1197,7 +1211,8 @@ void HttpServer::writeRealTimeChatPage(QTcpSocket *socket, QString &urlPath, boo
QString channelNameForUrl {c.first};
channelNameForUrl.remove('#');
QString channelLink = "/" + global::toLowerAndNoSpaces(s.first) + "/" + channelNameForUrl;
QString channelLink = "/" + global::toLowerAndNoSpaces(s.first) +
"/" + channelNameForUrl + "/" + year + "/" + month + "/" + day;
replaceTag(htmlChannelLine, "CHANNEL_LINK", channelLink);
htmlChannelLineS += htmlChannelLine;
@ -1259,10 +1274,6 @@ void HttpServer::writeRealTimeChatPage(QTcpSocket *socket, QString &urlPath, boo
//// Payload
page.replace("<div class=\"main_payload\">", "<div class=\"main_payload\" id=\"payload\">");
QString year {QDateTime::currentDateTime().toString("yyyy")};
QString month {QDateTime::currentDateTime().toString("MM")};
QString day {QDateTime::currentDateTime().toString("dd")};
bool logsExisted {false};
QFile file;
QDir fsPath(m_logFolder+server+global::slash+channel);
@ -1434,6 +1445,7 @@ void HttpServer::writeAjaxAnswer(QTcpSocket *socket, QString &urlPath, bool isHe
if (not m_messageCache.contains(channelId)) {
m_messageCache.insert(channelId, new MessagePool);
consoleLog("Message caching enabled for "+server+"/#"+channel+". Real time reading started.");
}
else {
auto messages = *(m_messageCache[channelId]->getMessages());
@ -1508,9 +1520,15 @@ void MessagePool::saveNewMessage(const QString &nick, const QString &text)
const std::map<qint64, Message *>* MessagePool::getMessages()
{
m_lastPing = QDateTime::currentMSecsSinceEpoch();
return &m_messages;
}
qint64 MessagePool::getLastPing()
{
return m_lastPing;
}
void MessagePool::messageToDelete(qint64 timestamp)
{
auto it = m_messages.find(timestamp);

View File

@ -9,6 +9,8 @@
#include <queue>
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
class Message : public QObject
{
Q_OBJECT
@ -34,6 +36,7 @@ public:
MessagePool(QObject *parent = nullptr);
void saveNewMessage(const QString& nick, const QString& text);
const std::map<qint64, Message*>* getMessages();
qint64 getLastPing();
private:
qint64 m_lastPing;
@ -43,7 +46,8 @@ public slots:
void messageToDelete(qint64 timestamp);
};
const QString HTTP_ACTUAL_ETAG {"2021-12-24"}; // Change it if svg, css or ico was modified
//////////////////////////////////////////////////
class HttpServer : public QObject
{
Q_OBJECT