From 301417488f2189042037b83a52548dc7f9d353f0 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 31 Jan 2026 16:33:32 +0100 Subject: [PATCH] chore: move some `Channel` signals to `TwitchChannel` (#6787) Reviewed-by: pajlada --- CHANGELOG.md | 1 + src/common/Channel.cpp | 1 - src/common/Channel.hpp | 6 ---- src/providers/twitch/TwitchChannel.cpp | 7 +++-- src/providers/twitch/TwitchChannel.hpp | 23 ++++++++++++++++ src/providers/twitch/TwitchIrcServer.cpp | 35 ++++++++++++------------ 6 files changed, 46 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d1be7f..2c8e10d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ - Dev: Remove unused `reloadChannelAndSubscriberEmotes`. (#6756) - Dev: Refactored `DebugCount`. (#6753) - Dev: Moved `PluginMeta` to its own file. (#6757) +- Dev: Moves some `Channel` signals to `TwitchChannel`. (#6787) ## 2.5.4 diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 9e476b9a..beb14b27 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -37,7 +37,6 @@ Channel::~Channel() { app->getChatLogger()->closeChannel(this->name_, this->platform_); } - this->destroyed.invoke(); } Channel::Type Channel::getType() const diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index d9a4ad17..65f256c0 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -61,11 +61,6 @@ public: ~Channel() override; // SIGNALS - pajlada::Signals::Signal - sendMessageSignal; - pajlada::Signals::Signal - sendReplySignal; pajlada::Signals::Signal> messageAppended; pajlada::Signals::Signal &> messagesAddedAtStart; @@ -74,7 +69,6 @@ public: messageReplaced; /// Invoked when some number of messages were filled in using time received pajlada::Signals::Signal &> filledInMessages; - pajlada::Signals::NoArgSignal destroyed; pajlada::Signals::NoArgSignal displayNameChanged; pajlada::Signals::NoArgSignal messagesCleared; diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 25a1a5ab..3ee7e4ed 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -240,6 +240,8 @@ TwitchChannel::~TwitchChannel() getApp()->getSeventvEventAPI()->unsubscribeTwitchChannel( this->roomId()); } + + this->destroyed.invoke(); } void TwitchChannel::initialize() @@ -834,7 +836,7 @@ void TwitchChannel::sendMessage(const QString &message) } bool messageSent = false; - this->sendMessageSignal.invoke(this->getName(), parsedMessage, messageSent); + this->sendMessageSignal.invoke(parsedMessage, messageSent); this->updateBttvActivity(); this->updateSevenTVActivity(); @@ -876,8 +878,7 @@ void TwitchChannel::sendReply(const QString &message, const QString &replyId) } bool messageSent = false; - this->sendReplySignal.invoke(this->getName(), parsedMessage, replyId, - messageSent); + this->sendReplySignal.invoke(parsedMessage, replyId, messageSent); if (messageSent) { diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index d401dd1f..326e1e8d 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -297,6 +297,27 @@ public: */ std::shared_ptr 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 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 + sendReplySignal; + /** * This signal fires when the local user has joined the channel **/ @@ -315,6 +336,8 @@ public: pajlada::Signals::NoArgSignal roomModesChanged; + pajlada::Signals::NoArgSignal destroyed; + // Channel point rewards void addQueuedRedemption(const QString &rewardId, const QString &originalContent, diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 76092c21..29ca7d7d 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -321,8 +321,7 @@ std::shared_ptr TwitchIrcServer::createChannel( // no Channel's should live // NOTE: CHANNEL_LIFETIME std::ignore = channel->sendMessageSignal.connect( - [this, channel = std::weak_ptr(channel)](auto &chan, auto &msg, - bool &sent) { + [this, channel = std::weak_ptr(channel)](auto &msg, bool &sent) { auto c = channel.lock(); if (!c) { @@ -331,8 +330,8 @@ std::shared_ptr TwitchIrcServer::createChannel( this->onMessageSendRequested(c, msg, sent); }); std::ignore = channel->sendReplySignal.connect( - [this, channel = std::weak_ptr(channel)](auto &chan, auto &msg, - auto &replyId, bool &sent) { + [this, channel = std::weak_ptr(channel)](auto &msg, auto &replyId, + bool &sent) { auto c = channel.lock(); if (!c) { @@ -1155,28 +1154,30 @@ ChannelPtr TwitchIrcServer::getOrAddChannel(const QString &dirtyChannelName) // value doesn't exist chan = this->createChannel(channelName); - if (!chan) + auto *twitchChannel = dynamic_cast(chan.get()); + if (!chan || !twitchChannel) { return Channel::getEmpty(); } this->channels.insert(channelName, chan); - this->signalHolder.managedConnect(chan->destroyed, [this, channelName] { - // fourtf: issues when the server itself is destroyed + this->signalHolder.managedConnect( + twitchChannel->destroyed, [this, channelName] { + // fourtf: issues when the server itself is destroyed - qCDebug(chatterinoIrc) << "[TwitchIrcServer::addChannel]" << channelName - << "was destroyed"; - this->channels.remove(channelName); + qCDebug(chatterinoIrc) << "[TwitchIrcServer::addChannel]" + << channelName << "was destroyed"; + this->channels.remove(channelName); - if (this->readConnection_) - { - // HACK(mm2pl): This prevents custom invalid twitch channels used by plugins from being joined - if (!channelName.startsWith("/")) + if (this->readConnection_) { - 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 {