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 the input font not immediately updating when zooming in/out. (#5960)
- Bugfix: Fixed color input thinking blue is also red. (#5982) - 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: 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: Remove unneeded platform specifier for toasts. (#5914)
- Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784) - Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784)
- Dev: Removed unused PubSub whisper code. (#5898) - Dev: Removed unused PubSub whisper code. (#5898)
@@ -2,6 +2,7 @@
#include <boost/json.hpp> #include <boost/json.hpp>
#include <chrono>
#include <optional> #include <optional>
#include <string> #include <string>
@@ -23,8 +24,8 @@ namespace chatterino::eventsub::lib::messages {
struct Metadata { struct Metadata {
std::string messageID; std::string messageID;
std::string messageType; std::string messageType;
// TODO: should this be chronofied? /// json_tag=AsISO8601
std::string messageTimestamp; std::chrono::system_clock::time_point messageTimestamp;
std::optional<std::string> subscriptionType; std::optional<std::string> subscriptionType;
std::optional<std::string> subscriptionVersion; std::optional<std::string> subscriptionVersion;
@@ -44,6 +44,8 @@ boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
return messageType.error(); 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"); const auto *jvmessageTimestamp = root.if_contains("message_timestamp");
if (jvmessageTimestamp == nullptr) if (jvmessageTimestamp == nullptr)
{ {
@@ -51,7 +53,8 @@ boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
} }
auto messageTimestamp = 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()) if (messageTimestamp.has_error())
{ {
@@ -90,7 +93,7 @@ boost::json::result_for<Metadata, boost::json::value>::type tag_invoke(
return Metadata{ return Metadata{
.messageID = std::move(messageID.value()), .messageID = std::move(messageID.value()),
.messageType = std::move(messageType.value()), .messageType = std::move(messageType.value()),
.messageTimestamp = std::move(messageTimestamp.value()), .messageTimestamp = messageTimestamp.value(),
.subscriptionType = std::move(subscriptionType), .subscriptionType = std::move(subscriptionType),
.subscriptionVersion = std::move(subscriptionVersion), .subscriptionVersion = std::move(subscriptionVersion),
}; };
+2
View File
@@ -56,6 +56,8 @@ enum class MessageFlag : std::int64_t {
AutoModBlockedTerm = (1LL << 38), AutoModBlockedTerm = (1LL << 38),
/// The message is a full clear chat message (/clear) /// The message is a full clear chat message (/clear)
ClearChat = (1LL << 39), ClearChat = (1LL << 39),
/// The message is built from EventSub
EventSub = (1LL << 40),
}; };
using MessageFlags = FlagsEnum<MessageFlag>; using MessageFlags = FlagsEnum<MessageFlag>;
+2 -5
View File
@@ -12,6 +12,7 @@
#include "providers/twitch/TwitchIrcServer.hpp" #include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp"
#include "util/PostToThread.hpp" #include "util/PostToThread.hpp"
#include <boost/json.hpp> #include <boost/json.hpp>
@@ -148,11 +149,7 @@ void Connection::onChannelModerate(
return; return;
} }
auto now = QDateTime::currentDateTime(); auto now = chronoToQDateTime(metadata.messageTimestamp);
if (getApp()->isTest())
{
now = QDateTime::fromSecsSinceEpoch(0).toUTC();
}
std::visit( std::visit(
[&](auto &&action) { [&](auto &&action) {
@@ -41,8 +41,8 @@ EventSubMessageBuilder::EventSubMessageBuilder(TwitchChannel *channel,
const QDateTime &time) const QDateTime &time)
: channel(channel) : channel(channel)
{ {
this->emplace<TimestampElement>(); this->emplace<TimestampElement>(time.time());
this->message().flags.set(MessageFlag::System); this->message().flags.set(MessageFlag::System, MessageFlag::EventSub);
this->message().flags.set(MessageFlag::Timeout); // do we need this? this->message().flags.set(MessageFlag::Timeout); // do we need this?
this->message().serverReceivedTime = time; this->message().serverReceivedTime = time;
} }
+19
View File
@@ -3,9 +3,11 @@
#include "Application.hpp" #include "Application.hpp"
#include "providers/twitch/TwitchCommon.hpp" #include "providers/twitch/TwitchCommon.hpp"
#include <QDateTime>
#include <QDirIterator> #include <QDirIterator>
#include <QLocale> #include <QLocale>
#include <QRegularExpression> #include <QRegularExpression>
#include <QTimeZone>
#include <QUuid> #include <QUuid>
namespace { namespace {
@@ -314,4 +316,21 @@ QLocale getSystemLocale()
return QLocale::system(); 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 } // namespace chatterino
+8
View File
@@ -4,11 +4,14 @@
#include <QLocale> #include <QLocale>
#include <QString> #include <QString>
#include <chrono>
#include <cmath> #include <cmath>
#include <optional> #include <optional>
#include <utility> #include <utility>
#include <vector> #include <vector>
class QDateTime;
namespace chatterino { namespace chatterino {
// only qualified for tests // only qualified for tests
@@ -191,4 +194,9 @@ QString unescapeZeroWidthJoiner(QString escaped);
QLocale getSystemLocale(); 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 } // namespace chatterino
@@ -60,7 +60,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -157,13 +157,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz banned uint128: my reason ", "messageText": "nerixyz banned uint128: my reason ",
"searchText": "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", "timeoutUser": "uint128",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -141,13 +141,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz banned uint128. ", "messageText": "nerixyz banned uint128. ",
"searchText": "nerixyz banned uint128. ", "searchText": "nerixyz banned uint128. ",
"serverReceivedTime": "1970-01-01T00:00:00Z", "serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "uint128", "timeoutUser": "uint128",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -111,7 +111,7 @@
"loginName": "", "loginName": "",
"messageText": "nerixyz cleared the chat. ", "messageText": "nerixyz cleared the chat. ",
"searchText": "nerixyz cleared the chat. ", "searchText": "nerixyz cleared the chat. ",
"serverReceivedTime": "1970-01-01T00:00:00Z", "serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "nerixyz", "timeoutUser": "nerixyz",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -159,13 +159,13 @@
] ]
} }
], ],
"flags": "System|Timeout|DoNotTriggerNotification", "flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "testaccount_420", "loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…", "messageText": "testaccount_420 deleted message from testaccount_420 saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…",
"searchText": "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", "timeoutUser": "testaccount_420",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -159,13 +159,13 @@
] ]
} }
], ],
"flags": "System|Timeout|DoNotTriggerNotification", "flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "testaccount_420", "loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 saying: asd", "messageText": "testaccount_420 deleted message from testaccount_420 saying: asd",
"searchText": "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", "timeoutUser": "testaccount_420",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned off emote-only mode. ", "messageText": "nerixyz turned off emote-only mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned on emote-only mode. ", "messageText": "nerixyz turned on emote-only mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -57,7 +57,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -66,7 +66,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -150,13 +150,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned on followers-only mode. ", "messageText": "nerixyz turned on followers-only mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned off followers-only mode. ", "messageText": "nerixyz turned off followers-only mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -57,7 +57,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -66,7 +66,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -166,13 +166,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned on followers-only mode. (15 minutes) ", "messageText": "nerixyz turned on followers-only mode. (15 minutes) ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -191,13 +191,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz banned twitchdev in testaccount_420: a reason 😂 ", "messageText": "nerixyz banned twitchdev in testaccount_420: a reason 😂 ",
"searchText": "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", "timeoutUser": "twitchdev",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -174,13 +174,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz banned twitchdev in testaccount_420. ", "messageText": "nerixyz banned twitchdev in testaccount_420. ",
"searchText": "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", "timeoutUser": "twitchdev",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -192,13 +192,13 @@
] ]
} }
], ],
"flags": "System|Timeout|DoNotTriggerNotification", "flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "testaccount_420", "loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…", "messageText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…",
"searchText": "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", "timeoutUser": "testaccount_420",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -61,7 +61,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -70,7 +70,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -192,13 +192,13 @@
] ]
} }
], ],
"flags": "System|Timeout|DoNotTriggerNotification", "flags": "System|Timeout|DoNotTriggerNotification|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "testaccount_420", "loginName": "testaccount_420",
"messageText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: dfg", "messageText": "testaccount_420 deleted message from testaccount_420 in bajlada saying: dfg",
"searchText": "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", "timeoutUser": "testaccount_420",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -59,7 +59,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -68,7 +68,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -173,13 +173,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz unbanned uint128 in testaccount_420. ", "messageText": "nerixyz unbanned uint128 in testaccount_420. ",
"searchText": "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", "timeoutUser": "uint128",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned off slow mode. ", "messageText": "nerixyz turned off slow mode. ",
"searchText": "nerixyz turned off slow mode. ", "searchText": "nerixyz turned off slow mode. ",
"serverReceivedTime": "1970-01-01T00:00:00Z", "serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -57,7 +57,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -66,7 +66,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -166,13 +166,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned on slow mode. (10 seconds) ", "messageText": "nerixyz turned on slow mode. (10 seconds) ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned off subscribers-only mode. ", "messageText": "nerixyz turned off subscribers-only mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned on subscribers-only mode. ", "messageText": "nerixyz turned on subscribers-only mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -59,7 +59,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -68,7 +68,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -140,13 +140,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz unbanned uint128. ", "messageText": "nerixyz unbanned uint128. ",
"searchText": "nerixyz unbanned uint128. ", "searchText": "nerixyz unbanned uint128. ",
"serverReceivedTime": "1970-01-01T00:00:00Z", "serverReceivedTime": "2024-05-14T12:31:47Z",
"timeoutUser": "uint128", "timeoutUser": "uint128",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned off unique-chat mode. ", "messageText": "nerixyz turned off unique-chat mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -55,7 +55,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -64,7 +64,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -148,13 +148,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "nerixyz", "loginName": "nerixyz",
"messageText": "nerixyz turned on unique-chat mode. ", "messageText": "nerixyz turned on unique-chat mode. ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -159,13 +159,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "quotrok", "loginName": "quotrok",
"messageText": "quotrok has warned twitchdev: cut it out ", "messageText": "quotrok has warned twitchdev: cut it out ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
@@ -60,7 +60,7 @@
"trailingSpace": true, "trailingSpace": true,
"type": "TextElement", "type": "TextElement",
"words": [ "words": [
"0:00" "12:31"
] ]
}, },
"flags": "Timestamp", "flags": "Timestamp",
@@ -69,7 +69,7 @@
"type": "None", "type": "None",
"value": "" "value": ""
}, },
"time": "00:00:00", "time": "12:31:47",
"tooltip": "", "tooltip": "",
"trailingSpace": true, "trailingSpace": true,
"type": "TimestampElement" "type": "TimestampElement"
@@ -159,13 +159,13 @@
] ]
} }
], ],
"flags": "System|Timeout", "flags": "System|Timeout|EventSub",
"id": "", "id": "",
"localizedName": "", "localizedName": "",
"loginName": "quotrok", "loginName": "quotrok",
"messageText": "quotrok has warned twitchdev: cut it out ", "messageText": "quotrok has warned twitchdev: cut it out ",
"searchText": "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": "", "timeoutUser": "",
"userID": "", "userID": "",
"usernameColor": "#ff000000" "usernameColor": "#ff000000"
+22
View File
@@ -1,7 +1,11 @@
#include "util/Helpers.hpp" #include "util/Helpers.hpp"
#include "mocks/BaseApplication.hpp"
#include "Test.hpp" #include "Test.hpp"
#include <QDateTime>
#include <QTimeZone>
#include <span> #include <span>
using namespace chatterino; using namespace chatterino;
@@ -556,3 +560,21 @@ TEST(Helpers, unescapeZeroWidthJoiner)
EXPECT_EQ(actual, c.output); 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");
}