added limit to cached username colors (#2515)
This commit is contained in:
@@ -7,6 +7,7 @@ namespace chatterino {
|
||||
|
||||
ChannelChatters::ChannelChatters(Channel &channel)
|
||||
: channel_(channel)
|
||||
, chatterColors_(ChannelChatters::maxChatterColorCount)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -72,22 +73,23 @@ void ChannelChatters::setChatters(UsernameSet &&set)
|
||||
|
||||
const QColor ChannelChatters::getUserColor(const QString &user)
|
||||
{
|
||||
const auto chatterColors = this->chatterColors_.accessConst();
|
||||
const auto chatterColors = this->chatterColors_.access();
|
||||
|
||||
const auto search = chatterColors->find(user.toLower());
|
||||
if (search == chatterColors->end())
|
||||
auto lowerUser = user.toLower();
|
||||
|
||||
if (!chatterColors->exists(lowerUser))
|
||||
{
|
||||
// Returns an invalid color so we can decide not to override `textColor`
|
||||
return QColor();
|
||||
}
|
||||
|
||||
return search->second;
|
||||
return QColor::fromRgb(chatterColors->get(lowerUser));
|
||||
}
|
||||
|
||||
void ChannelChatters::setUserColor(const QString &user, const QColor &color)
|
||||
{
|
||||
const auto chatterColors = this->chatterColors_.access();
|
||||
chatterColors->insert_or_assign(user.toLower(), color);
|
||||
chatterColors->put(user.toLower(), color.rgb());
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "common/UsernameSet.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
|
||||
#include "lrucache/lrucache.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -22,11 +25,13 @@ public:
|
||||
void setUserColor(const QString &user, const QColor &color);
|
||||
|
||||
private:
|
||||
static constexpr int maxChatterColorCount = 5000;
|
||||
|
||||
Channel &channel_;
|
||||
|
||||
// maps 2 char prefix to set of names
|
||||
UniqueAccess<UsernameSet> chatters_;
|
||||
UniqueAccess<std::map<QString, QColor>> chatterColors_;
|
||||
UniqueAccess<cache::lru_cache<QString, QRgb>> chatterColors_;
|
||||
|
||||
// combines multiple joins/parts into one message
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
|
||||
Reference in New Issue
Block a user