chore: move some Channel signals to TwitchChannel (#6787)

Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Nerixyz
2026-01-31 16:33:32 +01:00
committed by GitHub
parent 8f660b6de5
commit 301417488f
6 changed files with 46 additions and 27 deletions
+1
View File
@@ -104,6 +104,7 @@
- Dev: Remove unused `reloadChannelAndSubscriberEmotes`. (#6756) - Dev: Remove unused `reloadChannelAndSubscriberEmotes`. (#6756)
- Dev: Refactored `DebugCount`. (#6753) - Dev: Refactored `DebugCount`. (#6753)
- Dev: Moved `PluginMeta` to its own file. (#6757) - Dev: Moved `PluginMeta` to its own file. (#6757)
- Dev: Moves some `Channel` signals to `TwitchChannel`. (#6787)
## 2.5.4 ## 2.5.4
-1
View File
@@ -37,7 +37,6 @@ Channel::~Channel()
{ {
app->getChatLogger()->closeChannel(this->name_, this->platform_); app->getChatLogger()->closeChannel(this->name_, this->platform_);
} }
this->destroyed.invoke();
} }
Channel::Type Channel::getType() const Channel::Type Channel::getType() const
-6
View File
@@ -61,11 +61,6 @@ public:
~Channel() override; ~Channel() override;
// SIGNALS // SIGNALS
pajlada::Signals::Signal<const QString &, const QString &, bool &>
sendMessageSignal;
pajlada::Signals::Signal<const QString &, const QString &, const QString &,
bool &>
sendReplySignal;
pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>> pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
messageAppended; messageAppended;
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart; pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
@@ -74,7 +69,6 @@ public:
messageReplaced; messageReplaced;
/// Invoked when some number of messages were filled in using time received /// Invoked when some number of messages were filled in using time received
pajlada::Signals::Signal<const std::vector<MessagePtr> &> filledInMessages; pajlada::Signals::Signal<const std::vector<MessagePtr> &> filledInMessages;
pajlada::Signals::NoArgSignal destroyed;
pajlada::Signals::NoArgSignal displayNameChanged; pajlada::Signals::NoArgSignal displayNameChanged;
pajlada::Signals::NoArgSignal messagesCleared; pajlada::Signals::NoArgSignal messagesCleared;
+4 -3
View File
@@ -240,6 +240,8 @@ TwitchChannel::~TwitchChannel()
getApp()->getSeventvEventAPI()->unsubscribeTwitchChannel( getApp()->getSeventvEventAPI()->unsubscribeTwitchChannel(
this->roomId()); this->roomId());
} }
this->destroyed.invoke();
} }
void TwitchChannel::initialize() void TwitchChannel::initialize()
@@ -834,7 +836,7 @@ void TwitchChannel::sendMessage(const QString &message)
} }
bool messageSent = false; bool messageSent = false;
this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent); this->sendMessageSignal.invoke(parsedMessage, messageSent);
this->updateBttvActivity(); this->updateBttvActivity();
this->updateSevenTVActivity(); this->updateSevenTVActivity();
@@ -876,8 +878,7 @@ void TwitchChannel::sendReply(const QString &message, const QString &replyId)
} }
bool messageSent = false; bool messageSent = false;
this->sendReplySignal.invoke(this->getName(), parsedMessage, replyId, this->sendReplySignal.invoke(parsedMessage, replyId, messageSent);
messageSent);
if (messageSent) if (messageSent)
{ {
+23
View File
@@ -297,6 +297,27 @@ public:
*/ */
std::shared_ptr<MessageThread> getOrCreateThread(const MessagePtr &message); std::shared_ptr<MessageThread> getOrCreateThread(const MessagePtr &message);
/// Fired when a message is supposed to be sent by the user in this channel.
///
/// This should only be handled by one component.
///
/// Arguments:
/// - `messageText`: The text to be sent.
/// - `wasSent`: A return channel for whether the message was sent or not.
pajlada::Signals::Signal<const QString &, bool &> sendMessageSignal;
/// Fired when a reply to a message is supposed to be sent by the user in
/// this channel.
///
/// This should only be handled by one component.
///
/// Arguments:
/// - `messageText`: The text to be sent.
/// - `replyToMessageID`: The ID of the replied-to message.
/// - `wasSent`: A return channel for whether the message was sent or not.
pajlada::Signals::Signal<const QString &, const QString &, bool &>
sendReplySignal;
/** /**
* This signal fires when the local user has joined the channel * This signal fires when the local user has joined the channel
**/ **/
@@ -315,6 +336,8 @@ public:
pajlada::Signals::NoArgSignal roomModesChanged; pajlada::Signals::NoArgSignal roomModesChanged;
pajlada::Signals::NoArgSignal destroyed;
// Channel point rewards // Channel point rewards
void addQueuedRedemption(const QString &rewardId, void addQueuedRedemption(const QString &rewardId,
const QString &originalContent, const QString &originalContent,
+18 -17
View File
@@ -321,8 +321,7 @@ std::shared_ptr<Channel> TwitchIrcServer::createChannel(
// no Channel's should live // no Channel's should live
// NOTE: CHANNEL_LIFETIME // NOTE: CHANNEL_LIFETIME
std::ignore = channel->sendMessageSignal.connect( std::ignore = channel->sendMessageSignal.connect(
[this, channel = std::weak_ptr(channel)](auto &chan, auto &msg, [this, channel = std::weak_ptr(channel)](auto &msg, bool &sent) {
bool &sent) {
auto c = channel.lock(); auto c = channel.lock();
if (!c) if (!c)
{ {
@@ -331,8 +330,8 @@ std::shared_ptr<Channel> TwitchIrcServer::createChannel(
this->onMessageSendRequested(c, msg, sent); this->onMessageSendRequested(c, msg, sent);
}); });
std::ignore = channel->sendReplySignal.connect( std::ignore = channel->sendReplySignal.connect(
[this, channel = std::weak_ptr(channel)](auto &chan, auto &msg, [this, channel = std::weak_ptr(channel)](auto &msg, auto &replyId,
auto &replyId, bool &sent) { bool &sent) {
auto c = channel.lock(); auto c = channel.lock();
if (!c) if (!c)
{ {
@@ -1155,28 +1154,30 @@ ChannelPtr TwitchIrcServer::getOrAddChannel(const QString &dirtyChannelName)
// value doesn't exist // value doesn't exist
chan = this->createChannel(channelName); chan = this->createChannel(channelName);
if (!chan) auto *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
if (!chan || !twitchChannel)
{ {
return Channel::getEmpty(); return Channel::getEmpty();
} }
this->channels.insert(channelName, chan); this->channels.insert(channelName, chan);
this->signalHolder.managedConnect(chan->destroyed, [this, channelName] { this->signalHolder.managedConnect(
// fourtf: issues when the server itself is destroyed twitchChannel->destroyed, [this, channelName] {
// fourtf: issues when the server itself is destroyed
qCDebug(chatterinoIrc) << "[TwitchIrcServer::addChannel]" << channelName qCDebug(chatterinoIrc) << "[TwitchIrcServer::addChannel]"
<< "was destroyed"; << channelName << "was destroyed";
this->channels.remove(channelName); this->channels.remove(channelName);
if (this->readConnection_) if (this->readConnection_)
{
// HACK(mm2pl): This prevents custom invalid twitch channels used by plugins from being joined
if (!channelName.startsWith("/"))
{ {
this->readConnection_->sendRaw("PART #" + channelName); // HACK(mm2pl): This prevents custom invalid twitch channels used by plugins from being joined
if (!channelName.startsWith("/"))
{
this->readConnection_->sendRaw("PART #" + channelName);
}
} }
} });
});
// join IRC channel // join IRC channel
{ {