Fix signal connection nodiscard warnings (#4818)

This commit is contained in:
pajlada
2023-09-16 13:52:51 +02:00
committed by GitHub
parent 2d5f078306
commit 8fe3af3522
40 changed files with 709 additions and 554 deletions
+2 -2
View File
@@ -50,7 +50,7 @@ AbstractIrcServer::AbstractIrcServer()
this->writeConnection_->connectionLost, [this](bool timeout) {
qCDebug(chatterinoIrc)
<< "Write connection reconnect requested. Timeout:" << timeout;
this->writeConnection_->smartReconnect.invoke();
this->writeConnection_->smartReconnect();
});
// Listen to read connection message signals
@@ -86,7 +86,7 @@ AbstractIrcServer::AbstractIrcServer()
this->addGlobalSystemMessage(
"Server connection timed out, reconnecting");
}
this->readConnection_->smartReconnect.invoke();
this->readConnection_->smartReconnect();
});
}
+9 -3
View File
@@ -88,7 +88,9 @@ void IrcServerData::setPassword(const QString &password)
Irc::Irc()
{
this->connections.itemInserted.connect([this](auto &&args) {
// We can safely ignore this signal connection since `connections` will always
// be destroyed before the Irc object
std::ignore = this->connections.itemInserted.connect([this](auto &&args) {
// make sure only one id can only exist for one server
assert(this->servers_.find(args.item.id) == this->servers_.end());
@@ -117,7 +119,9 @@ Irc::Irc()
}
});
this->connections.itemRemoved.connect([this](auto &&args) {
// We can safely ignore this signal connection since `connections` will always
// be destroyed before the Irc object
std::ignore = this->connections.itemRemoved.connect([this](auto &&args) {
// restore
if (auto server = this->servers_.find(args.item.id);
server != this->servers_.end())
@@ -141,7 +145,9 @@ Irc::Irc()
}
});
this->connections.delayedItemsChanged.connect([this] {
// We can safely ignore this signal connection since `connections` will always
// be destroyed before the Irc object
std::ignore = this->connections.delayedItemsChanged.connect([this] {
this->save();
});
}
+13 -12
View File
@@ -38,18 +38,6 @@ IrcConnection::IrcConnection(QObject *parent)
}
});
// Schedule a reconnect that won't violate RECONNECT_MIN_INTERVAL
this->smartReconnect.connect([this] {
if (this->reconnectTimer_.isActive())
{
return;
}
auto delay = this->reconnectBackoff_.next();
qCDebug(chatterinoIrc) << "Reconnecting in" << delay.count() << "ms";
this->reconnectTimer_.start(delay);
});
this->reconnectTimer_.setSingleShot(true);
QObject::connect(&this->reconnectTimer_, &QTimer::timeout, [this] {
if (this->isConnected())
@@ -123,6 +111,19 @@ IrcConnection::~IrcConnection()
this->disconnect();
}
void IrcConnection::smartReconnect()
{
if (this->reconnectTimer_.isActive())
{
// Ignore this reconnect request, we already have a reconnect request queued up
return;
}
auto delay = this->reconnectBackoff_.next();
qCDebug(chatterinoIrc) << "Reconnecting in" << delay.count() << "ms";
this->reconnectTimer_.start(delay);
}
void IrcConnection::open()
{
this->expectConnectionLoss_ = false;
+2 -1
View File
@@ -20,7 +20,8 @@ public:
pajlada::Signals::Signal<bool> connectionLost;
// Request a reconnect with a minimum interval between attempts.
pajlada::Signals::NoArgSignal smartReconnect;
// This won't violate RECONNECT_MIN_INTERVAL
void smartReconnect();
virtual void open();
virtual void close();
@@ -20,7 +20,9 @@ TwitchAccountManager::TwitchAccountManager()
currentUser->loadSeventvUserID();
});
this->accounts.itemRemoved.connect([this](const auto &acc) {
// We can safely ignore this signal connection since accounts will always be removed
// before TwitchAccountManager
std::ignore = this->accounts.itemRemoved.connect([this](const auto &acc) {
this->removeUser(acc.item.get());
});
}
+32 -28
View File
@@ -94,25 +94,15 @@ TwitchChannel::TwitchChannel(const QString &name)
}));
this->refreshPubSub();
this->userStateChanged.connect([this] {
// We can safely ignore this signal connection since it's a private signal, meaning
// it will only ever be invoked by TwitchChannel itself
std::ignore = this->userStateChanged.connect([this] {
this->refreshPubSub();
});
// room id loaded -> refresh live status
this->roomIdChanged.connect([this]() {
this->refreshPubSub();
this->refreshBadges();
this->refreshCheerEmotes();
this->refreshFFZChannelEmotes(false);
this->refreshBTTVChannelEmotes(false);
this->refreshSevenTVChannelEmotes(false);
this->joinBttvChannel();
this->listenSevenTVCosmetics();
getIApp()->getTwitchLiveController()->add(
std::dynamic_pointer_cast<TwitchChannel>(shared_from_this()));
});
this->connected.connect([this]() {
// We can safely ignore this signal connection this has no external dependencies - once the signal
// is destroyed, it will no longer be able to fire
std::ignore = this->connected.connect([this]() {
if (this->roomId().isEmpty())
{
// If we get a reconnected event when the room id is not set, we
@@ -125,18 +115,7 @@ TwitchChannel::TwitchChannel(const QString &name)
this->loadRecentMessagesReconnect();
});
this->messageRemovedFromStart.connect([this](MessagePtr &msg) {
if (msg->replyThread)
{
if (msg->replyThread->liveCount(msg) == 0)
{
this->threads_.erase(msg->replyThread->rootId());
}
}
});
// timers
QObject::connect(&this->chattersListTimer_, &QTimer::timeout, [this] {
this->refreshChatters();
});
@@ -538,6 +517,20 @@ void TwitchChannel::showLoginMessage()
this->addMessage(builder.release());
}
void TwitchChannel::roomIdChanged()
{
this->refreshPubSub();
this->refreshBadges();
this->refreshCheerEmotes();
this->refreshFFZChannelEmotes(false);
this->refreshBTTVChannelEmotes(false);
this->refreshSevenTVChannelEmotes(false);
this->joinBttvChannel();
this->listenSevenTVCosmetics();
getIApp()->getTwitchLiveController()->add(
std::dynamic_pointer_cast<TwitchChannel>(shared_from_this()));
}
QString TwitchChannel::prepareMessage(const QString &message) const
{
auto app = getApp();
@@ -729,7 +722,7 @@ void TwitchChannel::setRoomId(const QString &id)
if (*this->roomID_.accessConst() != id)
{
*this->roomID_.access() = id;
this->roomIdChanged.invoke();
this->roomIdChanged();
this->loadRecentMessages();
}
}
@@ -1063,6 +1056,17 @@ bool TwitchChannel::tryReplaceLastLiveUpdateAddOrRemove(
return true;
}
void TwitchChannel::messageRemovedFromStart(const MessagePtr &msg)
{
if (msg->replyThread)
{
if (msg->replyThread->liveCount(msg) == 0)
{
this->threads_.erase(msg->replyThread->rootId());
}
}
}
const QString &TwitchChannel::subscriptionUrl()
{
return this->subscriptionUrl_;
+8 -4
View File
@@ -191,8 +191,7 @@ public:
const std::unordered_map<QString, std::weak_ptr<MessageThread>> &threads()
const;
// Signals
pajlada::Signals::NoArgSignal roomIdChanged;
// Only TwitchChannel may invoke this signal
pajlada::Signals::NoArgSignal userStateChanged;
/**
@@ -242,8 +241,6 @@ private:
QString actualDisplayName;
} nameOptions;
private:
// Methods
void refreshPubSub();
void refreshChatters();
void refreshBadges();
@@ -252,6 +249,11 @@ private:
void loadRecentMessagesReconnect();
void cleanUpReplyThreads();
void showLoginMessage();
/// roomIdChanged is called whenever this channel's ID has been changed
/// This should only happen once per channel, whenever the ID goes from unset to set
void roomIdChanged();
/** Joins (subscribes to) a Twitch channel for updates on BTTV. */
void joinBttvChannel() const;
/**
@@ -335,6 +337,8 @@ private:
std::unordered_map<QString, std::weak_ptr<MessageThread>> threads_;
protected:
void messageRemovedFromStart(const MessagePtr &msg) override;
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> seventvEmotes_;
+8 -5
View File
@@ -133,21 +133,24 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection,
std::shared_ptr<Channel> TwitchIrcServer::createChannel(
const QString &channelName)
{
auto channel =
std::shared_ptr<TwitchChannel>(new TwitchChannel(channelName));
auto channel = std::make_shared<TwitchChannel>(channelName);
channel->initialize();
channel->sendMessageSignal.connect(
// We can safely ignore these signal connections since the TwitchIrcServer is only
// ever destroyed when the full Application state is about to be destroyed, at which point
// no Channel's should live
// NOTE: CHANNEL_LIFETIME
std::ignore = channel->sendMessageSignal.connect(
[this, channel = channel.get()](auto &chan, auto &msg, bool &sent) {
this->onMessageSendRequested(channel, msg, sent);
});
channel->sendReplySignal.connect(
std::ignore = channel->sendReplySignal.connect(
[this, channel = channel.get()](auto &chan, auto &msg, auto &replyId,
bool &sent) {
this->onReplySendRequested(channel, msg, replyId, sent);
});
return std::shared_ptr<Channel>(channel);
return channel;
}
void TwitchIrcServer::privateMessageReceived(