feat: add badges, emotes, and filters for suspicious messages (#5060)
* feat: show chat badges on suspicious user messages * feat: display emotes in suspicious user messages * feat: add search filters for suspicious messages * chore: update changelog * refactor: resolve initial nits * fix: finish adding new filter identifier * Comment the new message flags * Add a list of known issues to low trust update messages * fix: Keep shared-pointerness of the channel Without this change, we would have the possibility of using the TwitchChannel after the Channel itself has gone out of scope, albeit not realistically since we just post this to a thread and parse it - there's no networking or big delays involved. but this shows the intent better --------- Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -21,8 +21,12 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
{
|
||||
this->msgID = data.value("message_id").toString();
|
||||
this->sentAt = data.value("sent_at").toString();
|
||||
this->text =
|
||||
data.value("message_content").toObject().value("text").toString();
|
||||
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());
|
||||
}
|
||||
|
||||
// the rest of the data is within a nested object
|
||||
data = data.value("low_trust_user").toObject();
|
||||
@@ -35,23 +39,22 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
this->suspiciousUserColor =
|
||||
QColor(sender.value("chat_color").toString());
|
||||
|
||||
std::vector<LowTrustUserChatBadge> badges;
|
||||
for (const auto &badge : sender.value("badges").toArray())
|
||||
{
|
||||
badges.emplace_back(badge.toObject());
|
||||
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});
|
||||
}
|
||||
this->senderBadges = badges;
|
||||
|
||||
const auto sharedValue = data.value("shared_ban_channel_ids");
|
||||
std::vector<QString> sharedIDs;
|
||||
if (!sharedValue.isNull())
|
||||
{
|
||||
for (const auto &id : sharedValue.toArray())
|
||||
{
|
||||
sharedIDs.emplace_back(id.toString());
|
||||
this->sharedBanChannelIDs.emplace_back(id.toString());
|
||||
}
|
||||
}
|
||||
this->sharedBanChannelIDs = sharedIDs;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,17 +91,15 @@ PubSubLowTrustUsersMessage::PubSubLowTrustUsersMessage(const QJsonObject &root)
|
||||
this->evasionEvaluation = oEvaluation.value();
|
||||
}
|
||||
|
||||
FlagsEnum<RestrictionType> restrictions;
|
||||
for (const auto &rType : data.value("types").toArray())
|
||||
{
|
||||
if (const auto oRestriction = magic_enum::enum_cast<RestrictionType>(
|
||||
rType.toString().toStdString());
|
||||
oRestriction.has_value())
|
||||
{
|
||||
restrictions.set(oRestriction.value());
|
||||
this->restrictionTypes.set(oRestriction.value());
|
||||
}
|
||||
}
|
||||
this->restrictionTypes = restrictions;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "providers/twitch/TwitchBadge.hpp"
|
||||
|
||||
#include <common/FlagsEnum.hpp>
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <QColor>
|
||||
@@ -8,18 +10,21 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct LowTrustUserChatBadge {
|
||||
QString id;
|
||||
QString version;
|
||||
|
||||
explicit LowTrustUserChatBadge(const QJsonObject &obj)
|
||||
: id(obj.value("id").toString())
|
||||
, version(obj.value("version").toString())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct PubSubLowTrustUsersMessage {
|
||||
struct Fragment {
|
||||
QString text;
|
||||
QString emoteID;
|
||||
|
||||
explicit Fragment(const QJsonObject &obj)
|
||||
: text(obj.value("text").toString())
|
||||
, emoteID(obj.value("emoticon")
|
||||
.toObject()
|
||||
.value("emoticonID")
|
||||
.toString())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The type of low trust message update
|
||||
*/
|
||||
@@ -102,6 +107,12 @@ struct PubSubLowTrustUsersMessage {
|
||||
*/
|
||||
QString text;
|
||||
|
||||
/**
|
||||
* Pre-parsed components of the message.
|
||||
* Only used for the UserMessage type.
|
||||
*/
|
||||
std::vector<Fragment> fragments;
|
||||
|
||||
/**
|
||||
* ID of the message.
|
||||
* Only used for the UserMessage type.
|
||||
@@ -130,7 +141,7 @@ struct PubSubLowTrustUsersMessage {
|
||||
* A list of badges of the user who sent the message.
|
||||
* Only used for the UserMessage type.
|
||||
*/
|
||||
std::vector<LowTrustUserChatBadge> senderBadges;
|
||||
std::vector<Badge> senderBadges;
|
||||
|
||||
/**
|
||||
* Stores the string value of `type`
|
||||
|
||||
Reference in New Issue
Block a user