Use server time in received IRC messages where available (#3026)

This commit is contained in:
Paweł 2021-07-17 18:22:25 +02:00 committed by GitHub
parent fa2fd4593b
commit a84e62c6bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 8 deletions

View file

@ -4,6 +4,8 @@
- Major: Newly uploaded Twitch emotes are once again present in emote picker and can be autocompleted with Tab as well. (#2992) - Major: Newly uploaded Twitch emotes are once again present in emote picker and can be autocompleted with Tab as well. (#2992)
- Minor: Added autocompletion in /whispers for Twitch emotes, Global Bttv/Ffz emotes and emojis. (#2999) - Minor: Added autocompletion in /whispers for Twitch emotes, Global Bttv/Ffz emotes and emojis. (#2999)
- Minor: Received Twitch messages now use the exact same timestamp (obtained from Twitch's server) for every Chatterino user instead of assuming message timestamp on client's side. (#3021)
- Minor: Received IRC messages use `time` message tag for timestamp if it's available. (#3021)
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010) - Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
- Dev: Ubuntu packages are now available (#2936) - Dev: Ubuntu packages are now available (#2936)

View file

@ -40,7 +40,8 @@ MessagePtr IrcMessageBuilder::build()
// PUSH ELEMENTS // PUSH ELEMENTS
this->appendChannelName(); this->appendChannelName();
this->emplace<TimestampElement>(); this->emplace<TimestampElement>(
calculateMessageTimestamp(this->ircMessage));
this->appendUsername(); this->appendUsername();
@ -70,8 +71,6 @@ void IrcMessageBuilder::addWords(const QStringList &words)
void IrcMessageBuilder::appendUsername() void IrcMessageBuilder::appendUsername()
{ {
auto app = getApp();
QString username = this->userName; QString username = this->userName;
this->message().loginName = username; this->message().loginName = username;
this->message().displayName = username; this->message().displayName = username;

View file

@ -9,6 +9,7 @@
#include "providers/irc/IrcChannel2.hpp" #include "providers/irc/IrcChannel2.hpp"
#include "providers/irc/IrcMessageBuilder.hpp" #include "providers/irc/IrcMessageBuilder.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "util/IrcHelpers.hpp"
#include "util/QObjectRef.hpp" #include "util/QObjectRef.hpp"
#include <QMetaEnum> #include <QMetaEnum>
@ -92,7 +93,8 @@ void IrcServer::initializeConnectionSignals(IrcConnection *connection,
// XD PAJLADA // XD PAJLADA
MessageBuilder builder; MessageBuilder builder;
builder.emplace<TimestampElement>(); builder.emplace<TimestampElement>(
calculateMessageTimestamp(message));
builder.emplace<TextElement>( builder.emplace<TextElement>(
message->nick(), MessageElementFlag::Username); message->nick(), MessageElementFlag::Username);
builder.emplace<TextElement>( builder.emplace<TextElement>(
@ -259,7 +261,8 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message)
{ {
MessageBuilder builder; MessageBuilder builder;
builder.emplace<TimestampElement>(); builder.emplace<TimestampElement>(
calculateMessageTimestamp(message));
builder.emplace<TextElement>(message->toData(), builder.emplace<TextElement>(message->toData(),
MessageElementFlag::Text); MessageElementFlag::Text);
builder->flags.set(MessageFlag::Debug); builder->flags.set(MessageFlag::Debug);

View file

@ -65,7 +65,7 @@ inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
if (message->tags().contains("historical")) if (message->tags().contains("historical"))
{ {
bool customReceived = false; bool customReceived = false;
qint64 ts = auto ts =
message->tags().value("rm-received-ts").toLongLong(&customReceived); message->tags().value("rm-received-ts").toLongLong(&customReceived);
if (!customReceived) if (!customReceived)
{ {
@ -74,10 +74,27 @@ inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
return QDateTime::fromMSecsSinceEpoch(ts).time(); return QDateTime::fromMSecsSinceEpoch(ts).time();
} }
else
// If present, handle tmi-sent-ts tag and use it as timestamp
if (message->tags().contains("tmi-sent-ts"))
{ {
return QTime::currentTime(); auto ts = message->tags().value("tmi-sent-ts").toLongLong();
return QDateTime::fromMSecsSinceEpoch(ts).time();
} }
// 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();
} }
} // namespace chatterino } // namespace chatterino