feat(eventsub): use special flag and timestamps from metadata (#5996)

This commit is contained in:
nerix
2025-02-26 15:40:42 +01:00
committed by GitHub
parent b957af4f50
commit 63b5b2ca6a
33 changed files with 159 additions and 107 deletions
+1 -1
View File
@@ -30,7 +30,7 @@
- Bugfix: Fixed the input font not immediately updating when zooming in/out. (#5960)
- Bugfix: Fixed color input thinking blue is also red. (#5982)
- Dev: Subscriptions to PubSub channel points redemption topics now use no auth token, making it continue to work during PubSub shutdown. (#5947)
- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904, #5910, #5903, #5915, #5916, #5930, #5935, #5932, #5943, #5952, #5953, #5968, #5973, #5974, #5980, #5981, #5985, #5990, #5992, #5993)
- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904, #5910, #5903, #5915, #5916, #5930, #5935, #5932, #5943, #5952, #5953, #5968, #5973, #5974, #5980, #5981, #5985, #5990, #5992, #5993, #5996)
- Dev: Remove unneeded platform specifier for toasts. (#5914)
- Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784)
- Dev: Removed unused PubSub whisper code. (#5898)
@@ -2,6 +2,7 @@
#include <boost/json.hpp>
#include <chrono>
#include <optional>
#include <string>
@@ -23,8 +24,8 @@ namespace chatterino::eventsub::lib::messages {
struct Metadata {
std::string messageID;
std::string messageType;
// TODO: should this be chronofied?
std::string messageTimestamp;
/// json_tag=AsISO8601
std::chrono::system_clock::time_point messageTimestamp;
std::optional<std::string> subscriptionType;
std::optional<std::string> subscriptionVersion;
@@ -44,6 +44,8 @@ boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
return messageType.error();
}
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<
decltype(std::declval<Metadata>().messageTimestamp)>>);
const auto *jvmessageTimestamp = root.if_contains("message_timestamp");
if (jvmessageTimestamp == nullptr)
{
@@ -51,7 +53,8 @@ boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
}
auto messageTimestamp =
boost::json::try_value_to<std::string>(*jvmessageTimestamp);
boost::json::try_value_to<std::chrono::system_clock::time_point>(
*jvmessageTimestamp, AsISO8601());
if (messageTimestamp.has_error())
{
@@ -90,7 +93,7 @@ boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
return Metadata{
.messageID = std::move(messageID.value()),
.messageType = std::move(messageType.value()),
.messageTimestamp = std::move(messageTimestamp.value()),
.messageTimestamp = messageTimestamp.value(),
.subscriptionType = std::move(subscriptionType),
.subscriptionVersion = std::move(subscriptionVersion),
};
+2
View File
@@ -56,6 +56,8 @@ enum class MessageFlag : std::int64_t {
AutoModBlockedTerm = (1LL << 38),
/// The message is a full clear chat message (/clear)
ClearChat = (1LL << 39),
/// The message is built from EventSub
EventSub = (1LL << 40),
};
using MessageFlags = FlagsEnum<MessageFlag>;
+2 -5
View File
@@ -12,6 +12,7 @@
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp"
#include "util/PostToThread.hpp"
#include <boost/json.hpp>
@@ -148,11 +149,7 @@ void Connection::onChannelModerate(
return;
}
auto now = QDateTime::currentDateTime();
if (getApp()->isTest())
{
now = QDateTime::fromSecsSinceEpoch(0).toUTC();
}
auto now = chronoToQDateTime(metadata.messageTimestamp);
std::visit(
[&](auto &&action) {
@@ -41,8 +41,8 @@ EventSubMessageBuilder::EventSubMessageBuilder(TwitchChannel *channel,
const QDateTime &time)
: channel(channel)
{
this->emplace<TimestampElement>();
this->message().flags.set(MessageFlag::System);
this->emplace<TimestampElement>(time.time());
this->message().flags.set(MessageFlag::System, MessageFlag::EventSub);
this->message().flags.set(MessageFlag::Timeout); // do we need this?
this->message().serverReceivedTime = time;
}
+19
View File
@@ -3,9 +3,11 @@
#include "Application.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include <QDateTime>
#include <QDirIterator>
#include <QLocale>
#include <QRegularExpression>
#include <QTimeZone>
#include <QUuid>
namespace {
@@ -314,4 +316,21 @@ QLocale getSystemLocale()
return QLocale::system();
}
QDateTime chronoToQDateTime(std::chrono::system_clock::time_point time)
{
auto msSinceEpoch =
std::chrono::time_point_cast<std::chrono::milliseconds>(time)
.time_since_epoch();
auto dt = QDateTime::fromMSecsSinceEpoch(msSinceEpoch.count());
#if CHATTERINO_WITH_TESTS
if (getApp()->isTest())
{
dt = dt.toUTC();
}
#endif
return dt;
}
} // namespace chatterino
+8
View File
@@ -4,11 +4,14 @@
#include <QLocale>
#include <QString>
#include <chrono>
#include <cmath>
#include <optional>
#include <utility>
#include <vector>
class QDateTime;
namespace chatterino {
// only qualified for tests
@@ -191,4 +194,9 @@ QString unescapeZeroWidthJoiner(QString escaped);
QLocale getSystemLocale();
/// @brief Converts `time` to a QDateTime in a local time zone
///
/// Note: When running tests, this will always return a date-time in UTC.
QDateTime chronoToQDateTime(std::chrono::system_clock::time_point time);
} // namespace chatterino
@@ -60,7 +60,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -157,13 +157,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz banned uint128: my reason ",
"searchText": "nerixyz banned uint128: my reason ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "uint128",
"userID": "",
"usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -141,13 +141,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz banned uint128. ",
"searchText": "nerixyz banned uint128. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "uint128",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -111,7 +111,7 @@
"loginName": "",
"messageText": "nerixyz cleared the chat. ",
"searchText": "nerixyz cleared the chat. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "nerixyz",
"userID": "",
"usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -159,13 +159,13 @@
]
}
],
"flags": "System|Timeout|DoNotTriggerNotification",
"flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…",
"searchText": "testaccount_420 deleted message from testaccount_420 saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "testaccount_420",
"userID": "",
"usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -159,13 +159,13 @@
]
}
],
"flags": "System|Timeout|DoNotTriggerNotification",
"flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 saying: asd",
"searchText": "testaccount_420 deleted message from testaccount_420 saying: asd",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "testaccount_420",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned off emote-only mode. ",
"searchText": "nerixyz turned off emote-only mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned on emote-only mode. ",
"searchText": "nerixyz turned on emote-only mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -57,7 +57,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -66,7 +66,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -150,13 +150,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned on followers-only mode. ",
"searchText": "nerixyz turned on followers-only mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned off followers-only mode. ",
"searchText": "nerixyz turned off followers-only mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -57,7 +57,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -66,7 +66,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -166,13 +166,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned on followers-only mode. (15 minutes) ",
"searchText": "nerixyz turned on followers-only mode. (15 minutes) ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -191,13 +191,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz banned twitchdev in testaccount_420: a reason 😂 ",
"searchText": "nerixyz banned twitchdev in testaccount_420: a reason 😂 ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "twitchdev",
"userID": "",
"usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -174,13 +174,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz banned twitchdev in testaccount_420. ",
"searchText": "nerixyz banned twitchdev in testaccount_420. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "twitchdev",
"userID": "",
"usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -192,13 +192,13 @@
]
}
],
"flags": "System|Timeout|DoNotTriggerNotification",
"flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…",
"searchText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "testaccount_420",
"userID": "",
"usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -192,13 +192,13 @@
]
}
],
"flags": "System|Timeout|DoNotTriggerNotification",
"flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: dfg",
"searchText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: dfg",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "testaccount_420",
"userID": "",
"usernameColor": "#ff000000"
@@ -59,7 +59,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -68,7 +68,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -173,13 +173,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz unbanned uint128 in testaccount_420. ",
"searchText": "nerixyz unbanned uint128 in testaccount_420. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "uint128",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned off slow mode. ",
"searchText": "nerixyz turned off slow mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -57,7 +57,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -66,7 +66,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -166,13 +166,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned on slow mode. (10 seconds) ",
"searchText": "nerixyz turned on slow mode. (10 seconds) ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned off subscribers-only mode. ",
"searchText": "nerixyz turned off subscribers-only mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned on subscribers-only mode. ",
"searchText": "nerixyz turned on subscribers-only mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -59,7 +59,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -68,7 +68,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -140,13 +140,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz unbanned uint128. ",
"searchText": "nerixyz unbanned uint128. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "uint128",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned off unique-chat mode. ",
"searchText": "nerixyz turned off unique-chat mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -148,13 +148,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "nerixyz",
"messageText": "nerixyz turned on unique-chat mode. ",
"searchText": "nerixyz turned on unique-chat mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -159,13 +159,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "quotrok",
"messageText": "quotrok has warned twitchdev: cut it out ",
"searchText": "quotrok has warned twitchdev: cut it out ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"0:00"
"12:31"
]
},
"flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None",
"value": ""
},
"time": "00:00:00",
"time": "12:31:47",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
@@ -159,13 +159,13 @@
]
}
],
"flags": "System|Timeout",
"flags": "System|Timeout|EventSub",
"id": "",
"localizedName": "",
"loginName": "quotrok",
"messageText": "quotrok has warned twitchdev: cut it out ",
"searchText": "quotrok has warned twitchdev: cut it out ",
"serverReceivedTime": "1970-01-01T00:00:00Z",
"serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "",
"userID": "",
"usernameColor": "#ff000000"
+22
View File
@@ -1,7 +1,11 @@
#include "util/Helpers.hpp"
#include "mocks/BaseApplication.hpp"
#include "Test.hpp"
#include <QDateTime>
#include <QTimeZone>
#include <span>
using namespace chatterino;
@@ -556,3 +560,21 @@ TEST(Helpers, unescapeZeroWidthJoiner)
EXPECT_EQ(actual, c.output);
}
}
TEST(Helpers, chronoToQDateTime)
{
mock::BaseApplication app;
auto epoch = chronoToQDateTime({});
ASSERT_EQ(epoch.timeZone(), QTimeZone::utc());
ASSERT_EQ(epoch.toMSecsSinceEpoch(), 0);
std::chrono::milliseconds somePointSinceEpoch{1740574189131};
auto qPointSinceEpoch = chronoToQDateTime(
std::chrono::system_clock::time_point{somePointSinceEpoch});
ASSERT_EQ(qPointSinceEpoch.timeZone(), QTimeZone::utc());
ASSERT_EQ(qPointSinceEpoch.toMSecsSinceEpoch(),
somePointSinceEpoch.count());
ASSERT_EQ(qPointSinceEpoch.toString(Qt::ISODateWithMs),
"2025-02-26T12:49:49.131Z");
}