diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f9c4316..0bde2cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/messages/metadata.hpp b/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/messages/metadata.hpp index cd603851..ade7f74f 100644 --- a/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/messages/metadata.hpp +++ b/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/messages/metadata.hpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -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 subscriptionType; std::optional subscriptionVersion; diff --git a/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp b/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp index 815e72b3..d9aa2bf8 100644 --- a/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp +++ b/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp @@ -44,6 +44,8 @@ boost::json::result_for::type tag_invoke( return messageType.error(); } + static_assert(std::is_trivially_copyable_v().messageTimestamp)>>); const auto *jvmessageTimestamp = root.if_contains("message_timestamp"); if (jvmessageTimestamp == nullptr) { @@ -51,7 +53,8 @@ boost::json::result_for::type tag_invoke( } auto messageTimestamp = - boost::json::try_value_to(*jvmessageTimestamp); + boost::json::try_value_to( + *jvmessageTimestamp, AsISO8601()); if (messageTimestamp.has_error()) { @@ -90,7 +93,7 @@ boost::json::result_for::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), }; diff --git a/src/messages/MessageFlag.hpp b/src/messages/MessageFlag.hpp index 317cf5a9..8923856d 100644 --- a/src/messages/MessageFlag.hpp +++ b/src/messages/MessageFlag.hpp @@ -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; diff --git a/src/providers/twitch/eventsub/Connection.cpp b/src/providers/twitch/eventsub/Connection.cpp index 1b2ae43c..c18a048a 100644 --- a/src/providers/twitch/eventsub/Connection.cpp +++ b/src/providers/twitch/eventsub/Connection.cpp @@ -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 @@ -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) { diff --git a/src/providers/twitch/eventsub/MessageBuilder.cpp b/src/providers/twitch/eventsub/MessageBuilder.cpp index 29495536..da11a5f6 100644 --- a/src/providers/twitch/eventsub/MessageBuilder.cpp +++ b/src/providers/twitch/eventsub/MessageBuilder.cpp @@ -41,8 +41,8 @@ EventSubMessageBuilder::EventSubMessageBuilder(TwitchChannel *channel, const QDateTime &time) : channel(channel) { - this->emplace(); - this->message().flags.set(MessageFlag::System); + this->emplace(time.time()); + this->message().flags.set(MessageFlag::System, MessageFlag::EventSub); this->message().flags.set(MessageFlag::Timeout); // do we need this? this->message().serverReceivedTime = time; } diff --git a/src/util/Helpers.cpp b/src/util/Helpers.cpp index 4df84739..5e3780dd 100644 --- a/src/util/Helpers.cpp +++ b/src/util/Helpers.cpp @@ -3,9 +3,11 @@ #include "Application.hpp" #include "providers/twitch/TwitchCommon.hpp" +#include #include #include #include +#include #include 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(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 diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp index 5ea221f2..d079a7d7 100644 --- a/src/util/Helpers.hpp +++ b/src/util/Helpers.hpp @@ -4,11 +4,14 @@ #include #include +#include #include #include #include #include +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 diff --git a/tests/snapshots/EventSub/channel-moderate/ban-reason.json b/tests/snapshots/EventSub/channel-moderate/ban-reason.json index afdb8aaa..f4556cc9 100644 --- a/tests/snapshots/EventSub/channel-moderate/ban-reason.json +++ b/tests/snapshots/EventSub/channel-moderate/ban-reason.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/ban.json b/tests/snapshots/EventSub/channel-moderate/ban.json index 0298e650..43785d63 100644 --- a/tests/snapshots/EventSub/channel-moderate/ban.json +++ b/tests/snapshots/EventSub/channel-moderate/ban.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/clear.json b/tests/snapshots/EventSub/channel-moderate/clear.json index 8f10e386..29df6d01 100644 --- a/tests/snapshots/EventSub/channel-moderate/clear.json +++ b/tests/snapshots/EventSub/channel-moderate/clear.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/delete-long.json b/tests/snapshots/EventSub/channel-moderate/delete-long.json index 9f4beedf..90c6814e 100644 --- a/tests/snapshots/EventSub/channel-moderate/delete-long.json +++ b/tests/snapshots/EventSub/channel-moderate/delete-long.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/delete.json b/tests/snapshots/EventSub/channel-moderate/delete.json index fb5bc363..13dcdac6 100644 --- a/tests/snapshots/EventSub/channel-moderate/delete.json +++ b/tests/snapshots/EventSub/channel-moderate/delete.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/emoteonly-off.json b/tests/snapshots/EventSub/channel-moderate/emoteonly-off.json index 2e6a57c7..4209178c 100644 --- a/tests/snapshots/EventSub/channel-moderate/emoteonly-off.json +++ b/tests/snapshots/EventSub/channel-moderate/emoteonly-off.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/emoteonly.json b/tests/snapshots/EventSub/channel-moderate/emoteonly.json index d253223d..d4f563f8 100644 --- a/tests/snapshots/EventSub/channel-moderate/emoteonly.json +++ b/tests/snapshots/EventSub/channel-moderate/emoteonly.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/followers-0s.json b/tests/snapshots/EventSub/channel-moderate/followers-0s.json index dad868f3..3d81109e 100644 --- a/tests/snapshots/EventSub/channel-moderate/followers-0s.json +++ b/tests/snapshots/EventSub/channel-moderate/followers-0s.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/followers-off.json b/tests/snapshots/EventSub/channel-moderate/followers-off.json index fa646bc7..f3d47934 100644 --- a/tests/snapshots/EventSub/channel-moderate/followers-off.json +++ b/tests/snapshots/EventSub/channel-moderate/followers-off.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/followers.json b/tests/snapshots/EventSub/channel-moderate/followers.json index 361840d0..6929753d 100644 --- a/tests/snapshots/EventSub/channel-moderate/followers.json +++ b/tests/snapshots/EventSub/channel-moderate/followers.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/shared-ban-reason.json b/tests/snapshots/EventSub/channel-moderate/shared-ban-reason.json index 908c6b32..4c75af18 100644 --- a/tests/snapshots/EventSub/channel-moderate/shared-ban-reason.json +++ b/tests/snapshots/EventSub/channel-moderate/shared-ban-reason.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/shared-ban.json b/tests/snapshots/EventSub/channel-moderate/shared-ban.json index 43334455..577e352f 100644 --- a/tests/snapshots/EventSub/channel-moderate/shared-ban.json +++ b/tests/snapshots/EventSub/channel-moderate/shared-ban.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/shared-delete-long.json b/tests/snapshots/EventSub/channel-moderate/shared-delete-long.json index 4cf8c72e..d256e198 100644 --- a/tests/snapshots/EventSub/channel-moderate/shared-delete-long.json +++ b/tests/snapshots/EventSub/channel-moderate/shared-delete-long.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/shared-delete.json b/tests/snapshots/EventSub/channel-moderate/shared-delete.json index f2b6403d..678ca4a7 100644 --- a/tests/snapshots/EventSub/channel-moderate/shared-delete.json +++ b/tests/snapshots/EventSub/channel-moderate/shared-delete.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/shared-unban.json b/tests/snapshots/EventSub/channel-moderate/shared-unban.json index 8fe240bf..4026208f 100644 --- a/tests/snapshots/EventSub/channel-moderate/shared-unban.json +++ b/tests/snapshots/EventSub/channel-moderate/shared-unban.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/slow-off.json b/tests/snapshots/EventSub/channel-moderate/slow-off.json index 0900e00a..b5a74f1e 100644 --- a/tests/snapshots/EventSub/channel-moderate/slow-off.json +++ b/tests/snapshots/EventSub/channel-moderate/slow-off.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/slow.json b/tests/snapshots/EventSub/channel-moderate/slow.json index 5dfa26cb..dcd3132a 100644 --- a/tests/snapshots/EventSub/channel-moderate/slow.json +++ b/tests/snapshots/EventSub/channel-moderate/slow.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/subscribers-off.json b/tests/snapshots/EventSub/channel-moderate/subscribers-off.json index 92de568d..1dc59e43 100644 --- a/tests/snapshots/EventSub/channel-moderate/subscribers-off.json +++ b/tests/snapshots/EventSub/channel-moderate/subscribers-off.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/subscribers.json b/tests/snapshots/EventSub/channel-moderate/subscribers.json index dcd7224d..4616b65e 100644 --- a/tests/snapshots/EventSub/channel-moderate/subscribers.json +++ b/tests/snapshots/EventSub/channel-moderate/subscribers.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/unban.json b/tests/snapshots/EventSub/channel-moderate/unban.json index 9a33e399..f5b8f607 100644 --- a/tests/snapshots/EventSub/channel-moderate/unban.json +++ b/tests/snapshots/EventSub/channel-moderate/unban.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/uniquechat-off.json b/tests/snapshots/EventSub/channel-moderate/uniquechat-off.json index 43ab3354..d3db2f08 100644 --- a/tests/snapshots/EventSub/channel-moderate/uniquechat-off.json +++ b/tests/snapshots/EventSub/channel-moderate/uniquechat-off.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/uniquechat.json b/tests/snapshots/EventSub/channel-moderate/uniquechat.json index 15e398b5..5ea4cdfd 100644 --- a/tests/snapshots/EventSub/channel-moderate/uniquechat.json +++ b/tests/snapshots/EventSub/channel-moderate/uniquechat.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/warn-shared.json b/tests/snapshots/EventSub/channel-moderate/warn-shared.json index 41095094..dcf5daba 100644 --- a/tests/snapshots/EventSub/channel-moderate/warn-shared.json +++ b/tests/snapshots/EventSub/channel-moderate/warn-shared.json @@ -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" diff --git a/tests/snapshots/EventSub/channel-moderate/warn.json b/tests/snapshots/EventSub/channel-moderate/warn.json index fc067443..91412ee3 100644 --- a/tests/snapshots/EventSub/channel-moderate/warn.json +++ b/tests/snapshots/EventSub/channel-moderate/warn.json @@ -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" diff --git a/tests/src/Helpers.cpp b/tests/src/Helpers.cpp index c2cf5694..ab4b1e1a 100644 --- a/tests/src/Helpers.cpp +++ b/tests/src/Helpers.cpp @@ -1,7 +1,11 @@ #include "util/Helpers.hpp" +#include "mocks/BaseApplication.hpp" #include "Test.hpp" +#include +#include + #include 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"); +}