feat(eventsub): use special flag and timestamps from metadata (#5996)
This commit is contained in:
@@ -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),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user