refactor: adapt magic_enum to Qt (#5258)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user