2023-12-31 11:44:55 +01:00
|
|
|
#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
|
|
|
: typeString(root.value("type").toString())
|
|
|
|
{
|
|
|
|
if (const auto oType =
|
|
|
|
magic_enum::enum_cast<Type>(this->typeString.toStdString());
|
|
|
|
oType.has_value())
|
|
|
|
{
|
|
|
|
this->type = oType.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data = root.value("data").toObject();
|
|
|
|
|
|
|
|
if (this->type == Type::UserMessage)
|
|
|
|
{
|
|
|
|
this->msgID = data.value("message_id").toString();
|
|
|
|
this->sentAt = data.value("sent_at").toString();
|
2024-01-06 14:22:00 +01:00
|
|
|
const auto content = data.value("message_content").toObject();
|
|
|
|
this->text = content.value("text").toString();
|
|
|
|
for (const auto &part : content.value("fragments").toArray())
|
|
|
|
{
|
|
|
|
this->fragments.emplace_back(part.toObject());
|
|
|
|
}
|
2023-12-31 11:44:55 +01:00
|
|
|
|
|
|
|
// the rest of the data is within a nested object
|
|
|
|
data = data.value("low_trust_user").toObject();
|
|
|
|
|
|
|
|
const auto sender = data.value("sender").toObject();
|
|
|
|
this->suspiciousUserID = sender.value("user_id").toString();
|
|
|
|
this->suspiciousUserLogin = sender.value("login").toString();
|
|
|
|
this->suspiciousUserDisplayName =
|
|
|
|
sender.value("display_name").toString();
|
|
|
|
this->suspiciousUserColor =
|
|
|
|
QColor(sender.value("chat_color").toString());
|
|
|
|
|
|
|
|
for (const auto &badge : sender.value("badges").toArray())
|
|
|
|
{
|
2024-01-06 14:22:00 +01:00
|
|
|
const auto badgeObj = badge.toObject();
|
|
|
|
const auto badgeID = badgeObj.value("id").toString();
|
|
|
|
const auto badgeVersion = badgeObj.value("version").toString();
|
|
|
|
this->senderBadges.emplace_back(Badge{badgeID, badgeVersion});
|
2023-12-31 11:44:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto sharedValue = data.value("shared_ban_channel_ids");
|
|
|
|
if (!sharedValue.isNull())
|
|
|
|
{
|
|
|
|
for (const auto &id : sharedValue.toArray())
|
|
|
|
{
|
2024-01-06 14:22:00 +01:00
|
|
|
this->sharedBanChannelIDs.emplace_back(id.toString());
|
2023-12-31 11:44:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->suspiciousUserID = data.value("target_user_id").toString();
|
|
|
|
this->suspiciousUserLogin = data.value("target_user").toString();
|
|
|
|
this->suspiciousUserDisplayName = this->suspiciousUserLogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->channelID = data.value("channel_id").toString();
|
|
|
|
this->updatedAtString = data.value("updated_at").toString();
|
|
|
|
this->updatedAt = QDateTime::fromString(this->updatedAtString, Qt::ISODate)
|
|
|
|
.toLocalTime()
|
|
|
|
.toString("MMM d yyyy, h:mm ap");
|
|
|
|
|
|
|
|
const auto updatedBy = data.value("updated_by").toObject();
|
|
|
|
this->updatedByUserID = updatedBy.value("id").toString();
|
|
|
|
this->updatedByUserLogin = updatedBy.value("login").toString();
|
|
|
|
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());
|
|
|
|
oTreatment.has_value())
|
|
|
|
{
|
|
|
|
this->treatment = oTreatment.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
this->evasionEvaluationString =
|
|
|
|
data.value("ban_evasion_evaluation").toString();
|
|
|
|
if (const auto oEvaluation = magic_enum::enum_cast<EvasionEvaluation>(
|
|
|
|
this->evasionEvaluationString.toStdString());
|
|
|
|
oEvaluation.has_value())
|
|
|
|
{
|
|
|
|
this->evasionEvaluation = oEvaluation.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &rType : data.value("types").toArray())
|
|
|
|
{
|
|
|
|
if (const auto oRestriction = magic_enum::enum_cast<RestrictionType>(
|
|
|
|
rType.toString().toStdString());
|
|
|
|
oRestriction.has_value())
|
|
|
|
{
|
2024-01-06 14:22:00 +01:00
|
|
|
this->restrictionTypes.set(oRestriction.value());
|
2023-12-31 11:44:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|