Store serverReceivedTime in messages (#3735)

Co-authored-by: James Upjohn <jammehcow@jammehcow.co.nz>
This commit is contained in:
pajlada 2022-05-15 08:08:28 +02:00 committed by GitHub
parent 1bf31889f9
commit 3119a9bab3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 16 deletions

View file

@ -63,6 +63,7 @@ struct Message : boost::noncopyable {
QString timeoutUser;
QString channelName;
QColor usernameColor;
QDateTime serverReceivedTime;
std::vector<Badge> badges;
std::map<QString, QString> badgeInfos;
std::shared_ptr<QColor> highlightColor;

View file

@ -58,8 +58,8 @@ MessagePtr IrcMessageBuilder::build()
// PUSH ELEMENTS
this->appendChannelName();
this->emplace<TimestampElement>(
calculateMessageTimestamp(this->ircMessage));
this->message().serverReceivedTime = calculateMessageTime(this->ircMessage);
this->emplace<TimestampElement>(this->message().serverReceivedTime.time());
this->appendUsername();

View file

@ -270,7 +270,7 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message)
MessageBuilder builder;
builder.emplace<TimestampElement>(
calculateMessageTimestamp(message));
calculateMessageTime(message).time());
builder.emplace<TextElement>(message->toData(),
MessageElementFlag::Text);
builder->flags.set(MessageFlag::Debug);

View file

@ -421,7 +421,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
chan->disableAllMessages();
chan->addMessage(
makeSystemMessage("Chat has been cleared by a moderator.",
calculateMessageTimestamp(message)));
calculateMessageTime(message).time()));
return;
}
@ -437,7 +437,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
auto timeoutMsg =
MessageBuilder(timeoutMessage, username, durationInSeconds, false,
calculateMessageTimestamp(message))
calculateMessageTime(message).time())
.release();
chan->addOrReplaceTimeout(timeoutMsg);
@ -656,7 +656,7 @@ std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(
}
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
calculateMessageTimestamp(message));
calculateMessageTime(message).time());
b->flags.set(MessageFlag::Subscription);
auto newMessage = b.release();
@ -710,7 +710,7 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
}
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
calculateMessageTimestamp(message));
calculateMessageTime(message).time());
b->flags.set(MessageFlag::Subscription);
auto newMessage = b.release();
@ -780,7 +780,7 @@ std::vector<MessagePtr> IrcMessageHandler::parseNoticeMessage(
.arg(remainingTime.isEmpty() ? "0s" : remainingTime);
builtMessage.emplace_back(makeSystemMessage(
formattedMessage, calculateMessageTimestamp(message)));
formattedMessage, calculateMessageTime(message).time()));
return builtMessage;
}
@ -789,7 +789,7 @@ std::vector<MessagePtr> IrcMessageHandler::parseNoticeMessage(
std::vector<MessagePtr> builtMessages;
builtMessages.emplace_back(makeSystemMessage(
message->content(), calculateMessageTimestamp(message)));
message->content(), calculateMessageTime(message).time()));
return builtMessages;
}

View file

@ -187,8 +187,8 @@ MessagePtr TwitchMessageBuilder::build()
}
// timestamp
this->emplace<TimestampElement>(
calculateMessageTimestamp(this->ircMessage));
this->message().serverReceivedTime = calculateMessageTime(this->ircMessage);
this->emplace<TimestampElement>(this->message().serverReceivedTime.time());
if (this->shouldAddModerationElements())
{

View file

@ -58,7 +58,7 @@ inline QString parseTagString(const QString &input)
return output;
}
inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
inline QDateTime calculateMessageTime(const Communi::IrcMessage *message)
{
// Check if message is from recent-messages API
if (message->tags().contains("historical"))
@ -71,14 +71,14 @@ inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
ts = message->tags().value("tmi-sent-ts").toLongLong();
}
return QDateTime::fromMSecsSinceEpoch(ts).time();
return QDateTime::fromMSecsSinceEpoch(ts);
}
// If present, handle tmi-sent-ts tag and use it as timestamp
if (message->tags().contains("tmi-sent-ts"))
{
auto ts = message->tags().value("tmi-sent-ts").toLongLong();
return QDateTime::fromMSecsSinceEpoch(ts).time();
return QDateTime::fromMSecsSinceEpoch(ts);
}
// Some IRC Servers might have server-time tag containing UTC date in ISO format, use it as timestamp
@ -89,11 +89,11 @@ inline QTime calculateMessageTimestamp(const Communi::IrcMessage *message)
auto date = QDateTime::fromString(timedate, Qt::ISODate);
date.setTimeSpec(Qt::TimeSpec::UTC);
return date.toLocalTime().time();
return date.toLocalTime();
}
// Fallback to current time
return QTime::currentTime();
return QDateTime::currentDateTime();
}
} // namespace chatterino