mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
moved chatters to ChannelChatters
This commit is contained in:
parent
13c9aabf29
commit
96dac0fd3d
|
@ -77,6 +77,7 @@ SOURCES += \
|
|||
src/autogenerated/ResourcesAutogen.cpp \
|
||||
src/BrowserExtension.cpp \
|
||||
src/common/Channel.cpp \
|
||||
src/common/ChannelChatters.cpp \
|
||||
src/common/CompletionModel.cpp \
|
||||
src/common/Credentials.cpp \
|
||||
src/common/DownloadManager.cpp \
|
||||
|
@ -229,6 +230,7 @@ HEADERS += \
|
|||
src/common/Aliases.hpp \
|
||||
src/common/Atomic.hpp \
|
||||
src/common/Channel.hpp \
|
||||
src/common/ChannelChatters.hpp \
|
||||
src/common/Common.hpp \
|
||||
src/common/CompletionModel.hpp \
|
||||
src/common/ConcurrentMap.hpp \
|
||||
|
|
|
@ -70,13 +70,6 @@ void Channel::addMessage(MessagePtr message,
|
|||
auto app = getApp();
|
||||
MessagePtr deleted;
|
||||
|
||||
const QString &username = message->loginName;
|
||||
if (!username.isEmpty())
|
||||
{
|
||||
// TODO: Add recent chatters display name
|
||||
this->addRecentChatter(message);
|
||||
}
|
||||
|
||||
// FOURTF: change this when adding more providers
|
||||
if (this->isTwitchChannel() &&
|
||||
(!overridingFlags || !overridingFlags->has(MessageFlag::DoNotLog)))
|
||||
|
@ -246,10 +239,6 @@ void Channel::deleteMessage(QString messageID)
|
|||
}
|
||||
}
|
||||
|
||||
void Channel::addRecentChatter(const MessagePtr &message)
|
||||
{
|
||||
}
|
||||
|
||||
bool Channel::canSendMessage() const
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -90,7 +90,6 @@ public:
|
|||
|
||||
protected:
|
||||
virtual void onConnected();
|
||||
virtual void addRecentChatter(const MessagePtr &message);
|
||||
|
||||
private:
|
||||
const QString name_;
|
||||
|
|
72
src/common/ChannelChatters.cpp
Normal file
72
src/common/ChannelChatters.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "ChannelChatters.hpp"
|
||||
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
ChannelChatters::ChannelChatters(Channel &channel)
|
||||
: channel_(channel)
|
||||
{
|
||||
}
|
||||
|
||||
AccessGuard<const UsernameSet> ChannelChatters::accessChatters() const
|
||||
{
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
void ChannelChatters::setChatters(UsernameSet &&set)
|
||||
{
|
||||
*this->chatters_.access() = set;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
37
src/common/ChannelChatters.hpp
Normal file
37
src/common/ChannelChatters.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "common/UsernameSet.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ChannelChatters
|
||||
{
|
||||
public:
|
||||
ChannelChatters(Channel &channel);
|
||||
virtual ~ChannelChatters() = default; // add vtable
|
||||
|
||||
AccessGuard<const UsernameSet> accessChatters() const;
|
||||
|
||||
void addRecentChatter(const QString &user);
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
void setChatters(UsernameSet &&set);
|
||||
|
||||
private:
|
||||
Channel &channel_;
|
||||
|
||||
// maps 2 char prefix to set of names
|
||||
UniqueAccess<UsernameSet> chatters_;
|
||||
|
||||
// combines multiple joins/parts into one message
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
bool joinedUsersMergeQueued_ = false;
|
||||
UniqueAccess<QStringList> partedUsers_;
|
||||
bool partedUsersMergeQueued_ = false;
|
||||
|
||||
QObject lifetimeGuard_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -359,20 +359,6 @@ void AbstractIrcServer::privateMessageReceived(
|
|||
void AbstractIrcServer::readConnectionMessageReceived(
|
||||
Communi::IrcMessage *message)
|
||||
{
|
||||
/* XXX: only print this message once
|
||||
if (message->type() == Communi::IrcMessage::Join)
|
||||
{
|
||||
auto x = static_cast<Communi::IrcJoinMessage *>(message);
|
||||
|
||||
if (auto it = this->channels.find(this->cleanChannelName(x->channel()));
|
||||
it != this->channels.end())
|
||||
{
|
||||
if (auto shared = it->lock())
|
||||
shared->addMessage(
|
||||
MessageBuilder(systemMessage, "joined").release());
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void AbstractIrcServer::forEachChannel(std::function<void(ChannelPtr)> func)
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace chatterino {
|
|||
|
||||
IrcChannel::IrcChannel(const QString &name, IrcServer *server)
|
||||
: Channel(name, Channel::Type::Irc)
|
||||
, ChannelChatters(*static_cast<Channel *>(this))
|
||||
, server_(server)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/ChannelChatters.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Irc;
|
||||
class IrcServer;
|
||||
|
||||
class IrcChannel : public Channel
|
||||
class IrcChannel : public Channel, public ChannelChatters
|
||||
{
|
||||
public:
|
||||
explicit IrcChannel(const QString &name, IrcServer *server);
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
#include "IrcMessageHandler.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "controllers/highlights/HighlightController.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/LimitedQueue.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/twitch/TwitchAccountManager.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchHelpers.hpp"
|
||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||
#include "singletons/Resources.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
|
@ -93,8 +95,9 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
|||
|
||||
void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
|
||||
const QString &target,
|
||||
const QString &content, TwitchIrcServer &server,
|
||||
bool isSub, bool isAction)
|
||||
const QString &content,
|
||||
TwitchIrcServer &server, bool isSub,
|
||||
bool isAction)
|
||||
{
|
||||
QString channelName;
|
||||
if (!trimChannelName(target, channelName))
|
||||
|
@ -144,6 +147,10 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
|
|||
}
|
||||
|
||||
chan->addMessage(msg);
|
||||
if (auto chatters = dynamic_cast<ChannelChatters *>(chan.get()))
|
||||
{
|
||||
chatters->addRecentChatter(msg->displayName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -591,7 +598,12 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
|
|||
if (TwitchChannel *twitchChannel =
|
||||
dynamic_cast<TwitchChannel *>(channel.get()))
|
||||
{
|
||||
twitchChannel->addJoinedUser(message->nick());
|
||||
if (message->nick() !=
|
||||
getApp()->accounts->twitch.getCurrent()->getUserName() &&
|
||||
getSettings()->showJoins.getValue())
|
||||
{
|
||||
twitchChannel->addJoinedUser(message->nick());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -604,7 +616,12 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
|
|||
if (TwitchChannel *twitchChannel =
|
||||
dynamic_cast<TwitchChannel *>(channel.get()))
|
||||
{
|
||||
twitchChannel->addPartedUser(message->nick());
|
||||
if (message->nick() !=
|
||||
getApp()->accounts->twitch.getCurrent()->getUserName() &&
|
||||
getSettings()->showJoins.getValue())
|
||||
{
|
||||
twitchChannel->addPartedUser(message->nick());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ TwitchChannel::TwitchChannel(const QString &name,
|
|||
TwitchBadges &globalTwitchBadges, BttvEmotes &bttv,
|
||||
FfzEmotes &ffz)
|
||||
: Channel(name, Channel::Type::Twitch)
|
||||
, ChannelChatters(*static_cast<Channel *>(this))
|
||||
, subscriptionUrl_("https://www.twitch.tv/subs/" + name)
|
||||
, channelUrl_("https://twitch.tv/" + name)
|
||||
, popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name)
|
||||
|
@ -275,71 +276,6 @@ bool TwitchChannel::hasHighRateLimit() const
|
|||
return this->isMod() || this->isBroadcaster() || this->isVIP();
|
||||
}
|
||||
|
||||
void TwitchChannel::addRecentChatter(const MessagePtr &message)
|
||||
{
|
||||
this->chatters_.access()->insert(message->displayName);
|
||||
}
|
||||
|
||||
void TwitchChannel::addJoinedUser(const QString &user)
|
||||
{
|
||||
auto app = getApp();
|
||||
if (user == app->accounts->twitch.getCurrent()->getUserName() ||
|
||||
!getSettings()->showJoins.getValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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->addMessage(builder.release());
|
||||
this->joinedUsersMergeQueued_ = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchChannel::addPartedUser(const QString &user)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
if (user == app->accounts->twitch.getCurrent()->getUserName() ||
|
||||
!getSettings()->showJoins.getValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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->addMessage(builder.release());
|
||||
partedUsers->clear();
|
||||
|
||||
this->partedUsersMergeQueued_ = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
QString TwitchChannel::roomId() const
|
||||
{
|
||||
return *this->roomID_.access();
|
||||
|
@ -379,11 +315,6 @@ AccessGuard<const TwitchChannel::StreamStatus>
|
|||
return this->streamStatus_.accessConst();
|
||||
}
|
||||
|
||||
AccessGuard<const UsernameSet> TwitchChannel::accessChatters() const
|
||||
{
|
||||
return this->chatters_.accessConst();
|
||||
}
|
||||
|
||||
const TwitchBadges &TwitchChannel::globalTwitchBadges() const
|
||||
{
|
||||
return this->globalTwitchBadges_;
|
||||
|
@ -686,7 +617,7 @@ void TwitchChannel::refreshChatters()
|
|||
auto pair = parseChatters(result.parseJson());
|
||||
if (pair.first)
|
||||
{
|
||||
*this->chatters_.access() = std::move(pair.second);
|
||||
this->setChatters(std::move(pair.second));
|
||||
}
|
||||
|
||||
return pair.first;
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/ChannelChatters.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "common/UsernameSet.hpp"
|
||||
#include "providers/ffz/FfzModBadge.hpp"
|
||||
#include "providers/twitch/TwitchEmotes.hpp"
|
||||
|
||||
|
@ -32,7 +32,9 @@ class BttvEmotes;
|
|||
|
||||
class TwitchIrcServer;
|
||||
|
||||
class TwitchChannel : public Channel, pajlada::Signals::SignalHolder
|
||||
class TwitchChannel : public Channel,
|
||||
public ChannelChatters,
|
||||
pajlada::Signals::SignalHolder
|
||||
{
|
||||
public:
|
||||
struct StreamStatus {
|
||||
|
@ -74,7 +76,6 @@ public:
|
|||
QString roomId() const;
|
||||
AccessGuard<const RoomModes> accessRoomModes() const;
|
||||
AccessGuard<const StreamStatus> accessStreamStatus() const;
|
||||
AccessGuard<const UsernameSet> accessChatters() const;
|
||||
|
||||
// Emotes
|
||||
const TwitchBadges &globalTwitchBadges() const;
|
||||
|
@ -99,9 +100,6 @@ public:
|
|||
pajlada::Signals::NoArgSignal liveStatusChanged;
|
||||
pajlada::Signals::NoArgSignal roomModesChanged;
|
||||
|
||||
protected:
|
||||
void addRecentChatter(const MessagePtr &message) override;
|
||||
|
||||
private:
|
||||
struct NameOptions {
|
||||
QString displayName;
|
||||
|
@ -123,8 +121,6 @@ private:
|
|||
void refreshCheerEmotes();
|
||||
void loadRecentMessages();
|
||||
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
void setLive(bool newLiveStatus);
|
||||
void setMod(bool value);
|
||||
void setVIP(bool value);
|
||||
|
@ -138,7 +134,6 @@ private:
|
|||
const QString popoutPlayerUrl_;
|
||||
UniqueAccess<StreamStatus> streamStatus_;
|
||||
UniqueAccess<RoomModes> roomModes_;
|
||||
UniqueAccess<UsernameSet> chatters_; // maps 2 char prefix to set of names
|
||||
|
||||
// Emotes
|
||||
TwitchBadges &globalTwitchBadges_;
|
||||
|
@ -161,11 +156,6 @@ private:
|
|||
bool staff_ = false;
|
||||
UniqueAccess<QString> roomID_;
|
||||
|
||||
UniqueAccess<QStringList> joinedUsers_;
|
||||
bool joinedUsersMergeQueued_ = false;
|
||||
UniqueAccess<QStringList> partedUsers_;
|
||||
bool partedUsersMergeQueued_ = false;
|
||||
|
||||
// --
|
||||
QString lastSentMessage_;
|
||||
QObject lifetimeGuard_;
|
||||
|
|
Loading…
Reference in a new issue