From fc81fa6fb937b6e5936715578c6df625195d9250 Mon Sep 17 00:00:00 2001 From: acetone Date: Sat, 1 Jan 2022 03:41:34 -0500 Subject: [PATCH] real time mode upgrade --- html/realtimechat.js | 8 ++++++++ ircclient.cpp | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/html/realtimechat.js b/html/realtimechat.js index 7dc984f..946dabf 100644 --- a/html/realtimechat.js +++ b/html/realtimechat.js @@ -7,8 +7,10 @@ let objOnlineList = document.getElementById("onlineList"); let lastMessageId = document.getElementById("LMId").innerText; let reqIsFailed = false; let firstLoadingWithDisconnectedServer = false; +let unreadedCount = 0; const ajaxUrl = document.getElementById("ajaxPath").innerText; +const originalTitle = document.title; const audio = new Audio('/newmessage.mp3'); const HTML_SERVER_ONLINE_MARKER = "✅"; const HTML_SERVER_OFFLINE_MARKER = "❌"; @@ -29,6 +31,8 @@ function appendMessage(nick /* if == "***", then system message */, message) nicknameContainer.innerText = nick; nicknameContainer.setAttribute("style", "color: #1b4af5"); if (document.hidden) { + unreadedCount++; + document.title = '(' + unreadedCount + ') ' + originalTitle; audio.play(); } } @@ -111,6 +115,10 @@ function toAJAX() function loop() { + if (!document.hidden && unreadedCount>0) { + unreadedCount = 0; + document.title = originalTitle; + } let dots = objPath.innerText; if (dots === "...") { dots = "" diff --git a/ircclient.cpp b/ircclient.cpp index 95c1233..ad12229 100644 --- a/ircclient.cpp +++ b/ircclient.cpp @@ -208,6 +208,8 @@ void IrcClient::toTrigger(const QString& channel, const QString &nickname, const void IrcClient::toChatLog(QString channel, const QString &nick, const QString &message) { channel.remove('#'); + emit newMessage(m_connectionData.displayName, channel, nick, message); + QDir dir(m_connectionData.logFolderPath); if (not dir.exists(channel)) { dir.mkdir(channel); @@ -251,7 +253,6 @@ void IrcClient::toChatLog(QString channel, const QString &nick, const QString &m QString logMessage {"["+nick+"] " + message + '\n'}; file.write(logMessage.toUtf8()); - emit newMessage(m_connectionData.displayName, channel, nick, message); file.close(); }