fix: correctly override user color in sub gifts (#6322)
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user