mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Fix timestamps on some messages loaded from the recent-messages service on startup (#2020)
This commit is contained in:
parent
b67e20d962
commit
58a6983796
|
@ -16,6 +16,7 @@
|
||||||
- Bugfix: Handle symlinks properly when saving commands & settings (#1856, #1908)
|
- 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: 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: 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
|
## 2.2.0
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,8 @@ MessageBuilder::MessageBuilder(SystemMessageTag, const QString &text,
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageBuilder::MessageBuilder(TimeoutMessageTag,
|
MessageBuilder::MessageBuilder(TimeoutMessageTag,
|
||||||
const QString &systemMessageText, int times)
|
const QString &systemMessageText, int times,
|
||||||
|
const QTime &time)
|
||||||
: MessageBuilder()
|
: MessageBuilder()
|
||||||
{
|
{
|
||||||
QString username = systemMessageText.split(" ").at(0);
|
QString username = systemMessageText.split(" ").at(0);
|
||||||
|
@ -135,7 +136,7 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag,
|
||||||
|
|
||||||
QString text;
|
QString text;
|
||||||
|
|
||||||
this->emplace<TimestampElement>();
|
this->emplace<TimestampElement>(time);
|
||||||
this->emplaceSystemTextAndUpdate(username, text)
|
this->emplaceSystemTextAndUpdate(username, text)
|
||||||
->setLink({Link::UserInfo, username});
|
->setLink({Link::UserInfo, username});
|
||||||
this->emplaceSystemTextAndUpdate(
|
this->emplaceSystemTextAndUpdate(
|
||||||
|
@ -147,13 +148,14 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag,
|
||||||
|
|
||||||
MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
|
MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
|
||||||
const QString &durationInSeconds,
|
const QString &durationInSeconds,
|
||||||
const QString &reason, bool multipleTimes)
|
const QString &reason, bool multipleTimes,
|
||||||
|
const QTime &time)
|
||||||
: MessageBuilder()
|
: MessageBuilder()
|
||||||
{
|
{
|
||||||
QString fullText;
|
QString fullText;
|
||||||
QString text;
|
QString text;
|
||||||
|
|
||||||
this->emplace<TimestampElement>();
|
this->emplace<TimestampElement>(time);
|
||||||
this->emplaceSystemTextAndUpdate(username, fullText)
|
this->emplaceSystemTextAndUpdate(username, fullText)
|
||||||
->setLink({Link::UserInfo, username});
|
->setLink({Link::UserInfo, username});
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,11 @@ public:
|
||||||
MessageBuilder(SystemMessageTag, const QString &text,
|
MessageBuilder(SystemMessageTag, const QString &text,
|
||||||
const QTime &time = QTime::currentTime());
|
const QTime &time = QTime::currentTime());
|
||||||
MessageBuilder(TimeoutMessageTag, const QString &systemMessageText,
|
MessageBuilder(TimeoutMessageTag, const QString &systemMessageText,
|
||||||
int times);
|
int times, const QTime &time = QTime::currentTime());
|
||||||
MessageBuilder(TimeoutMessageTag, const QString &username,
|
MessageBuilder(TimeoutMessageTag, const QString &username,
|
||||||
const QString &durationInSeconds, const QString &reason,
|
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 BanAction &action, uint32_t count = 1);
|
||||||
MessageBuilder(const UnbanAction &action);
|
MessageBuilder(const UnbanAction &action);
|
||||||
MessageBuilder(const AutomodUserAction &action);
|
MessageBuilder(const AutomodUserAction &action);
|
||||||
|
|
|
@ -370,7 +370,8 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||||
{
|
{
|
||||||
chan->disableAllMessages();
|
chan->disableAllMessages();
|
||||||
chan->addMessage(
|
chan->addMessage(
|
||||||
makeSystemMessage("Chat has been cleared by a moderator."));
|
makeSystemMessage("Chat has been cleared by a moderator.",
|
||||||
|
calculateMessageTimestamp(message)));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -390,8 +391,9 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
||||||
reason = v.toString();
|
reason = v.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto timeoutMsg = MessageBuilder(timeoutMessage, username,
|
auto timeoutMsg =
|
||||||
durationInSeconds, reason, false)
|
MessageBuilder(timeoutMessage, username, durationInSeconds, reason,
|
||||||
|
false, calculateMessageTimestamp(message))
|
||||||
.release();
|
.release();
|
||||||
chan->addOrReplaceTimeout(timeoutMsg);
|
chan->addOrReplaceTimeout(timeoutMsg);
|
||||||
|
|
||||||
|
@ -556,8 +558,9 @@ std::vector<MessagePtr> IrcMessageHandler::parseUserNoticeMessage(
|
||||||
|
|
||||||
if (it != tags.end())
|
if (it != tags.end())
|
||||||
{
|
{
|
||||||
auto b = MessageBuilder(systemMessage,
|
auto b =
|
||||||
parseTagString(it.value().toString()));
|
MessageBuilder(systemMessage, parseTagString(it.value().toString()),
|
||||||
|
calculateMessageTimestamp(message));
|
||||||
|
|
||||||
b->flags.set(MessageFlag::Subscription);
|
b->flags.set(MessageFlag::Subscription);
|
||||||
auto newMessage = b.release();
|
auto newMessage = b.release();
|
||||||
|
@ -597,8 +600,9 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
||||||
|
|
||||||
if (it != tags.end())
|
if (it != tags.end())
|
||||||
{
|
{
|
||||||
auto b = MessageBuilder(systemMessage,
|
auto b =
|
||||||
parseTagString(it.value().toString()));
|
MessageBuilder(systemMessage, parseTagString(it.value().toString()),
|
||||||
|
calculateMessageTimestamp(message));
|
||||||
|
|
||||||
b->flags.set(MessageFlag::Subscription);
|
b->flags.set(MessageFlag::Subscription);
|
||||||
auto newMessage = b.release();
|
auto newMessage = b.release();
|
||||||
|
@ -659,25 +663,8 @@ std::vector<MessagePtr> IrcMessageHandler::parseNoticeMessage(
|
||||||
{
|
{
|
||||||
std::vector<MessagePtr> builtMessages;
|
std::vector<MessagePtr> builtMessages;
|
||||||
|
|
||||||
if (message->tags().contains("historical"))
|
builtMessages.emplace_back(makeSystemMessage(
|
||||||
{
|
message->content(), calculateMessageTimestamp(message)));
|
||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return builtMessages;
|
return builtMessages;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,15 @@ namespace {
|
||||||
|
|
||||||
// rebuild the raw irc message so we can convert it back to an ircmessage again!
|
// rebuild the raw irc message so we can convert it back to an ircmessage again!
|
||||||
// this could probably be done in a smarter way
|
// this could probably be done in a smarter way
|
||||||
|
|
||||||
auto s = QString(":tmi.twitch.tv NOTICE %1 :%2")
|
auto s = QString(":tmi.twitch.tv NOTICE %1 :%2")
|
||||||
.arg(channelName)
|
.arg(channelName)
|
||||||
.arg(noticeMessage);
|
.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
|
// parseRecentMessages takes a json object and returns a vector of
|
||||||
|
|
|
@ -220,24 +220,8 @@ MessagePtr TwitchMessageBuilder::build()
|
||||||
}
|
}
|
||||||
|
|
||||||
// timestamp
|
// timestamp
|
||||||
if (this->historicalMessage_)
|
this->emplace<TimestampElement>(
|
||||||
{
|
calculateMessageTimestamp(this->ircMessage));
|
||||||
// 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>();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addModerationElement = true;
|
bool addModerationElement = true;
|
||||||
if (this->senderIsBroadcaster)
|
if (this->senderIsBroadcaster)
|
||||||
|
|
|
@ -58,4 +58,25 @@ inline QString parseTagString(const QString &input)
|
||||||
return output;
|
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
|
} // namespace chatterino
|
||||||
|
|
Loading…
Reference in a new issue