2017-12-17 00:01:42 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-08 15:57:00 +02:00
|
|
|
#include <IrcMessage>
|
2017-12-17 00:01:42 +01:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
namespace chatterino {
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
inline QString parseTagString(const QString &input)
|
2017-12-17 00:01:42 +01:00
|
|
|
{
|
|
|
|
QString output = input;
|
2017-12-17 00:39:27 +01:00
|
|
|
output.detach();
|
2017-12-17 00:01:42 +01:00
|
|
|
|
2018-06-05 16:29:06 +02:00
|
|
|
auto length = output.length();
|
2017-12-17 00:01:42 +01:00
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
for (int i = 0; i < length - 1; i++)
|
|
|
|
{
|
|
|
|
if (output[i] == '\\')
|
|
|
|
{
|
2017-12-17 00:39:27 +01:00
|
|
|
QChar c = output[i + 1];
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
switch (c.cell())
|
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case 'n': {
|
2018-06-05 16:29:06 +02:00
|
|
|
output.replace(i, 2, '\n');
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-17 00:56:33 +01:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case 'r': {
|
2018-06-05 16:29:06 +02:00
|
|
|
output.replace(i, 2, '\r');
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-17 00:56:33 +01:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case 's': {
|
2018-06-05 16:29:06 +02:00
|
|
|
output.replace(i, 2, ' ');
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-17 00:56:33 +01:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case '\\': {
|
2018-06-05 16:29:06 +02:00
|
|
|
output.replace(i, 2, '\\');
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-17 00:56:33 +01:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
case ':': {
|
2018-06-05 16:29:06 +02:00
|
|
|
output.replace(i, 2, ';');
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-17 00:56:33 +01:00
|
|
|
|
2019-09-26 00:51:05 +02:00
|
|
|
default: {
|
2018-06-05 16:29:06 +02:00
|
|
|
output.remove(i, 1);
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-12-17 00:39:27 +01:00
|
|
|
}
|
2017-12-17 00:56:33 +01:00
|
|
|
|
2018-06-05 16:29:06 +02:00
|
|
|
length--;
|
2017-12-17 00:39:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 13:44:15 +02:00
|
|
|
return output;
|
2017-12-17 00:01:42 +01:00
|
|
|
}
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2020-10-03 13:37:07 +02:00
|
|
|
inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// Check if message is from recent-messages API
|
|
|
|
if (message->tags().contains("historical"))
|
|
|
|
{
|
|
|
|
bool customReceived = false;
|
2021-07-17 18:22:25 +02:00
|
|
|
auto ts =
|
2020-10-03 13:37:07 +02:00
|
|
|
message->tags().value("rm-received-ts").toLongLong(&customReceived);
|
|
|
|
if (!customReceived)
|
|
|
|
{
|
|
|
|
ts = message->tags().value("tmi-sent-ts").toLongLong();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDateTime::fromMSecsSinceEpoch(ts).time();
|
|
|
|
}
|
2021-07-17 18:22:25 +02:00
|
|
|
|
|
|
|
// If present, handle tmi-sent-ts tag and use it as timestamp
|
|
|
|
if (message->tags().contains("tmi-sent-ts"))
|
2020-10-03 13:37:07 +02:00
|
|
|
{
|
2021-07-17 18:22:25 +02:00
|
|
|
auto ts = message->tags().value("tmi-sent-ts").toLongLong();
|
|
|
|
return QDateTime::fromMSecsSinceEpoch(ts).time();
|
2020-10-03 13:37:07 +02:00
|
|
|
}
|
2021-07-17 18:22:25 +02:00
|
|
|
|
|
|
|
// Some IRC Servers might have server-time tag containing UTC date in ISO format, use it as timestamp
|
|
|
|
// See: https://ircv3.net/irc/#server-time
|
|
|
|
if (message->tags().contains("time"))
|
|
|
|
{
|
|
|
|
QString timedate = message->tags().value("time").toString();
|
|
|
|
|
|
|
|
auto date = QDateTime::fromString(timedate, Qt::ISODate);
|
|
|
|
date.setTimeSpec(Qt::TimeSpec::UTC);
|
|
|
|
return date.toLocalTime().time();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to current time
|
|
|
|
return QTime::currentTime();
|
2020-10-03 13:37:07 +02:00
|
|
|
}
|
|
|
|
|
2017-12-17 00:01:42 +01:00
|
|
|
} // namespace chatterino
|