mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Store serverReceivedTime in messages (#3735)
Co-authored-by: James Upjohn <jammehcow@jammehcow.co.nz>
This commit is contained in:
parent
1bf31889f9
commit
3119a9bab3
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue