refactor: Move uncategorized notifications to their own message flag (#7038)

This commit is contained in:
pajlada
2026-06-13 14:48:02 +02:00
committed by GitHub
parent 01f50a3bc9
commit 1ca16ec1a4
13 changed files with 88 additions and 36 deletions
+15 -3
View File
@@ -1707,10 +1707,22 @@ std::pair<MessagePtrMut, HighlightAlert> MessageBuilder::makeIrcMessage(
builder->flags.set(MessageFlag::Disabled);
}
if (tags.contains("msg-id") &&
tags["msg-id"].toString().split(';').contains("highlighted-message"))
auto msgIdIt = tags.constFind("msg-id");
if (msgIdIt != tags.constEnd())
{
builder->flags.set(MessageFlag::RedeemedHighlight);
// TODO: Why do we have to split this into a list?
auto msgIdTypes = msgIdIt->toString().split(';');
if (msgIdTypes.contains("highlighted-message"))
{
builder->flags.set(MessageFlag::RedeemedHighlight);
}
if (msgIdTypes.contains("viewermilestone") ||
msgIdTypes.contains("modiversary"))
{
builder->flags.set(MessageFlag::WatchStreak);
}
}
if (tags.contains("first-msg") && tags["first-msg"].toString() == "1")
+2
View File
@@ -78,6 +78,8 @@ enum class MessageFlag : std::int64_t {
InvalidReplyTarget = (1LL << 42),
WatchStreak = (1LL << 43),
Announcement = (1LL << 44),
/// Notifications that do not yet have special handling/categorization
UncategorizedNotification = (1LL << 45),
};
using MessageFlags = FlagsEnum<MessageFlag>;
+6
View File
@@ -465,6 +465,12 @@ void MessageLayout::updateBuffer(QPixmap *buffer,
{
backgroundColor = QColor("#4A273D");
}
else if (this->message_->flags.has(MessageFlag::UncategorizedNotification))
{
// TODO: Give this a better/its own color :-)
backgroundColor = blendColors(
backgroundColor, *ctx.colorProvider.color(ColorType::Subscription));
}
painter.fillRect(buffer->rect(), backgroundColor);
+51 -22
View File
@@ -57,6 +57,26 @@ const QSet<QString> SPECIAL_MESSAGE_TYPES{
"socialsharingbadge", // social media badge from sharing clips
};
/// Message types that we know and should explicitly not set as uncategorized because their message flag
/// gets set to a reasonable value elsewhere
const QSet<QString> KNOWN_MESSAGE_TYPES{
"viewermilestone", // watch streak, but other categories possible in future
"modiversary", // Mod anniversary.
"sub", //
"subgift", //
"resub", // resub messages
"bitsbadgetier", // bits badge upgrade
"ritual", // new viewer ritual
"announcement", // new mod announcement thing
};
/// MessageFlag::Subscription message types
const QSet<QString> SUB_MESSAGE_TYPES{
"sub", //
"subgift", //
"resub", // resub messages
};
const QString ANONYMOUS_GIFTER_ID = "274598607";
MessagePtr generateBannedMessage(bool confirmedBan)
@@ -427,9 +447,12 @@ void IrcMessageHandler::parsePrivMessageInto(
}
}
IrcMessageHandler::addMessage(
message, sink, channel, unescapeZeroWidthJoiner(message->content()),
*getApp()->getTwitch(), false, message->isAction());
IrcMessageHandler::addMessage(message, sink, channel,
unescapeZeroWidthJoiner(message->content()),
*getApp()->getTwitch(),
{
.isAction = message->isAction(),
});
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
{
@@ -781,7 +804,11 @@ void IrcMessageHandler::parseUserNoticeMessageInto(Communi::IrcMessage *message,
if (!content.isEmpty())
{
addMessage(message, sink, channel, content, *getApp()->getTwitch(),
true, false, msgType);
{
.isSub = SUB_MESSAGE_TYPES.contains(msgType),
.isSpecial = true,
},
msgType);
}
}
@@ -947,10 +974,14 @@ void IrcMessageHandler::parseUserNoticeMessageInto(Communi::IrcMessage *message,
.value_or(HelixAnnouncementColor::Primary);
}
}
else
else if (SUB_MESSAGE_TYPES.contains(msgType))
{
msg->flags.set(MessageFlag::Subscription);
}
else
{
msg->flags.set(MessageFlag::UncategorizedNotification);
}
if (mirrored)
{
@@ -1139,15 +1170,19 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
MessageSink &sink, TwitchChannel *chan,
const QString &originalContent,
ITwitchIrcServer &twitch, bool isSub,
bool isAction, const QString &msgType)
ITwitchIrcServer &twitch,
AddMessageArgs addArgs,
const QString &msgType)
{
assert(chan);
auto isSub = addArgs.isSub;
auto isAction = addArgs.isAction;
MessageParseArgs args;
if (isSub)
args.isSubscriptionMessage = isSub;
if (addArgs.isSpecial)
{
args.isSubscriptionMessage = msgType != "announcement";
args.trimSubscriberUsername = true;
}
@@ -1264,11 +1299,11 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
{
if (isSub)
{
if (msgType == "viewermilestone" || msgType == "modiversary")
{
msg->flags.set(MessageFlag::WatchStreak);
}
else if (msgType == "announcement")
msg->flags.set(MessageFlag::Subscription);
}
else if (addArgs.isSpecial)
{
if (msgType == "announcement")
{
msg->flags.set(MessageFlag::Announcement);
@@ -1280,15 +1315,9 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
.value_or(HelixAnnouncementColor::Primary);
}
}
else
else if (!KNOWN_MESSAGE_TYPES.contains(msgType))
{
msg->flags.set(MessageFlag::Subscription);
}
if (tags.value("msg-id") != "announcement")
{
// We want announcements to be able to show up in mentions
msg->flags.unset(MessageFlag::Highlighted);
msg->flags.set(MessageFlag::UncategorizedNotification);
}
}
+7 -1
View File
@@ -26,6 +26,12 @@ struct ClearChatMessage {
std::optional<QString> username;
};
struct AddMessageArgs {
bool isSub = false;
bool isAction = false;
bool isSpecial = false;
};
class IrcMessageHandler
{
IrcMessageHandler() = default;
@@ -64,7 +70,7 @@ public:
static void addMessage(Communi::IrcMessage *message, MessageSink &sink,
TwitchChannel *chan, const QString &originalContent,
ITwitchIrcServer &twitch, bool isSub, bool isAction,
ITwitchIrcServer &twitch, AddMessageArgs addArgs,
const QString &msgType = "");
private:
+1 -1
View File
@@ -545,7 +545,7 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
MessageSinkTrait::AddMentionsToGlobalChannel);
IrcMessageHandler::instance().addMessage(
msg.message.get(), sink, this, msg.originalContent,
*server, false, false);
*server, AddMessageArgs{});
if (sink.messages().empty())
{
return true;
@@ -75,7 +75,7 @@
],
"externalBadges": [
],
"flags": "System|DoNotTriggerNotification|Subscription",
"flags": "System|DoNotTriggerNotification|UncategorizedNotification",
"frozen": false,
"id": "",
"localizedName": "",
@@ -156,7 +156,6 @@
],
"flags": "Collapsed|WatchStreak",
"frozen": false,
"highlightColor": "#64c466ff",
"id": "090939a1-18a5-4370-9066-b4f56512c320",
"localizedName": "",
"loginName": "jcrouzer",
+1 -1
View File
@@ -87,7 +87,7 @@
],
"externalBadges": [
],
"flags": "System|DoNotTriggerNotification|Subscription",
"flags": "System|DoNotTriggerNotification|UncategorizedNotification",
"frozen": false,
"id": "",
"localizedName": "",
@@ -132,9 +132,8 @@
],
"externalBadges": [
],
"flags": "Collapsed|Subscription",
"flags": "Collapsed|UncategorizedNotification",
"frozen": false,
"highlightColor": "#64c466ff",
"id": "b468ef1c-f072-4ef9-a620-d7c4bdb8832f",
"localizedName": "",
"loginName": "gunny_q",
@@ -224,7 +223,7 @@
],
"externalBadges": [
],
"flags": "System|DoNotTriggerNotification|Subscription",
"flags": "System|DoNotTriggerNotification|UncategorizedNotification",
"frozen": false,
"id": "",
"localizedName": "",
@@ -167,7 +167,7 @@
],
"externalBadges": [
],
"flags": "Collapsed|Subscription",
"flags": "Highlighted|Collapsed|Subscription",
"frozen": false,
"highlightColor": "#64c466ff",
"id": "db25007f-7a18-43eb-9379-80131e44d633",
@@ -167,7 +167,7 @@
],
"externalBadges": [
],
"flags": "Collapsed|Subscription",
"flags": "Highlighted|Collapsed|Subscription",
"frozen": false,
"highlightColor": "#64c466ff",
"id": "db25007f-7a18-43eb-9379-80131e44d633",
@@ -147,7 +147,6 @@
],
"flags": "Collapsed|WatchStreak",
"frozen": false,
"highlightColor": "#64c466ff",
"id": "5f360c15-db41-439a-83fd-2e2dbcdebada",
"localizedName": "",
"loginName": "imrlazyi",