Fix timestamps on some messages loaded from the recent-messages service on startup (#2020)

This commit is contained in:
Daniel 2020-10-03 07:37:07 -04:00 committed by GitHub
parent b67e20d962
commit 58a6983796
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 52 deletions

View file

@ -16,6 +16,7 @@
- Bugfix: Handle symlinks properly when saving commands & settings (#1856, #1908)
- Bugfix: Starting Chatterino in a minimized state after an update will no longer cause a crash
- Bugfix: Modify the emote parsing to handle some edge-cases with dots and stuff (#1704, #1714)
- Bugfix: Fixed timestamps being incorrect on some messages loaded from the recent-messages service on startup (#1286, #2020)
## 2.2.0

View file

@ -127,7 +127,8 @@ MessageBuilder::MessageBuilder(SystemMessageTag, const QString &text,
}
MessageBuilder::MessageBuilder(TimeoutMessageTag,
const QString &systemMessageText, int times)
const QString &systemMessageText, int times,
const QTime &time)
: MessageBuilder()
{
QString username = systemMessageText.split(" ").at(0);
@ -135,7 +136,7 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag,
QString text;
this->emplace<TimestampElement>();
this->emplace<TimestampElement>(time);
this->emplaceSystemTextAndUpdate(username, text)
->setLink({Link::UserInfo, username});
this->emplaceSystemTextAndUpdate(
@ -147,13 +148,14 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag,
MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
const QString &durationInSeconds,
const QString &reason, bool multipleTimes)
const QString &reason, bool multipleTimes,
const QTime &time)
: MessageBuilder()
{
QString fullText;
QString text;
this->emplace<TimestampElement>();
this->emplace<TimestampElement>(time);
this->emplaceSystemTextAndUpdate(username, fullText)
->setLink({Link::UserInfo, username});

View file

@ -42,10 +42,11 @@ public:
MessageBuilder(SystemMessageTag, const QString &text,
const QTime &time = QTime::currentTime());
MessageBuilder(TimeoutMessageTag, const QString &systemMessageText,
int times);
int times, const QTime &time = QTime::currentTime());
MessageBuilder(TimeoutMessageTag, const QString &username,
const QString &durationInSeconds, const QString &reason,
bool multipleTimes);
bool multipleTimes,
const QTime &time = QTime::currentTime());
MessageBuilder(const BanAction &action, uint32_t count = 1);
MessageBuilder(const UnbanAction &action);
MessageBuilder(const AutomodUserAction &action);

View file

@ -370,7 +370,8 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
{
chan->disableAllMessages();
chan->addMessage(
makeSystemMessage("Chat has been cleared by a moderator."));
makeSystemMessage("Chat has been cleared by a moderator.",
calculateMessageTimestamp(message)));
return;
}
@ -390,8 +391,9 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
reason = v.toString();
}
auto timeoutMsg = MessageBuilder(timeoutMessage, username,
durationInSeconds, reason, false)
auto timeoutMsg =
MessageBuilder(timeoutMessage, username, durationInSeconds, reason,
false, calculateMessageTimestamp(message))
.release();
chan->addOrReplaceTimeout(timeoutMsg);
@ -556,8 +558,9 @@ std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(
if (it != tags.end())
{
auto b = MessageBuilder(systemMessage,
parseTagString(it.value().toString()));
auto b =
MessageBuilder(systemMessage, parseTagString(it.value().toString()),
calculateMessageTimestamp(message));
b->flags.set(MessageFlag::Subscription);
auto newMessage = b.release();
@ -597,8 +600,9 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
if (it != tags.end())
{
auto b = MessageBuilder(systemMessage,
parseTagString(it.value().toString()));
auto b =
MessageBuilder(systemMessage, parseTagString(it.value().toString()),
calculateMessageTimestamp(message));
b->flags.set(MessageFlag::Subscription);
auto newMessage = b.release();
@ -659,25 +663,8 @@ std::vector<MessagePtr> IrcMessageHandler::parseNoticeMessage(
{
std::vector<MessagePtr> builtMessages;
if (message->tags().contains("historical"))
{
bool customReceived = false;
qint64 ts = message->tags()
.value("rm-received-ts")
.toLongLong(&customReceived);
if (!customReceived)
{
ts = message->tags().value("tmi-sent-ts").toLongLong();
}
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(ts);
builtMessages.emplace_back(
makeSystemMessage(message->content(), dateTime.time()));
}
else
{
builtMessages.emplace_back(makeSystemMessage(message->content()));
}
builtMessages.emplace_back(makeSystemMessage(
message->content(), calculateMessageTimestamp(message)));
return builtMessages;
}

View file

@ -71,11 +71,15 @@ namespace {
// rebuild the raw irc message so we can convert it back to an ircmessage again!
// this could probably be done in a smarter way
auto s = QString(":tmi.twitch.tv NOTICE %1 :%2")
.arg(channelName)
.arg(noticeMessage);
return Communi::IrcMessage::fromData(s.toUtf8(), nullptr);
auto newMessage = Communi::IrcMessage::fromData(s.toUtf8(), nullptr);
newMessage->setTags(message->tags());
return newMessage;
}
// parseRecentMessages takes a json object and returns a vector of

View file

@ -220,24 +220,8 @@ MessagePtr TwitchMessageBuilder::build()
}
// timestamp
if (this->historicalMessage_)
{
// This may be architecture dependent(datatype)
bool customReceived = false;
qint64 ts =
this->tags.value("rm-received-ts").toLongLong(&customReceived);
if (!customReceived)
{
ts = this->tags.value("tmi-sent-ts").toLongLong();
}
QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(ts);
this->emplace<TimestampElement>(dateTime.time());
}
else
{
this->emplace<TimestampElement>();
}
this->emplace<TimestampElement>(
calculateMessageTimestamp(this->ircMessage));
bool addModerationElement = true;
if (this->senderIsBroadcaster)

View file

@ -58,4 +58,25 @@ inline QString parseTagString(const QString &input)
return output;
}
inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
{
// Check if message is from recent-messages API
if (message->tags().contains("historical"))
{
bool customReceived = false;
qint64 ts =
message->tags().value("rm-received-ts").toLongLong(&customReceived);
if (!customReceived)
{
ts = message->tags().value("tmi-sent-ts").toLongLong();
}
return QDateTime::fromMSecsSinceEpoch(ts).time();
}
else
{
return QTime::currentTime();
}
}
} // namespace chatterino