refactor: rename Badge to TwitchBadge (#6706)
this change is made to clarify that the previously-called Badge object is actually specialized for Twitch badges
This commit is contained in:
@@ -95,8 +95,8 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
|
||||
using MessageFlag = chatterino::MessageFlag;
|
||||
|
||||
QStringList badges;
|
||||
badges.reserve(m->badges.size());
|
||||
for (const auto &e : m->badges)
|
||||
badges.reserve(m->twitchBadges.size());
|
||||
for (const auto &e : m->twitchBadges)
|
||||
{
|
||||
badges << e.key_;
|
||||
}
|
||||
@@ -114,9 +114,9 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
|
||||
continue;
|
||||
}
|
||||
subscribed = true;
|
||||
if (m->badgeInfos.find(subBadge) != m->badgeInfos.end())
|
||||
if (m->twitchBadgeInfos.find(subBadge) != m->twitchBadgeInfos.end())
|
||||
{
|
||||
subLength = m->badgeInfos.at(subBadge).toInt();
|
||||
subLength = m->twitchBadgeInfos.at(subBadge).toInt();
|
||||
}
|
||||
}
|
||||
ContextMap vars = {
|
||||
|
||||
@@ -73,7 +73,7 @@ bool HighlightBadge::hasSound() const
|
||||
return this->hasSound_;
|
||||
}
|
||||
|
||||
bool HighlightBadge::isMatch(const Badge &badge) const
|
||||
bool HighlightBadge::isMatch(const TwitchBadge &badge) const
|
||||
{
|
||||
if (this->isMulti_)
|
||||
{
|
||||
@@ -92,7 +92,7 @@ bool HighlightBadge::isMatch(const Badge &badge) const
|
||||
}
|
||||
}
|
||||
|
||||
bool HighlightBadge::compare(const QString &id, const Badge &badge) const
|
||||
bool HighlightBadge::compare(const QString &id, const TwitchBadge &badge) const
|
||||
{
|
||||
if (this->hasVersions_)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Badge;
|
||||
class TwitchBadge;
|
||||
|
||||
class HighlightBadge
|
||||
{
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
bool showInMentions() const;
|
||||
bool hasAlert() const;
|
||||
bool hasSound() const;
|
||||
bool isMatch(const Badge &badge) const;
|
||||
bool isMatch(const TwitchBadge &badge) const;
|
||||
|
||||
/**
|
||||
* @brief Check if this highlight phrase has a custom sound set.
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
static QColor FALLBACK_HIGHLIGHT_COLOR;
|
||||
|
||||
private:
|
||||
bool compare(const QString &id, const Badge &badge) const;
|
||||
bool compare(const QString &id, const TwitchBadge &badge) const;
|
||||
|
||||
QString badgeName_;
|
||||
QString displayName_;
|
||||
|
||||
@@ -13,16 +13,17 @@ namespace chatterino {
|
||||
|
||||
struct HighlightResult;
|
||||
struct MessageParseArgs;
|
||||
class Badge;
|
||||
class TwitchBadge;
|
||||
|
||||
enum class MessageFlag : std::int64_t;
|
||||
using MessageFlags = FlagsEnum<MessageFlag>;
|
||||
|
||||
struct HighlightCheck {
|
||||
using Checker = std::function<std::optional<HighlightResult>(
|
||||
const MessageParseArgs &args, const std::vector<Badge> &badges,
|
||||
const QString &senderName, const QString &originalMessage,
|
||||
const MessageFlags &messageFlags, bool self)>;
|
||||
const MessageParseArgs &args,
|
||||
const std::vector<TwitchBadge> &twitchBadges, const QString &senderName,
|
||||
const QString &originalMessage, const MessageFlags &messageFlags,
|
||||
bool self)>;
|
||||
Checker cb;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@ using namespace chatterino;
|
||||
auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck
|
||||
{
|
||||
return HighlightCheck{
|
||||
[highlight](const auto &args, const auto &badges,
|
||||
[highlight](const auto &args, const auto &twitchBadges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
(void)args; // unused
|
||||
(void)badges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)flags; // unused
|
||||
(void)args; // unused
|
||||
(void)twitchBadges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)flags; // unused
|
||||
|
||||
if (self)
|
||||
{
|
||||
@@ -72,10 +72,11 @@ void rebuildSubscriptionHighlights(Settings &settings,
|
||||
// The custom sub highlight color is handled in ColorProvider
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto &args, const auto &badges, const auto &senderName,
|
||||
const auto &originalMessage, const auto &flags,
|
||||
[=](const auto &args, const auto &twitchBadges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
(void)badges; // unused
|
||||
(void)twitchBadges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
@@ -118,10 +119,11 @@ void rebuildWhisperHighlights(Settings &settings,
|
||||
// The custom whisper highlight color is handled in ColorProvider
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto &args, const auto &badges, const auto &senderName,
|
||||
const auto &originalMessage, const auto &flags,
|
||||
[=](const auto &args, const auto &twitchBadges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
(void)badges; // unused
|
||||
(void)twitchBadges; // unused
|
||||
(void)senderName; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
@@ -160,7 +162,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
|
||||
auto highlightInMentions =
|
||||
settings.showThreadHighlightInMentions.getValue();
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto & /*args*/, const auto & /*badges*/,
|
||||
[=](const auto & /*args*/, const auto & /*twitchBadges*/,
|
||||
const auto & /*senderName*/, const auto & /*originalMessage*/,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
@@ -218,7 +220,7 @@ void rebuildMessageHighlights(Settings &settings,
|
||||
ColorProvider::instance().color(ColorType::AutomodHighlight);
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[=](const auto & /*args*/, const auto & /*badges*/,
|
||||
[=](const auto & /*args*/, const auto & /*twitchBadges*/,
|
||||
const auto & /*senderName*/, const auto & /*originalMessage*/,
|
||||
const auto &flags,
|
||||
const auto /*self*/) -> std::optional<HighlightResult> {
|
||||
@@ -255,11 +257,12 @@ void rebuildUserHighlights(Settings &settings,
|
||||
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[showInMentions](
|
||||
const auto &args, const auto &badges, const auto &senderName,
|
||||
const auto &originalMessage, const auto &flags,
|
||||
const auto &args, const auto &twitchBadges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
(void)args; //unused
|
||||
(void)badges; //unused
|
||||
(void)twitchBadges; //unused
|
||||
(void)senderName; //unused
|
||||
(void)flags; //unused
|
||||
(void)originalMessage; //unused
|
||||
@@ -281,12 +284,12 @@ void rebuildUserHighlights(Settings &settings,
|
||||
for (const auto &highlight : *userHighlights)
|
||||
{
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[highlight](const auto &args, const auto &badges,
|
||||
[highlight](const auto &args, const auto &twitchBadges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
(void)args; // unused
|
||||
(void)badges; // unused
|
||||
(void)twitchBadges; // unused
|
||||
(void)originalMessage; // unused
|
||||
(void)flags; // unused
|
||||
(void)self; // unused
|
||||
@@ -321,7 +324,7 @@ void rebuildBadgeHighlights(Settings &settings,
|
||||
for (const auto &highlight : *badgeHighlights)
|
||||
{
|
||||
checks.emplace_back(HighlightCheck{
|
||||
[highlight](const auto &args, const auto &badges,
|
||||
[highlight](const auto &args, const auto &twitchBadges,
|
||||
const auto &senderName, const auto &originalMessage,
|
||||
const auto &flags,
|
||||
const auto self) -> std::optional<HighlightResult> {
|
||||
@@ -331,7 +334,7 @@ void rebuildBadgeHighlights(Settings &settings,
|
||||
(void)flags; // unused
|
||||
(void)self; // unused
|
||||
|
||||
for (const Badge &badge : badges)
|
||||
for (const TwitchBadge &badge : twitchBadges)
|
||||
{
|
||||
if (highlight.isMatch(badge))
|
||||
{
|
||||
@@ -460,7 +463,7 @@ void HighlightController::rebuildChecks(Settings &settings)
|
||||
}
|
||||
|
||||
std::pair<bool, HighlightResult> HighlightController::check(
|
||||
const MessageParseArgs &args, const std::vector<Badge> &badges,
|
||||
const MessageParseArgs &args, const std::vector<TwitchBadge> &twitchBadges,
|
||||
const QString &senderName, const QString &originalMessage,
|
||||
const MessageFlags &messageFlags) const
|
||||
{
|
||||
@@ -475,7 +478,7 @@ std::pair<bool, HighlightResult> HighlightController::check(
|
||||
|
||||
for (const auto &check : *checks)
|
||||
{
|
||||
if (auto checkResult = check.cb(args, badges, senderName,
|
||||
if (auto checkResult = check.cb(args, twitchBadges, senderName,
|
||||
originalMessage, messageFlags, self);
|
||||
checkResult)
|
||||
{
|
||||
|
||||
@@ -8,18 +8,17 @@
|
||||
#include <boost/signals2/connection.hpp>
|
||||
#include <pajlada/settings.hpp>
|
||||
#include <pajlada/settings/settinglistener.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
#include <QColor>
|
||||
#include <QUrl>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Badge;
|
||||
class TwitchBadge;
|
||||
struct MessageParseArgs;
|
||||
class AccountController;
|
||||
enum class MessageFlag : std::int64_t;
|
||||
@@ -34,9 +33,9 @@ public:
|
||||
* @brief Checks the given message parameters if it matches our internal checks, and returns a result
|
||||
**/
|
||||
[[nodiscard]] std::pair<bool, HighlightResult> check(
|
||||
const MessageParseArgs &args, const std::vector<Badge> &badges,
|
||||
const QString &senderName, const QString &originalMessage,
|
||||
const MessageFlags &messageFlags) const;
|
||||
const MessageParseArgs &args,
|
||||
const std::vector<TwitchBadge> &twitchBadges, const QString &senderName,
|
||||
const QString &originalMessage, const MessageFlags &messageFlags) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -118,19 +118,19 @@ QJsonObject Message::toJson() const
|
||||
{"frozen"_L1, this->frozen},
|
||||
};
|
||||
|
||||
QJsonArray badges;
|
||||
for (const auto &badge : this->badges)
|
||||
QJsonArray twitchBadges;
|
||||
for (const auto &badge : this->twitchBadges)
|
||||
{
|
||||
badges.append(badge.key_);
|
||||
twitchBadges.append(badge.key_);
|
||||
}
|
||||
msg["badges"_L1] = badges;
|
||||
msg["twitchBadges"_L1] = twitchBadges;
|
||||
|
||||
QJsonObject badgeInfos;
|
||||
for (const auto &[key, value] : this->badgeInfos)
|
||||
QJsonObject twitchBadgeInfos;
|
||||
for (const auto &[key, value] : this->twitchBadgeInfos)
|
||||
{
|
||||
badgeInfos.insert(key, value);
|
||||
twitchBadgeInfos.insert(key, value);
|
||||
}
|
||||
msg["badgeInfos"_L1] = badgeInfos;
|
||||
msg["twitchBadgeInfos"_L1] = twitchBadgeInfos;
|
||||
|
||||
if (this->highlightColor)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ class QJsonObject;
|
||||
namespace chatterino {
|
||||
class MessageElement;
|
||||
class MessageThread;
|
||||
class Badge;
|
||||
class TwitchBadge;
|
||||
class ScrollbarHighlight;
|
||||
|
||||
struct Message;
|
||||
@@ -54,8 +54,13 @@ struct Message {
|
||||
QString channelName;
|
||||
QColor usernameColor;
|
||||
QDateTime serverReceivedTime;
|
||||
std::vector<Badge> badges;
|
||||
std::unordered_map<QString, QString> badgeInfos;
|
||||
|
||||
/// List of Twitch badges associated with this message
|
||||
std::vector<TwitchBadge> twitchBadges;
|
||||
|
||||
/// Map of extra data associated with each Twitch badge
|
||||
std::unordered_map<QString, QString> twitchBadgeInfos;
|
||||
|
||||
std::shared_ptr<QColor> highlightColor;
|
||||
// Each reply holds a reference to the thread. When every reply is dropped,
|
||||
// the reply thread will be cleaned up by the TwitchChannel.
|
||||
|
||||
@@ -236,7 +236,7 @@ QString stylizeUsername(const QString &username, const Message &message)
|
||||
return usernameText;
|
||||
}
|
||||
|
||||
std::optional<EmotePtr> getTwitchBadge(const Badge &badge,
|
||||
std::optional<EmotePtr> getTwitchBadge(const TwitchBadge &badge,
|
||||
const TwitchChannel *twitchChannel)
|
||||
{
|
||||
if (auto channelBadge =
|
||||
@@ -254,7 +254,8 @@ std::optional<EmotePtr> getTwitchBadge(const Badge &badge,
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void appendBadges(MessageBuilder *builder, const std::vector<Badge> &badges,
|
||||
void appendBadges(MessageBuilder *builder,
|
||||
const std::vector<TwitchBadge> &badges,
|
||||
const std::unordered_map<QString, QString> &badgeInfos,
|
||||
const TwitchChannel *twitchChannel)
|
||||
{
|
||||
@@ -344,15 +345,15 @@ void appendBadges(MessageBuilder *builder, const std::vector<Badge> &badges,
|
||||
->setTooltip(tooltip);
|
||||
}
|
||||
|
||||
builder->message().badges = badges;
|
||||
builder->message().badgeInfos = badgeInfos;
|
||||
builder->message().twitchBadges = badges;
|
||||
builder->message().twitchBadgeInfos = badgeInfos;
|
||||
}
|
||||
|
||||
std::vector<Badge> appendSharedChatBadges(
|
||||
MessageBuilder *builder, const std::vector<Badge> &sharedBadges,
|
||||
std::vector<TwitchBadge> appendSharedChatBadges(
|
||||
MessageBuilder *builder, const std::vector<TwitchBadge> &sharedBadges,
|
||||
const QString &sharedChannelName, const TwitchChannel *twitchChannel)
|
||||
{
|
||||
auto appendedBadges = std::vector<Badge>{};
|
||||
auto appendedBadges = std::vector<TwitchBadge>{};
|
||||
for (const auto &badge : sharedBadges)
|
||||
{
|
||||
if (badge.key_ != "moderator" && badge.key_ != "vip")
|
||||
|
||||
@@ -33,7 +33,7 @@ BadgePredicate::BadgePredicate(const QString &badges, bool negate)
|
||||
|
||||
bool BadgePredicate::appliesToImpl(const Message &message)
|
||||
{
|
||||
for (const Badge &badge : message.badges)
|
||||
for (const TwitchBadge &badge : message.twitchBadges)
|
||||
{
|
||||
if (this->badges_.contains(badge.key_, Qt::CaseInsensitive))
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ SubtierPredicate::SubtierPredicate(const QString &subtiers, bool negate)
|
||||
|
||||
bool SubtierPredicate::appliesToImpl(const Message &message)
|
||||
{
|
||||
for (const Badge &badge : message.badges)
|
||||
for (const TwitchBadge &badge : message.twitchBadges)
|
||||
{
|
||||
if (badge.key_ == "subscriber")
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ const QSet<QString> channelAuthority{"lead_moderator", "moderator", "vip",
|
||||
"broadcaster"};
|
||||
const QSet<QString> subBadges{"subscriber", "founder"};
|
||||
|
||||
Badge::Badge(QString key, QString value)
|
||||
TwitchBadge::TwitchBadge(QString key, QString value)
|
||||
: key_(std::move(key))
|
||||
, value_(std::move(value))
|
||||
{
|
||||
@@ -34,7 +34,7 @@ Badge::Badge(QString key, QString value)
|
||||
}
|
||||
}
|
||||
|
||||
bool Badge::operator==(const Badge &other) const
|
||||
bool TwitchBadge::operator==(const TwitchBadge &other) const
|
||||
{
|
||||
return this->key_ == other.key_ && this->value_ == other.value_;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Badge
|
||||
class TwitchBadge
|
||||
{
|
||||
public:
|
||||
Badge(QString key, QString value);
|
||||
TwitchBadge(QString key, QString value);
|
||||
|
||||
bool operator==(const Badge &other) const;
|
||||
bool operator==(const TwitchBadge &other) const;
|
||||
|
||||
// Class members are fetched from both "badges" and "badge-info" tags
|
||||
// E.g.: "badges": "subscriber/18", "badge-info": "subscriber/22"
|
||||
|
||||
@@ -106,10 +106,10 @@ std::unordered_map<QString, QString> parseBadgeInfoTag(const QVariantMap &tags)
|
||||
return infoMap;
|
||||
}
|
||||
|
||||
std::vector<Badge> parseBadgeTag(const QVariantMap &tags,
|
||||
const QString &tagName)
|
||||
std::vector<TwitchBadge> parseBadgeTag(const QVariantMap &tags,
|
||||
const QString &tagName)
|
||||
{
|
||||
std::vector<Badge> b;
|
||||
std::vector<TwitchBadge> b;
|
||||
|
||||
auto badgesIt = tags.constFind(tagName);
|
||||
if (badgesIt == tags.end())
|
||||
@@ -127,7 +127,7 @@ std::vector<Badge> parseBadgeTag(const QVariantMap &tags,
|
||||
}
|
||||
|
||||
auto pair = slashKeyValue(badge);
|
||||
b.emplace_back(Badge{pair.first, pair.second});
|
||||
b.emplace_back(TwitchBadge{pair.first, pair.second});
|
||||
}
|
||||
|
||||
return b;
|
||||
|
||||
@@ -47,8 +47,8 @@ std::unordered_map<QString, QString> parseBadgeInfoTag(const QVariantMap &tags);
|
||||
/// @param tags The tags of the IRC message
|
||||
/// @param tagName The name of the tag to read badges from
|
||||
/// @returns A list of badges (name and version)
|
||||
std::vector<Badge> parseBadgeTag(const QVariantMap &tags,
|
||||
const QString &tagName = "badges");
|
||||
std::vector<TwitchBadge> parseBadgeTag(const QVariantMap &tags,
|
||||
const QString &tagName = "badges");
|
||||
|
||||
/// @brief Parses Twitch emotes in an IRC message
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user