refactor: adapt magic_enum to Qt (#5258)
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "providers/seventv/eventapi/Message.hpp"
|
||||
#include "providers/seventv/SeventvBadges.hpp"
|
||||
#include "providers/seventv/SeventvCosmetics.hpp"
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
@@ -228,7 +229,7 @@ void SeventvEventAPI::handleDispatch(const Dispatch &dispatch)
|
||||
default: {
|
||||
qCDebug(chatterinoSeventvEventAPI)
|
||||
<< "Unknown subscription type:"
|
||||
<< magic_enum::enum_name(dispatch.type).data()
|
||||
<< qmagicenum::enumName(dispatch.type)
|
||||
<< "body:" << dispatch.body;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/seventv/eventapi/Dispatch.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
#include <utility>
|
||||
@@ -7,8 +9,7 @@
|
||||
namespace chatterino::seventv::eventapi {
|
||||
|
||||
Dispatch::Dispatch(QJsonObject obj)
|
||||
: type(magic_enum::enum_cast<SubscriptionType>(
|
||||
obj["type"].toString().toStdString())
|
||||
: type(qmagicenum::enumCast<SubscriptionType>(obj["type"].toString())
|
||||
.value_or(SubscriptionType::INVALID))
|
||||
, body(obj["body"].toObject())
|
||||
, id(this->body["id"].toString())
|
||||
@@ -95,8 +96,8 @@ bool UserConnectionUpdateDispatch::validate() const
|
||||
|
||||
CosmeticCreateDispatch::CosmeticCreateDispatch(const Dispatch &dispatch)
|
||||
: data(dispatch.body["object"]["data"].toObject())
|
||||
, kind(magic_enum::enum_cast<CosmeticKind>(
|
||||
dispatch.body["object"]["kind"].toString().toStdString())
|
||||
, kind(qmagicenum::enumCast<CosmeticKind>(
|
||||
dispatch.body["object"]["kind"].toString())
|
||||
.value_or(CosmeticKind::INVALID))
|
||||
{
|
||||
}
|
||||
@@ -111,8 +112,7 @@ EntitlementCreateDeleteDispatch::EntitlementCreateDeleteDispatch(
|
||||
{
|
||||
const auto obj = dispatch.body["object"].toObject();
|
||||
this->refID = obj["ref_id"].toString();
|
||||
this->kind = magic_enum::enum_cast<CosmeticKind>(
|
||||
obj["kind"].toString().toStdString())
|
||||
this->kind = qmagicenum::enumCast<CosmeticKind>(obj["kind"].toString())
|
||||
.value_or(CosmeticKind::INVALID);
|
||||
|
||||
const auto userConnections = obj["user"]["connections"].toArray();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/seventv/eventapi/Subscription.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@@ -9,14 +11,15 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace chatterino;
|
||||
using namespace chatterino::seventv::eventapi;
|
||||
|
||||
const char *typeToString(SubscriptionType type)
|
||||
QString typeToString(SubscriptionType type)
|
||||
{
|
||||
return magic_enum::enum_name(type).data();
|
||||
return qmagicenum::enumNameString(type);
|
||||
}
|
||||
|
||||
QJsonObject createDataJson(const char *typeName, const Condition &condition)
|
||||
QJsonObject createDataJson(const QString &typeName, const Condition &condition)
|
||||
{
|
||||
QJsonObject data;
|
||||
data["type"] = typeName;
|
||||
@@ -45,7 +48,7 @@ bool Subscription::operator!=(const Subscription &rhs) const
|
||||
|
||||
QByteArray Subscription::encodeSubscribe() const
|
||||
{
|
||||
const auto *typeName = typeToString(this->type);
|
||||
auto typeName = typeToString(this->type);
|
||||
QJsonObject root;
|
||||
root["op"] = (int)Opcode::Subscribe;
|
||||
root["d"] = createDataJson(typeName, this->condition);
|
||||
@@ -54,7 +57,7 @@ QByteArray Subscription::encodeSubscribe() const
|
||||
|
||||
QByteArray Subscription::encodeUnsubscribe() const
|
||||
{
|
||||
const auto *typeName = typeToString(this->type);
|
||||
auto typeName = typeToString(this->type);
|
||||
QJsonObject root;
|
||||
root["op"] = (int)Opcode::Unsubscribe;
|
||||
root["d"] = createDataJson(typeName, this->condition);
|
||||
@@ -66,8 +69,7 @@ QDebug &operator<<(QDebug &dbg, const Subscription &subscription)
|
||||
std::visit(
|
||||
[&](const auto &cond) {
|
||||
dbg << "Subscription{ condition:" << cond
|
||||
<< "type:" << magic_enum::enum_name(subscription.type).data()
|
||||
<< '}';
|
||||
<< "type:" << qmagicenum::enumName(subscription.type) << '}';
|
||||
},
|
||||
subscription.condition);
|
||||
return dbg;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "common/network/NetworkResult.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "util/CancellationToken.hpp"
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <QJsonDocument>
|
||||
@@ -1172,9 +1173,7 @@ void Helix::sendChatAnnouncement(
|
||||
|
||||
QJsonObject body;
|
||||
body.insert("message", message);
|
||||
const auto colorStr =
|
||||
std::string{magic_enum::enum_name<HelixAnnouncementColor>(color)};
|
||||
body.insert("color", QString::fromStdString(colorStr).toLower());
|
||||
body.insert("color", qmagicenum::enumNameString(color).toLower());
|
||||
|
||||
this->makePost("chat/announcements", urlQuery)
|
||||
.json(body)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/twitch/pubsubmessages/AutoMod.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root)
|
||||
@@ -7,7 +9,7 @@ PubSubAutoModQueueMessage::PubSubAutoModQueueMessage(const QJsonObject &root)
|
||||
, data(root.value("data").toObject())
|
||||
, status(this->data.value("status").toString())
|
||||
{
|
||||
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
||||
auto oType = qmagicenum::enumCast<Type>(this->typeString);
|
||||
if (oType.has_value())
|
||||
{
|
||||
this->type = oType.value();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/twitch/pubsubmessages/Base.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
PubSubMessage::PubSubMessage(QJsonObject _object)
|
||||
@@ -9,7 +11,7 @@ PubSubMessage::PubSubMessage(QJsonObject _object)
|
||||
, error(this->object.value("error").toString())
|
||||
, typeString(this->object.value("type").toString())
|
||||
{
|
||||
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
||||
auto oType = qmagicenum::enumCast<Type>(this->typeString);
|
||||
if (oType.has_value())
|
||||
{
|
||||
this->type = oType.value();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/twitch/pubsubmessages/ChannelPoints.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
PubSubCommunityPointsChannelV1Message::PubSubCommunityPointsChannelV1Message(
|
||||
@@ -7,7 +9,7 @@ PubSubCommunityPointsChannelV1Message::PubSubCommunityPointsChannelV1Message(
|
||||
: typeString(root.value("type").toString())
|
||||
, data(root.value("data").toObject())
|
||||
{
|
||||
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
||||
auto oType = qmagicenum::enumCast<Type>(this->typeString);
|
||||
if (oType.has_value())
|
||||
{
|
||||
this->type = oType.value();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/twitch/pubsubmessages/ChatModeratorAction.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
PubSubChatModeratorActionMessage::PubSubChatModeratorActionMessage(
|
||||
@@ -7,7 +9,7 @@ PubSubChatModeratorActionMessage::PubSubChatModeratorActionMessage(
|
||||
: typeString(root.value("type").toString())
|
||||
, data(root.value("data").toObject())
|
||||
{
|
||||
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
||||
auto oType = qmagicenum::enumCast<Type>(this->typeString);
|
||||
if (oType.has_value())
|
||||
{
|
||||
this->type = oType.value();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonArray>
|
||||
|
||||
@@ -8,8 +10,7 @@ namespace chatterino {
|
||||
PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
: typeString(root.value("type").toString())
|
||||
{
|
||||
if (const auto oType =
|
||||
magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
||||
if (const auto oType = qmagicenum::enumCast<Type>(this->typeString);
|
||||
oType.has_value())
|
||||
{
|
||||
this->type = oType.value();
|
||||
@@ -75,8 +76,8 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
this->updatedByUserDisplayName = updatedBy.value("display_name").toString();
|
||||
|
||||
this->treatmentString = data.value("treatment").toString();
|
||||
if (const auto oTreatment = magic_enum::enum_cast<Treatment>(
|
||||
this->treatmentString.toStdString());
|
||||
if (const auto oTreatment =
|
||||
qmagicenum::enumCast<Treatment>(this->treatmentString);
|
||||
oTreatment.has_value())
|
||||
{
|
||||
this->treatment = oTreatment.value();
|
||||
@@ -84,8 +85,8 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
|
||||
this->evasionEvaluationString =
|
||||
data.value("ban_evasion_evaluation").toString();
|
||||
if (const auto oEvaluation = magic_enum::enum_cast<EvasionEvaluation>(
|
||||
this->evasionEvaluationString.toStdString());
|
||||
if (const auto oEvaluation = qmagicenum::enumCast<EvasionEvaluation>(
|
||||
this->evasionEvaluationString);
|
||||
oEvaluation.has_value())
|
||||
{
|
||||
this->evasionEvaluation = oEvaluation.value();
|
||||
@@ -93,8 +94,8 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
|
||||
for (const auto &rType : data.value("types").toArray())
|
||||
{
|
||||
if (const auto oRestriction = magic_enum::enum_cast<RestrictionType>(
|
||||
rType.toString().toStdString());
|
||||
if (const auto oRestriction =
|
||||
qmagicenum::enumCast<RestrictionType>(rType.toString());
|
||||
oRestriction.has_value())
|
||||
{
|
||||
this->restrictionTypes.set(oRestriction.value());
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "providers/twitch/pubsubmessages/Whisper.hpp"
|
||||
|
||||
#include "util/QMagicEnum.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
PubSubWhisperMessage::PubSubWhisperMessage(const QJsonObject &root)
|
||||
: typeString(root.value("type").toString())
|
||||
{
|
||||
auto oType = magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
||||
auto oType = qmagicenum::enumCast<Type>(this->typeString);
|
||||
if (oType.has_value())
|
||||
{
|
||||
this->type = oType.value();
|
||||
|
||||
Reference in New Issue
Block a user