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