Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signal connection nodiscard warnings #4818

Merged
merged 38 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9944f9c
SplitHeader: Fix split signal connection warnings
pajlada Sep 15, 2023
5c139be
SplitHeader: Clean up mode update code
pajlada Sep 15, 2023
ae80e81
SplitHeader: Ensure the layout is only created once
pajlada Sep 15, 2023
8708e9c
SplitInput: Fix child UI signal connection warnings
pajlada Sep 15, 2023
6c9009c
ReplyThreadPopup: Fix child UI signal connection warnings
pajlada Sep 15, 2023
6e94668
Clean up Application signal connections
pajlada Sep 15, 2023
78dbf0c
Clean up AccountController signal connections
pajlada Sep 15, 2023
c3268c4
Clean up CommandController signal connections
pajlada Sep 15, 2023
006a89b
Clean up NotificationController signal connections
pajlada Sep 15, 2023
1cc8b5d
Clean up Irc2 signal connections
pajlada Sep 15, 2023
d3db178
Change IrcConnection's smartReconnect signal into a function
pajlada Sep 15, 2023
16073cf
Fix signal connections in SelectChannelDialog
pajlada Sep 15, 2023
bee2212
Clean up ChannelView signal connections
pajlada Sep 15, 2023
e706834
Clean up Split signal connections
pajlada Sep 15, 2023
fd7c001
Clean up HighlightingPage signal connections
pajlada Sep 15, 2023
1186698
Clean up IgnoresPage signal connections
pajlada Sep 15, 2023
77ad3e5
Clean up ModerationPage signal connections
pajlada Sep 15, 2023
5bf1787
Clean up NotificationPage signal connections
pajlada Sep 15, 2023
3a472f3
Clean up KeyboardSettingsPage signal connections
pajlada Sep 15, 2023
1ee5ef4
Clean up FiltersPage signal connections
pajlada Sep 15, 2023
f08ece4
Clean up GeneralPageView signal connections
pajlada Sep 15, 2023
3b76334
Clean up NicknamesPage signal connections
pajlada Sep 15, 2023
1d8e069
Clean up AccountsPage signal connections
pajlada Sep 15, 2023
c119058
Clean up CommandPage signal connections
pajlada Sep 15, 2023
65e3e61
Clean up UserInfoPopup signal connections
pajlada Sep 15, 2023
375259b
Clean up EmotePopup signal connections
pajlada Sep 15, 2023
72f1e6b
Clean up TwitchAccountManager signal connections
pajlada Sep 15, 2023
2e0f40c
Clean up Logging signal connections
pajlada Sep 15, 2023
9ba4e45
Clean up TwitchIrcServer signal connections
pajlada Sep 15, 2023
a8d50e5
Mini TwitchIrcServer.cpp refactor :tf:
pajlada Sep 15, 2023
06f1784
Clean up AccountSwitchWidget signal connections when it gets destroyed
pajlada Sep 15, 2023
c5c778c
Clean up signal connection in WindowManager
pajlada Sep 15, 2023
fe17ece
Clean up InitUpdateButton signal connections
pajlada Sep 15, 2023
f2cd112
Clean up some TwitchChannel signal connections
pajlada Sep 15, 2023
15540cc
TwitchChannel/Channel: Convert the `messageRemovedFromStart` signal i…
pajlada Sep 15, 2023
8023903
TwitchChannel: Refactor roomIdChanged into a function
pajlada Sep 15, 2023
959f6d9
Add changelog entry
pajlada Sep 15, 2023
eb4a285
comment
pajlada Sep 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- Dev: Fix clang-tidy `cppcoreguidelines-pro-type-member-init` warnings. (#4426)
- Dev: Immediate layout for invisible `ChannelView`s is skipped. (#4811)
- Dev: Refactor `Image` & Image's `Frames`. (#4773)
- Dev: Clarify signal connection lifetimes where applicable. (#4818)

## 2.4.5

Expand Down
416 changes: 221 additions & 195 deletions src/Application.cpp

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void Channel::addMessage(MessagePtr message,

if (this->messages_.pushBack(message, deleted))
{
this->messageRemovedFromStart.invoke(deleted);
this->messageRemovedFromStart(deleted);
}

this->messageAppended.invoke(message, overridingFlags);
Expand Down Expand Up @@ -353,6 +353,10 @@ void Channel::onConnected()
{
}

void Channel::messageRemovedFromStart(const MessagePtr &msg)
{
}

//
// Indirect channel
//
Expand Down
2 changes: 1 addition & 1 deletion src/common/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Channel : public std::enable_shared_from_this<Channel>
pajlada::Signals::Signal<const QString &, const QString &, const QString &,
bool &>
sendReplySignal;
pajlada::Signals::Signal<MessagePtr &> messageRemovedFromStart;
pajlada::Signals::Signal<MessagePtr &, boost::optional<MessageFlags>>
messageAppended;
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
Expand Down Expand Up @@ -114,6 +113,7 @@ class Channel : public std::enable_shared_from_this<Channel>

protected:
virtual void onConnected();
virtual void messageRemovedFromStart(const MessagePtr &msg);

private:
const QString name_;
Expand Down
37 changes: 21 additions & 16 deletions src/controllers/accounts/AccountController.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AccountController.hpp"
#include "controllers/accounts/AccountController.hpp"

#include "controllers/accounts/Account.hpp"
#include "controllers/accounts/AccountModel.hpp"
Expand All @@ -10,22 +10,27 @@ namespace chatterino {
AccountController::AccountController()
: accounts_(SharedPtrElementLess<Account>{})
{
this->twitch.accounts.itemInserted.connect([this](const auto &args) {
this->accounts_.insert(std::dynamic_pointer_cast<Account>(args.item));
});

this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
if (args.caller != this)
{
auto &accs = this->twitch.accounts.raw();
auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end());

this->accounts_.removeAt(it - accs.begin(), this);
}
});
// These signal connections can safely be ignored since the twitch object
// will always be destroyed before the AccountController
std::ignore =
this->twitch.accounts.itemInserted.connect([this](const auto &args) {
this->accounts_.insert(
std::dynamic_pointer_cast<Account>(args.item));
});

std::ignore =
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
if (args.caller != this)
{
auto &accs = this->twitch.accounts.raw();
auto it = std::find(accs.begin(), accs.end(), args.item);
assert(it != accs.end());

this->accounts_.removeAt(it - accs.begin(), this);
}
});

this->accounts_.itemRemoved.connect([this](const auto &args) {
std::ignore = this->accounts_.itemRemoved.connect([this](const auto &args) {
switch (args.item->getProviderId())
{
case ProviderId::Twitch: {
Expand Down
8 changes: 5 additions & 3 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ void CommandController::initialize(Settings &, Paths &paths)

this->maxSpaces_ = maxSpaces;
};
this->items.itemInserted.connect(addFirstMatchToMap);
this->items.itemRemoved.connect(addFirstMatchToMap);
// We can safely ignore these signal connections since items will be destroyed
// before CommandController
std::ignore = this->items.itemInserted.connect(addFirstMatchToMap);
std::ignore = this->items.itemRemoved.connect(addFirstMatchToMap);

// Initialize setting manager for commands.json
auto path = combinePath(paths.settingsDirectory, "commands.json");
Expand All @@ -604,7 +606,7 @@ void CommandController::initialize(Settings &, Paths &paths)

// Update the setting when the vector of commands has been updated (most
// likely from the settings dialog)
this->items.delayedItemsChanged.connect([this] {
std::ignore = this->items.delayedItemsChanged.connect([this] {
this->commandsSetting_->setValue(this->items.raw());
});

Expand Down
10 changes: 7 additions & 3 deletions src/controllers/notifications/NotificationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
this->channelMap[Platform::Twitch].append(channelName);
}

this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] {
this->twitchSetting_.setValue(this->channelMap[Platform::Twitch].raw());
});
// We can safely ignore this signal connection since channelMap will always be destroyed
// before the NotificationController
std::ignore =
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] {
this->twitchSetting_.setValue(
this->channelMap[Platform::Twitch].raw());
});

liveStatusTimer_ = new QTimer();

Expand Down
4 changes: 2 additions & 2 deletions src/providers/irc/AbstractIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,7 +86,7 @@ AbstractIrcServer::AbstractIrcServer()
this->addGlobalSystemMessage(
"Server connection timed out, reconnecting");
}
this->readConnection_->smartReconnect.invoke();
this->readConnection_->smartReconnect();
});
}

Expand Down
12 changes: 9 additions & 3 deletions src/providers/irc/Irc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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())
Expand All @@ -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();
});
}
Expand Down
25 changes: 13 additions & 12 deletions src/providers/irc/IrcConnection2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/providers/irc/IrcConnection2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class IrcConnection : public Communi::IrcConnection
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();
Expand Down
4 changes: 3 additions & 1 deletion src/providers/twitch/TwitchAccountManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
Expand Down
60 changes: 32 additions & 28 deletions src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
});
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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_;
Expand Down
12 changes: 8 additions & 4 deletions src/providers/twitch/TwitchChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ class TwitchChannel : public Channel, public ChannelChatters
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;

/**
Expand Down Expand Up @@ -242,8 +241,6 @@ class TwitchChannel : public Channel, public ChannelChatters
QString actualDisplayName;
} nameOptions;

private:
// Methods
void refreshPubSub();
void refreshChatters();
void refreshBadges();
Expand All @@ -252,6 +249,11 @@ class TwitchChannel : public Channel, public ChannelChatters
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;
/**
Expand Down Expand Up @@ -335,6 +337,8 @@ class TwitchChannel : public Channel, public ChannelChatters
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_;
Expand Down
Loading