Moved getRandomColor method to util/Helpers.cpp (#2974)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -9,13 +9,13 @@
|
||||
#include "providers/ffz/FfzBadges.hpp"
|
||||
#include "providers/twitch/TwitchBadges.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchCommon.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/IrcHelpers.hpp"
|
||||
#include "widgets/Window.hpp"
|
||||
|
||||
@@ -48,21 +48,6 @@ namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
QColor getRandomColor(const QVariant &userId)
|
||||
{
|
||||
bool ok = true;
|
||||
int colorSeed = userId.toInt(&ok);
|
||||
if (!ok)
|
||||
{
|
||||
// We were unable to convert the user ID to an integer, this means Twitch has decided to start using non-integer user IDs
|
||||
// Just randomize the users color
|
||||
colorSeed = std::rand();
|
||||
}
|
||||
|
||||
const auto colorIndex = colorSeed % TWITCH_USERNAME_COLORS.size();
|
||||
return TWITCH_USERNAME_COLORS[colorIndex];
|
||||
}
|
||||
|
||||
QStringList parseTagList(const QVariantMap &tags, const QString &key)
|
||||
{
|
||||
auto iterator = tags.find(key);
|
||||
@@ -601,7 +586,8 @@ void TwitchMessageBuilder::parseUsernameColor()
|
||||
|
||||
if (getSettings()->colorizeNicknames && this->tags.contains("user-id"))
|
||||
{
|
||||
this->usernameColor_ = getRandomColor(this->tags.value("user-id"));
|
||||
this->usernameColor_ =
|
||||
getRandomColor(this->tags.value("user-id").toString());
|
||||
this->message().usernameColor = this->usernameColor_;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user