From ac8873056310a5f9ad3ff1dfd71a56a39a9d3f9f Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 25 Aug 2024 13:38:57 +0200 Subject: [PATCH] fix: remove deprecated `Application::getTwitchAbstract` (#5560) --- CHANGELOG.md | 1 + mocks/include/mocks/EmptyApplication.hpp | 7 ------- src/Application.cpp | 7 ------- src/Application.hpp | 3 --- src/controllers/commands/builtin/Misc.cpp | 9 ++++----- .../commands/builtin/twitch/SendWhisper.cpp | 7 +++---- .../notifications/NotificationController.cpp | 2 +- src/controllers/plugins/api/ChannelRef.cpp | 2 +- src/providers/twitch/IrcMessageHandler.cpp | 19 +++++++++---------- src/providers/twitch/TwitchChannel.cpp | 2 +- src/singletons/NativeMessaging.cpp | 7 +++---- src/singletons/StreamerMode.cpp | 4 ++-- src/singletons/WindowManager.cpp | 5 ++--- src/widgets/FramelessEmbedWindow.cpp | 3 +-- src/widgets/Window.cpp | 16 ++++++++-------- src/widgets/dialogs/SelectChannelDialog.cpp | 2 +- src/widgets/dialogs/UserInfoPopup.cpp | 7 +++---- src/widgets/dialogs/switcher/NewPopupItem.cpp | 3 +-- src/widgets/dialogs/switcher/NewTabItem.cpp | 2 +- src/widgets/helper/ChannelView.cpp | 4 ++-- src/widgets/splits/Split.cpp | 2 +- 21 files changed, 45 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cceb0c34..69b5315e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ - Dev: Refactored 7TV/BTTV definitions out of `TwitchIrcServer` into `Application`. (#5532) - Dev: Refactored code that's responsible for deleting old update files. (#5535) - Dev: Cleanly exit on shutdown. (#5537) +- Dev: Removed the `getTwitchAbstract` method in `Application`. (#5560) - Dev: Renamed threads created by Chatterino on Linux and Windows. (#5538, #5539, #5544) - Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527) - Dev: Added `FlagsEnum::isEmpty`. (#5550) diff --git a/mocks/include/mocks/EmptyApplication.hpp b/mocks/include/mocks/EmptyApplication.hpp index 1cf368154..63f928537 100644 --- a/mocks/include/mocks/EmptyApplication.hpp +++ b/mocks/include/mocks/EmptyApplication.hpp @@ -133,13 +133,6 @@ public: return nullptr; } - ITwitchIrcServer *getTwitchAbstract() override - { - assert(false && "EmptyApplication::getTwitchAbstract was called " - "without being initialized"); - return nullptr; - } - PubSub *getTwitchPubSub() override { assert(false && "getTwitchPubSub was called without being initialized"); diff --git a/src/Application.cpp b/src/Application.cpp index a341a4702..c8c1bf5d6 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -512,13 +512,6 @@ ITwitchIrcServer *Application::getTwitch() return this->twitch.get(); } -ITwitchIrcServer *Application::getTwitchAbstract() -{ - assertInGuiThread(); - - return this->twitch.get(); -} - PubSub *Application::getTwitchPubSub() { assertInGuiThread(); diff --git a/src/Application.hpp b/src/Application.hpp index 7eb7abda8..7fe804ae2 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -83,7 +83,6 @@ public: virtual HighlightController *getHighlights() = 0; virtual NotificationController *getNotifications() = 0; virtual ITwitchIrcServer *getTwitch() = 0; - virtual ITwitchIrcServer *getTwitchAbstract() = 0; virtual PubSub *getTwitchPubSub() = 0; virtual ILogging *getChatLogger() = 0; virtual IChatterinoBadges *getChatterinoBadges() = 0; @@ -194,8 +193,6 @@ public: NotificationController *getNotifications() override; HighlightController *getHighlights() override; ITwitchIrcServer *getTwitch() override; - [[deprecated("use getTwitch()")]] ITwitchIrcServer *getTwitchAbstract() - override; PubSub *getTwitchPubSub() override; ILogging *getChatLogger() override; FfzBadges *getFfzBadges() override; diff --git a/src/controllers/commands/builtin/Misc.cpp b/src/controllers/commands/builtin/Misc.cpp index 0b34dc5b4..a1adf5b34 100644 --- a/src/controllers/commands/builtin/Misc.cpp +++ b/src/controllers/commands/builtin/Misc.cpp @@ -388,7 +388,7 @@ QString popup(const CommandContext &ctx) } // Open channel passed as argument in a popup - auto targetChannel = getApp()->getTwitchAbstract()->getOrAddChannel(target); + auto targetChannel = getApp()->getTwitch()->getOrAddChannel(target); getApp()->getWindows()->openInPopup(targetChannel); return ""; @@ -530,8 +530,7 @@ QString sendRawMessage(const CommandContext &ctx) if (ctx.channel->isTwitchChannel()) { - getApp()->getTwitchAbstract()->sendRawMessage( - ctx.words.mid(1).join(" ")); + getApp()->getTwitch()->sendRawMessage(ctx.words.mid(1).join(" ")); } else { @@ -564,7 +563,7 @@ QString injectFakeMessage(const CommandContext &ctx) } auto ircText = ctx.words.mid(1).join(" "); - getApp()->getTwitchAbstract()->addFakeMessage(ircText); + getApp()->getTwitch()->addFakeMessage(ircText); return ""; } @@ -663,7 +662,7 @@ QString openUsercard(const CommandContext &ctx) stripChannelName(channelName); ChannelPtr channelTemp = - getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); + getApp()->getTwitch()->getChannelOrEmpty(channelName); if (channelTemp->isEmpty()) { diff --git a/src/controllers/commands/builtin/twitch/SendWhisper.cpp b/src/controllers/commands/builtin/twitch/SendWhisper.cpp index cb965d579..cd099ac23 100644 --- a/src/controllers/commands/builtin/twitch/SendWhisper.cpp +++ b/src/controllers/commands/builtin/twitch/SendWhisper.cpp @@ -182,10 +182,9 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) !(getSettings()->streamerModeSuppressInlineWhispers && getApp()->getStreamerMode()->isEnabled())) { - app->getTwitchAbstract()->forEachChannel( - [&messagexD](ChannelPtr _channel) { - _channel->addMessage(messagexD, MessageContext::Repost); - }); + app->getTwitch()->forEachChannel([&messagexD](ChannelPtr _channel) { + _channel->addMessage(messagexD, MessageContext::Repost); + }); } return true; diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 5f9d33e0d..7de9595ad 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -179,7 +179,7 @@ void NotificationController::fetchFakeChannels() for (size_t i = 0; i < channelMap[Platform::Twitch].raw().size(); i++) { const auto &name = channelMap[Platform::Twitch].raw()[i]; - auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(name); + auto chan = getApp()->getTwitch()->getChannelOrEmpty(name); if (chan->isEmpty()) { channels.push_back(name); diff --git a/src/controllers/plugins/api/ChannelRef.cpp b/src/controllers/plugins/api/ChannelRef.cpp index 68cf15980..a57e60119 100644 --- a/src/controllers/plugins/api/ChannelRef.cpp +++ b/src/controllers/plugins/api/ChannelRef.cpp @@ -300,7 +300,7 @@ int ChannelRef::get_by_name(lua_State *L) lua_pushnil(L); return 1; } - auto chn = getApp()->getTwitchAbstract()->getChannelOrEmpty(name); + auto chn = getApp()->getTwitch()->getChannelOrEmpty(name); lua::push(L, chn); return 1; } diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 81a0cc7d1..35ec83761 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -732,7 +732,7 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message) { return; } - auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); + auto chan = getApp()->getTwitch()->getChannelOrEmpty(chanName); auto *twitchChannel = dynamic_cast(chan.get()); if (!twitchChannel) @@ -794,7 +794,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) } // get channel - auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); + auto chan = getApp()->getTwitch()->getChannelOrEmpty(chanName); if (chan->isEmpty()) { @@ -839,7 +839,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) } // get channel - auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); + auto chan = getApp()->getTwitch()->getChannelOrEmpty(chanName); if (chan->isEmpty()) { @@ -887,7 +887,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) return; } - auto c = getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); + auto c = getApp()->getTwitch()->getChannelOrEmpty(channelName); if (c->isEmpty()) { return; @@ -976,8 +976,8 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) !(getSettings()->streamerModeSuppressInlineWhispers && getApp()->getStreamerMode()->isEnabled())) { - getApp()->getTwitchAbstract()->forEachChannel([&message, overrideFlags]( - ChannelPtr channel) { + getApp()->getTwitch()->forEachChannel([&message, overrideFlags]( + ChannelPtr channel) { channel->addMessage(message, MessageContext::Repost, overrideFlags); }); } @@ -1119,8 +1119,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) return; } - auto channel = - getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); + auto channel = getApp()->getTwitch()->getChannelOrEmpty(channelName); if (channel->isEmpty()) { @@ -1202,7 +1201,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) { - auto channel = getApp()->getTwitchAbstract()->getChannelOrEmpty( + auto channel = getApp()->getTwitch()->getChannelOrEmpty( message->parameter(0).remove(0, 1)); auto *twitchChannel = dynamic_cast(channel.get()); @@ -1225,7 +1224,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message) { - auto channel = getApp()->getTwitchAbstract()->getChannelOrEmpty( + auto channel = getApp()->getTwitch()->getChannelOrEmpty( message->parameter(0).remove(0, 1)); auto *twitchChannel = dynamic_cast(channel.get()); diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index c9c105176..52eea65b3 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -725,7 +725,7 @@ bool TwitchChannel::canReconnect() const void TwitchChannel::reconnect() { - getApp()->getTwitchAbstract()->connect(); + getApp()->getTwitch()->connect(); } QString TwitchChannel::getCurrentStreamID() const diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index 72dc1c3b6..5406fb4d2 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -254,7 +254,7 @@ void NativeMessagingServer::ReceiverThread::handleSelect( postToThread([=] { if (!name.isEmpty()) { - auto channel = getApp()->getTwitchAbstract()->getOrAddChannel(name); + auto channel = getApp()->getTwitch()->getOrAddChannel(name); if (getApp()->getTwitch()->getWatchingChannel().get() != channel) { getApp()->getTwitch()->setWatchingChannel(channel); @@ -268,7 +268,7 @@ void NativeMessagingServer::ReceiverThread::handleSelect( if (!name.isEmpty()) { window->setChannel( - getApp()->getTwitchAbstract()->getOrAddChannel(name)); + getApp()->getTwitch()->getOrAddChannel(name)); } #endif } @@ -319,8 +319,7 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels) continue; } // the deduping is done on the extension side - updated.emplace_back( - getApp()->getTwitchAbstract()->getOrAddChannel(name)); + updated.emplace_back(getApp()->getTwitch()->getOrAddChannel(name)); } // This will destroy channels that aren't used anymore. diff --git a/src/singletons/StreamerMode.cpp b/src/singletons/StreamerMode.cpp index fac58aaad..3d8d0d2cb 100644 --- a/src/singletons/StreamerMode.cpp +++ b/src/singletons/StreamerMode.cpp @@ -74,7 +74,7 @@ bool isBroadcasterSoftwareActive() shouldShowTimeoutWarning = false; postToThread([] { - getApp()->getTwitchAbstract()->addGlobalSystemMessage( + getApp()->getTwitch()->addGlobalSystemMessage( "Streamer Mode is set to Automatic, but pgrep timed " "out. This can happen if your system lagged at the " "wrong moment. If Streamer Mode continues to not work, " @@ -94,7 +94,7 @@ bool isBroadcasterSoftwareActive() shouldShowWarning = false; postToThread([] { - getApp()->getTwitchAbstract()->addGlobalSystemMessage( + getApp()->getTwitch()->addGlobalSystemMessage( "Streamer Mode is set to Automatic, but pgrep is " "missing. " "Install it to fix the issue or set Streamer Mode to " diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index c76437481..9581224e9 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -668,8 +668,7 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor) if (descriptor.type_ == "twitch") { - return getApp()->getTwitchAbstract()->getOrAddChannel( - descriptor.channelName_); + return getApp()->getTwitch()->getOrAddChannel(descriptor.channelName_); } else if (descriptor.type_ == "mentions") { @@ -693,7 +692,7 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor) } else if (descriptor.type_ == "misc") { - return getApp()->getTwitchAbstract()->getChannelOrEmpty( + return getApp()->getTwitch()->getChannelOrEmpty( descriptor.channelName_); } diff --git a/src/widgets/FramelessEmbedWindow.cpp b/src/widgets/FramelessEmbedWindow.cpp index 109a8bd55..550cd9052 100644 --- a/src/widgets/FramelessEmbedWindow.cpp +++ b/src/widgets/FramelessEmbedWindow.cpp @@ -54,8 +54,7 @@ bool FramelessEmbedWindow::nativeEvent(const QByteArray &eventType, auto channelName = root.value("channel-name").toString(); this->split_->setChannel( - getApp()->getTwitchAbstract()->getOrAddChannel( - channelName)); + getApp()->getTwitch()->getOrAddChannel(channelName)); } } } diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index b1c72012a..d91ca41df 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -261,7 +261,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleMiscMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitch()->addFakeMessage(msg); return ""; }); @@ -269,7 +269,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleCheerMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitch()->addFakeMessage(msg); return ""; }); @@ -277,7 +277,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleLinkMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitch()->addFakeMessage(msg); return ""; }); @@ -292,7 +292,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) oMessage->toInner() ->toInner(); - getApp()->getTwitchAbstract()->addFakeMessage( + getApp()->getTwitch()->addFakeMessage( getSampleChannelRewardIRCMessage()); getApp()->getTwitchPubSub()->pointReward.redeemed.invoke( oInnerMessage->data.value("redemption").toObject()); @@ -316,7 +316,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleEmoteTestMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitch()->addFakeMessage(msg); return ""; }); @@ -324,7 +324,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleSubMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->getTwitchAbstract()->addFakeMessage(msg); + getApp()->getTwitch()->addFakeMessage(msg); return ""; }); #endif @@ -487,8 +487,8 @@ void Window::addShortcuts() splitContainer = this->notebook_->getOrAddSelectedPage(); } Split *split = new Split(splitContainer); - split->setChannel(getApp()->getTwitchAbstract()->getOrAddChannel( - si.channelName)); + split->setChannel( + getApp()->getTwitch()->getOrAddChannel(si.channelName)); split->setFilters(si.filters); splitContainer->insertSplit(split); splitContainer->setSelected(split); diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index 559ebde0e..813d87137 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -262,7 +262,7 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const case TAB_TWITCH: { if (this->ui_.twitch.channel->isChecked()) { - return getApp()->getTwitchAbstract()->getOrAddChannel( + return getApp()->getTwitch()->getOrAddChannel( this->ui_.twitch.channelName->text().trimmed()); } else if (this->ui_.twitch.watching->isChecked()) diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 6ddb87586..4703cac76 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -305,16 +305,15 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) .getOrAddSelectedPage() ->appendNewSplit(false); split->setChannel( - app->getTwitchAbstract()->getOrAddChannel( + app->getTwitch()->getOrAddChannel( loginName.toLower())); }); menu->addAction( "Open channel in a new tab", this, [loginName] { ChannelPtr channel = - getApp() - ->getTwitchAbstract() - ->getOrAddChannel(loginName); + getApp()->getTwitch()->getOrAddChannel( + loginName); auto &nb = getApp() ->getWindows() ->getMainWindow() diff --git a/src/widgets/dialogs/switcher/NewPopupItem.cpp b/src/widgets/dialogs/switcher/NewPopupItem.cpp index 2f79693a0..5c60d471b 100644 --- a/src/widgets/dialogs/switcher/NewPopupItem.cpp +++ b/src/widgets/dialogs/switcher/NewPopupItem.cpp @@ -21,8 +21,7 @@ NewPopupItem::NewPopupItem(const QString &channelName) void NewPopupItem::action() { - auto channel = - getApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_); + auto channel = getApp()->getTwitch()->getOrAddChannel(this->channelName_); getApp()->getWindows()->openInPopup(channel); } diff --git a/src/widgets/dialogs/switcher/NewTabItem.cpp b/src/widgets/dialogs/switcher/NewTabItem.cpp index 0ce337e15..3b4746cf6 100644 --- a/src/widgets/dialogs/switcher/NewTabItem.cpp +++ b/src/widgets/dialogs/switcher/NewTabItem.cpp @@ -27,7 +27,7 @@ void NewTabItem::action() Split *split = new Split(container); split->setChannel( - getApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_)); + getApp()->getTwitch()->getOrAddChannel(this->channelName_)); container->insertSplit(split); } diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 9f410b9f9..5c07be6b3 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -2763,8 +2763,8 @@ void ChannelView::showUserInfoPopup(const QString &userName, auto *userPopup = new UserInfoPopup(getSettings()->autoCloseUserPopup, this->split_); - auto contextChannel = getApp()->getTwitchAbstract()->getChannelOrEmpty( - alternativePopoutChannel); + auto contextChannel = + getApp()->getTwitch()->getChannelOrEmpty(alternativePopoutChannel); auto openingChannel = this->hasSourceChannel() ? this->sourceChannel_ : this->underlyingChannel_; userPopup->setData(userName, contextChannel, openingChannel); diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 6fbfc12c5..490573140 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -271,7 +271,7 @@ Split::Split(QWidget *parent) std::ignore = this->view_->openChannelIn.connect( [this](QString twitchChannel, FromTwitchLinkOpenChannelIn openIn) { ChannelPtr channel = - getApp()->getTwitchAbstract()->getOrAddChannel(twitchChannel); + getApp()->getTwitch()->getOrAddChannel(twitchChannel); switch (openIn) { case FromTwitchLinkOpenChannelIn::Split: