#91 Timestamp for chat history.

master
Tomatix 3 years ago
parent 72de07fb30
commit 9012607434
  1. 42
      IdealIRC/IRC.cpp

@ -22,9 +22,29 @@
#include "ScriptEvent.h"
#include "Script/Builtin/ListUtils.h" // Needed for LIST_END_MAGIC
#include "config.h"
#include <fmt/format.h>
#include <QDateTime>
#include <QTimer>
#include <fmt/format.h>
#include <optional>
#include <algorithm>
namespace {
std::optional<QDateTime> tryGetTimeTag(const IRCMessage* ircmessage)
{
const auto& tags = ircmessage->getTags();
auto it = std::find_if(tags.cbegin(), tags.cend(), [](const std::string& tag) {
return tag.find("time=") != std::string::npos;
});
if (it == tags.cend())
return {};
const auto tag = QString::fromStdString(*it);
const auto timestamp = tag.split('=')[1];
const auto ts = QDateTime::fromString(timestamp, Qt::ISODateWithMs);
return ts.toLocalTime();
}
}
IRC::IRC(IWinStatus& status)
: m_status(status)
@ -463,7 +483,15 @@ void IRC::onMsgPrivmsg(const IRCPrefix& sender, const std::string& target, const
}
else
msg = fmt::format("<{}> {}", sender.toString(), message);
window->print(ptype, msg.c_str());
const auto rawmsg = getCurrentMessageRaw();
const auto ts = tryGetTimeTag(rawmsg);
if (ts)
window->printWithCustomTime(*ts, ptype, msg.c_str());
else
window->print(ptype, msg.c_str());
MdiManager::instance().highlight(window, hl);
if (messageHasMyNick)
@ -496,7 +524,15 @@ void IRC::onMsgNotice(const IRCPrefix& sender, const std::string& target, const
msg = fmt::format("-{}- {}", sender.toString(), message);
window = getStatus().getActiveWindow();
}
window->print(PrintType::Notice, msg.c_str());
const auto rawmsg = getCurrentMessageRaw();
const auto ts = tryGetTimeTag(rawmsg);
if (ts)
window->printWithCustomTime(*ts, PrintType::Notice, msg.c_str());
else
window->print(PrintType::Notice, msg.c_str());
MdiManager::instance().highlight(window, HL_Attention);
emit showTrayMessage(tr("Notice"), QString::fromStdString(msg));
}

Loading…
Cancel
Save