fix: correctly override user color in sub gifts (#6322)
This commit is contained in:
@@ -440,6 +440,8 @@ set(SOURCE_FILES
|
||||
providers/twitch/TwitchUser.hpp
|
||||
providers/twitch/TwitchUsers.cpp
|
||||
providers/twitch/TwitchUsers.hpp
|
||||
providers/twitch/UserColor.cpp
|
||||
providers/twitch/UserColor.hpp
|
||||
|
||||
providers/twitch/eventsub/Connection.cpp
|
||||
providers/twitch/eventsub/Connection.hpp
|
||||
|
||||
@@ -112,7 +112,7 @@ size_t ChannelChatters::colorsSize() const
|
||||
return size;
|
||||
}
|
||||
|
||||
const QColor ChannelChatters::getUserColor(const QString &user)
|
||||
QColor ChannelChatters::getUserColor(const QString &user) const
|
||||
{
|
||||
const auto chatterColors = this->chatterColors_.access();
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
void addRecentChatter(const QString &user);
|
||||
void addJoinedUser(const QString &user, bool isMod, bool isBroadcaster);
|
||||
void addPartedUser(const QString &user, bool isMod, bool isBroadcaster);
|
||||
const QColor getUserColor(const QString &user);
|
||||
QColor getUserColor(const QString &user) const;
|
||||
void setUserColor(const QString &user, const QColor &color);
|
||||
void updateOnlineChatters(const std::unordered_set<QString> &usernames);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "providers/twitch/TwitchIrc.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "providers/twitch/TwitchUsers.hpp"
|
||||
#include "providers/twitch/UserColor.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
@@ -587,8 +588,12 @@ MessagePtrMut MessageBuilder::makeSystemMessageWithUser(
|
||||
|
||||
MessagePtrMut MessageBuilder::makeSubgiftMessage(const QString &text,
|
||||
const QVariantMap &tags,
|
||||
const QTime &time)
|
||||
const QTime &time,
|
||||
TwitchChannel *channel)
|
||||
{
|
||||
const auto *userDataController = getApp()->getUserData();
|
||||
assert(userDataController != nullptr);
|
||||
|
||||
MessageBuilder builder;
|
||||
builder.emplace<TimestampElement>(time);
|
||||
|
||||
@@ -598,11 +603,16 @@ MessagePtrMut MessageBuilder::makeSubgiftMessage(const QString &text,
|
||||
{
|
||||
gifterDisplayName = gifterLogin;
|
||||
}
|
||||
MessageColor gifterColor = MessageColor::System;
|
||||
if (auto colorTag = tags.value("color").value<QColor>(); colorTag.isValid())
|
||||
{
|
||||
gifterColor = MessageColor(colorTag);
|
||||
}
|
||||
|
||||
auto gifterColor =
|
||||
twitch::getUserColor({
|
||||
.userLogin = gifterLogin,
|
||||
.userID = tags.value("user-id").toString(),
|
||||
.userDataController = userDataController,
|
||||
.channelChatters = channel,
|
||||
.color = tags.value("color").value<QColor>(),
|
||||
})
|
||||
.value_or(MessageColor::System);
|
||||
|
||||
auto recipientLogin =
|
||||
tags.value("msg-param-recipient-user-name").toString();
|
||||
@@ -617,6 +627,17 @@ MessagePtrMut MessageBuilder::makeSubgiftMessage(const QString &text,
|
||||
recipientDisplayName = recipientLogin;
|
||||
}
|
||||
|
||||
auto recipientColor =
|
||||
twitch::getUserColor(
|
||||
{
|
||||
.userLogin = recipientLogin,
|
||||
.userID = tags.value("msg-param-recipient-id").toString(),
|
||||
|
||||
.userDataController = userDataController,
|
||||
.channelChatters = channel,
|
||||
})
|
||||
.value_or(MessageColor::System);
|
||||
|
||||
const auto textFragments = text.split(SPACE_REGEX, Qt::SkipEmptyParts);
|
||||
for (const auto &word : textFragments)
|
||||
{
|
||||
@@ -632,8 +653,7 @@ MessagePtrMut MessageBuilder::makeSubgiftMessage(const QString &text,
|
||||
{
|
||||
builder
|
||||
.emplace<MentionElement>(recipientDisplayName, recipientLogin,
|
||||
MessageColor::System,
|
||||
MessageColor::System)
|
||||
MessageColor::System, recipientColor)
|
||||
->setTrailingSpace(false);
|
||||
builder.emplace<TextElement>(u"!"_s, MessageElementFlag::Text,
|
||||
MessageColor::System);
|
||||
|
||||
@@ -240,7 +240,8 @@ public:
|
||||
|
||||
static MessagePtrMut makeSubgiftMessage(const QString &text,
|
||||
const QVariantMap &tags,
|
||||
const QTime &time);
|
||||
const QTime &time,
|
||||
TwitchChannel *channel);
|
||||
|
||||
static MessagePtrMut makeMissingScopesMessage(const QString &missingScopes);
|
||||
|
||||
|
||||
@@ -667,6 +667,8 @@ void IrcMessageHandler::parseUserNoticeMessageInto(Communi::IrcMessage *message,
|
||||
MessageSink &sink,
|
||||
TwitchChannel *channel)
|
||||
{
|
||||
assert(channel != nullptr);
|
||||
|
||||
auto tags = message->tags();
|
||||
auto parameters = message->parameters();
|
||||
|
||||
@@ -775,7 +777,7 @@ void IrcMessageHandler::parseUserNoticeMessageInto(Communi::IrcMessage *message,
|
||||
// subgifts are special because they include two users
|
||||
auto msg = MessageBuilder::makeSubgiftMessage(
|
||||
parseTagString(messageText), tags,
|
||||
calculateMessageTime(message).time());
|
||||
calculateMessageTime(message).time(), channel);
|
||||
|
||||
msg->flags.set(MessageFlag::Subscription);
|
||||
if (mirrored)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "providers/twitch/UserColor.hpp"
|
||||
|
||||
#include "common/ChannelChatters.hpp"
|
||||
#include "controllers/userdata/UserDataController.hpp"
|
||||
#include "messages/MessageColor.hpp"
|
||||
|
||||
namespace chatterino::twitch {
|
||||
|
||||
std::optional<MessageColor> getUserColor(const GetUserColorParams ¶ms)
|
||||
{
|
||||
if (params.userDataController != nullptr)
|
||||
{
|
||||
if (!params.userID.isEmpty())
|
||||
{
|
||||
if (const auto &oUser =
|
||||
params.userDataController->getUser(params.userID))
|
||||
{
|
||||
const auto &user = *oUser;
|
||||
if (user.color && user.color->isValid())
|
||||
{
|
||||
return {*user.color};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (params.color.isValid())
|
||||
{
|
||||
return {params.color};
|
||||
}
|
||||
|
||||
if (params.channelChatters != nullptr)
|
||||
{
|
||||
if (!params.userLogin.isEmpty())
|
||||
{
|
||||
if (auto color =
|
||||
params.channelChatters->getUserColor(params.userLogin);
|
||||
color.isValid())
|
||||
{
|
||||
return {color};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace chatterino::twitch
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "messages/MessageColor.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include <optional>
|
||||
|
||||
class QColor;
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class IUserDataController;
|
||||
class ChannelChatters;
|
||||
|
||||
namespace twitch {
|
||||
|
||||
struct GetUserColorParams {
|
||||
QString userLogin;
|
||||
QString userID;
|
||||
|
||||
const IUserDataController *userDataController{};
|
||||
const ChannelChatters *channelChatters{};
|
||||
|
||||
QColor color;
|
||||
};
|
||||
|
||||
/// Attempt to get the color of the user based on the provided parameters.
|
||||
///
|
||||
/// If there's a valid color for the given user ID in the user data controller, return it.
|
||||
/// If there's a valid `color` parameter, return it.
|
||||
/// If there's a valid color for the given user login in the channel chatters set, return it.
|
||||
/// Otherwise, return nullopt.
|
||||
std::optional<MessageColor> getUserColor(const GetUserColorParams ¶ms);
|
||||
|
||||
} // namespace twitch
|
||||
} // namespace chatterino
|
||||
@@ -104,6 +104,9 @@ const QStringList &getSampleSubMessages()
|
||||
|
||||
// resub without message
|
||||
R"(@badges=subscriber/12;color=#CC00C2;display-name=cspice;emotes=;id=6fc4c3e0-ca61-454a-84b8-5669dee69fc9;login=cspice;mod=0;msg-id=resub;msg-param-months=12;msg-param-sub-plan-name=Channel\sSubscription\s(forsenlol):\s$9.99\sSub;msg-param-sub-plan=2000;room-id=22484632;subscriber=1;system-msg=cspice\sjust\ssubscribed\swith\sa\sTier\s2\ssub.\scspice\ssubscribed\sfor\s12\smonths\sin\sa\srow!;tmi-sent-ts=1528192510808;turbo=0;user-id=47894662;user-type= :tmi.twitch.tv USERNOTICE #pajlada)",
|
||||
|
||||
// pajlada gifted a sub to rustafur
|
||||
R"(@tmi-sent-ts=1751793597378;subscriber=1;id=ac51c358-0525-468f-9e0f-e9f2b7953c29;room-id=11148817;user-id=11148817;login=pajlada;display-name=pajlada;badges=broadcaster/1,subscriber/3072,partner/1;badge-info=subscriber/114;color=#CC44FF;flags=;user-type=;emotes=;msg-param-sub-plan-name=look\sat\sthose\sshitty\semotes,\srip\s$5\sLUL;msg-param-gift-months=1;system-msg=pajlada\sgifted\sa\sTier\s1\ssub\sto\srustafur!;msg-param-months=6;msg-param-origin-id=4645652708379472175;msg-param-recipient-id=27787997;msg-param-sub-plan=1000;msg-id=subgift;msg-param-recipient-display-name=rustafur;msg-param-recipient-user-name=rustafur;msg-param-community-gift-id=4645652708379472175;msg-param-sender-count=0 :tmi.twitch.tv USERNOTICE #pajlada)",
|
||||
};
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user