2020-10-18 15:54:48 +02:00
|
|
|
#include "ChannelChatters.hpp"
|
|
|
|
|
|
|
|
#include "messages/Message.hpp"
|
|
|
|
#include "messages/MessageBuilder.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
ChannelChatters::ChannelChatters(Channel &channel)
|
|
|
|
: channel_(channel)
|
2021-03-13 15:34:11 +01:00
|
|
|
, chatterColors_(ChannelChatters::maxChatterColorCount)
|
2020-10-18 15:54:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const UsernameSet> ChannelChatters::accessChatters() const
|
2020-10-18 15:54:48 +02:00
|
|
|
{
|
|
|
|
return this->chatters_.accessConst();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelChatters::addRecentChatter(const QString &user)
|
|
|
|
{
|
|
|
|
this->chatters_.access()->insert(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelChatters::addJoinedUser(const QString &user)
|
|
|
|
{
|
|
|
|
auto joinedUsers = this->joinedUsers_.access();
|
|
|
|
joinedUsers->append(user);
|
|
|
|
|
|
|
|
if (!this->joinedUsersMergeQueued_)
|
|
|
|
{
|
|
|
|
this->joinedUsersMergeQueued_ = true;
|
|
|
|
|
|
|
|
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
|
|
|
|
auto joinedUsers = this->joinedUsers_.access();
|
|
|
|
|
|
|
|
MessageBuilder builder(systemMessage,
|
|
|
|
"Users joined: " + joinedUsers->join(", "));
|
|
|
|
builder->flags.set(MessageFlag::Collapsed);
|
|
|
|
joinedUsers->clear();
|
|
|
|
this->channel_.addMessage(builder.release());
|
|
|
|
this->joinedUsersMergeQueued_ = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelChatters::addPartedUser(const QString &user)
|
|
|
|
{
|
|
|
|
auto partedUsers = this->partedUsers_.access();
|
|
|
|
partedUsers->append(user);
|
|
|
|
|
|
|
|
if (!this->partedUsersMergeQueued_)
|
|
|
|
{
|
|
|
|
this->partedUsersMergeQueued_ = true;
|
|
|
|
|
|
|
|
QTimer::singleShot(500, &this->lifetimeGuard_, [this] {
|
|
|
|
auto partedUsers = this->partedUsers_.access();
|
|
|
|
|
|
|
|
MessageBuilder builder(systemMessage,
|
|
|
|
"Users parted: " + partedUsers->join(", "));
|
|
|
|
builder->flags.set(MessageFlag::Collapsed);
|
|
|
|
this->channel_.addMessage(builder.release());
|
|
|
|
partedUsers->clear();
|
|
|
|
|
|
|
|
this->partedUsersMergeQueued_ = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-12-19 14:42:20 +01:00
|
|
|
|
2020-10-18 15:54:48 +02:00
|
|
|
void ChannelChatters::setChatters(UsernameSet &&set)
|
|
|
|
{
|
2020-12-20 16:43:35 +01:00
|
|
|
this->chatters_.access()->merge(std::move(set));
|
2020-10-18 15:54:48 +02:00
|
|
|
}
|
|
|
|
|
2020-12-19 14:42:20 +01:00
|
|
|
const QColor ChannelChatters::getUserColor(const QString &user)
|
|
|
|
{
|
2021-03-13 15:34:11 +01:00
|
|
|
const auto chatterColors = this->chatterColors_.access();
|
|
|
|
|
|
|
|
auto lowerUser = user.toLower();
|
2020-12-19 14:42:20 +01:00
|
|
|
|
2021-03-13 15:34:11 +01:00
|
|
|
if (!chatterColors->exists(lowerUser))
|
2020-12-19 14:42:20 +01:00
|
|
|
{
|
|
|
|
// Returns an invalid color so we can decide not to override `textColor`
|
|
|
|
return QColor();
|
|
|
|
}
|
|
|
|
|
2021-03-13 15:34:11 +01:00
|
|
|
return QColor::fromRgb(chatterColors->get(lowerUser));
|
2020-12-19 14:42:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChannelChatters::setUserColor(const QString &user, const QColor &color)
|
|
|
|
{
|
|
|
|
const auto chatterColors = this->chatterColors_.access();
|
2021-03-13 15:34:11 +01:00
|
|
|
chatterColors->put(user.toLower(), color.rgb());
|
2020-12-19 14:42:20 +01:00
|
|
|
}
|
|
|
|
|
2020-10-18 15:54:48 +02:00
|
|
|
} // namespace chatterino
|