From b6dc5d9e03aad21f1b8c76c588a1a627fbe41c9e Mon Sep 17 00:00:00 2001 From: pajlada Date: Sat, 1 Jun 2024 14:56:40 +0200 Subject: [PATCH] chore: refactor TwitchIrcServer (#5421) --- CHANGELOG.md | 1 + mocks/include/mocks/EmptyApplication.hpp | 7 ++ mocks/include/mocks/TwitchIrcServer.hpp | 74 ++++++++++++++++++ src/Application.cpp | 77 ++++++++++++------- src/Application.hpp | 9 +-- src/controllers/commands/builtin/Misc.cpp | 13 ++-- .../commands/builtin/twitch/SendWhisper.cpp | 6 +- .../notifications/NotificationController.cpp | 6 +- src/controllers/plugins/api/ChannelRef.cpp | 4 +- src/providers/irc/AbstractIrcServer.hpp | 33 ++++++-- src/providers/irc/IrcServer.cpp | 2 +- src/providers/twitch/IrcMessageHandler.cpp | 56 +++++++------- src/providers/twitch/IrcMessageHandler.hpp | 11 ++- src/providers/twitch/TwitchChannel.cpp | 41 +++++----- src/providers/twitch/TwitchIrcServer.cpp | 44 ++++++++++- src/providers/twitch/TwitchIrcServer.hpp | 38 ++++++++- src/singletons/NativeMessaging.cpp | 17 ++-- src/singletons/StreamerMode.cpp | 4 +- src/singletons/WindowManager.cpp | 16 ++-- src/widgets/FramelessEmbedWindow.cpp | 3 +- src/widgets/Window.cpp | 17 ++-- src/widgets/dialogs/SelectChannelDialog.cpp | 14 ++-- src/widgets/dialogs/UserInfoPopup.cpp | 12 +-- src/widgets/dialogs/switcher/NewPopupItem.cpp | 3 +- src/widgets/dialogs/switcher/NewTabItem.cpp | 3 +- src/widgets/helper/ChannelView.cpp | 21 ++--- src/widgets/settingspages/GeneralPage.cpp | 2 +- src/widgets/splits/Split.cpp | 2 +- 28 files changed, 373 insertions(+), 163 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 430291ed0..1ac43b47a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Dev: Add doxygen build target. (#5377) - Dev: Make printing of strings in tests easier. (#5379) - Dev: Refactor and document `Scrollbar`. (#5334, #5393) +- Dev: Refactor `TwitchIrcServer`, making it abstracted. (#5421) - Dev: Reduced the amount of scale events. (#5404, #5406) - Dev: Removed unused timegate settings. (#5361) - Dev: All Lua globals now show in the `c2` global in the LuaLS metadata. (#5385) diff --git a/mocks/include/mocks/EmptyApplication.hpp b/mocks/include/mocks/EmptyApplication.hpp index 5d5ea1064..54906f56c 100644 --- a/mocks/include/mocks/EmptyApplication.hpp +++ b/mocks/include/mocks/EmptyApplication.hpp @@ -118,6 +118,13 @@ public: return nullptr; } + IAbstractIrcServer *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/mocks/include/mocks/TwitchIrcServer.hpp b/mocks/include/mocks/TwitchIrcServer.hpp index 976d6f2ad..42abc30ec 100644 --- a/mocks/include/mocks/TwitchIrcServer.hpp +++ b/mocks/include/mocks/TwitchIrcServer.hpp @@ -2,8 +2,13 @@ #include "mocks/Channel.hpp" #include "providers/bttv/BttvEmotes.hpp" +#include "providers/bttv/BttvLiveUpdates.hpp" #include "providers/ffz/FfzEmotes.hpp" +#include "providers/seventv/eventapi/Client.hpp" +#include "providers/seventv/eventapi/Dispatch.hpp" +#include "providers/seventv/eventapi/Message.hpp" #include "providers/seventv/SeventvEmotes.hpp" +#include "providers/seventv/SeventvEventAPI.hpp" #include "providers/twitch/TwitchIrcServer.hpp" namespace chatterino::mock { @@ -16,22 +21,91 @@ public: std::shared_ptr(new MockChannel("testaccount_420"))) , watchingChannel(this->watchingChannelInner, Channel::Type::TwitchWatching) + , whispersChannel(std::shared_ptr(new MockChannel("whispers"))) + , mentionsChannel(std::shared_ptr(new MockChannel("forsen3"))) + , liveChannel(std::shared_ptr(new MockChannel("forsen"))) + , automodChannel(std::shared_ptr(new MockChannel("forsen2"))) { } + void forEachChannelAndSpecialChannels( + std::function func) override + { + // + } + + std::shared_ptr getChannelOrEmptyByID( + const QString &channelID) override + { + return {}; + } + + void dropSeventvChannel(const QString &userID, + const QString &emoteSetID) override + { + // + } + + std::unique_ptr &getBTTVLiveUpdates() override + { + return this->bttvLiveUpdates; + } + + std::unique_ptr &getSeventvEventAPI() override + { + return this->seventvEventAPI; + } + const IndirectChannel &getWatchingChannel() const override { return this->watchingChannel; } + void setWatchingChannel(ChannelPtr newWatchingChannel) override + { + this->watchingChannel.reset(newWatchingChannel); + } + QString getLastUserThatWhisperedMe() const override { return this->lastUserThatWhisperedMe; } + void setLastUserThatWhisperedMe(const QString &user) override + { + this->lastUserThatWhisperedMe = user; + } + + ChannelPtr getWhispersChannel() const override + { + return this->whispersChannel; + } + + ChannelPtr getMentionsChannel() const override + { + return this->mentionsChannel; + } + + ChannelPtr getLiveChannel() const override + { + return this->liveChannel; + } + + ChannelPtr getAutomodChannel() const override + { + return this->automodChannel; + } + ChannelPtr watchingChannelInner; IndirectChannel watchingChannel; + ChannelPtr whispersChannel; + ChannelPtr mentionsChannel; + ChannelPtr liveChannel; + ChannelPtr automodChannel; QString lastUserThatWhisperedMe{"forsen"}; + + std::unique_ptr bttvLiveUpdates; + std::unique_ptr seventvEventAPI; }; } // namespace chatterino::mock diff --git a/src/Application.cpp b/src/Application.cpp index e412fe8f4..5d70316bf 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -13,6 +13,7 @@ #include "controllers/sound/ISoundController.hpp" #include "providers/bttv/BttvEmotes.hpp" #include "providers/ffz/FfzEmotes.hpp" +#include "providers/irc/AbstractIrcServer.hpp" #include "providers/links/LinkResolver.hpp" #include "providers/seventv/SeventvAPI.hpp" #include "providers/seventv/SeventvEmotes.hpp" @@ -131,7 +132,7 @@ Application::Application(Settings &_settings, const Paths &paths, , commands(&this->emplace()) , notifications(&this->emplace()) , highlights(&this->emplace()) - , twitch(&this->emplace()) + , twitch(new TwitchIrcServer) , ffzBadges(&this->emplace()) , seventvBadges(&this->emplace()) , userData(&this->emplace(new UserDataController(paths))) @@ -170,6 +171,7 @@ void Application::fakeDtor() this->bttvEmotes.reset(); this->ffzEmotes.reset(); this->seventvEmotes.reset(); + // this->twitch.reset(); this->fonts.reset(); } @@ -483,7 +485,14 @@ ITwitchIrcServer *Application::getTwitch() { assertInGuiThread(); - return this->twitch; + return this->twitch.get(); +} + +IAbstractIrcServer *Application::getTwitchAbstract() +{ + assertInGuiThread(); + + return this->twitch.get(); } PubSub *Application::getTwitchPubSub() @@ -865,17 +874,25 @@ void Application::initPubSub() chan->addMessage(p.first); chan->addMessage(p.second); - getApp()->twitch->automodChannel->addMessage( - p.first); - getApp()->twitch->automodChannel->addMessage( - p.second); + getIApp() + ->getTwitch() + ->getAutomodChannel() + ->addMessage(p.first); + getIApp() + ->getTwitch() + ->getAutomodChannel() + ->addMessage(p.second); if (getSettings()->showAutomodInMentions) { - getApp()->twitch->mentionsChannel->addMessage( - p.first); - getApp()->twitch->mentionsChannel->addMessage( - p.second); + getIApp() + ->getTwitch() + ->getMentionsChannel() + ->addMessage(p.first); + getIApp() + ->getTwitch() + ->getMentionsChannel() + ->addMessage(p.second); } }); } @@ -984,7 +1001,9 @@ void Application::initPubSub() void Application::initBttvLiveUpdates() { - if (!this->twitch->bttvLiveUpdates) + auto &bttvLiveUpdates = this->twitch->getBTTVLiveUpdates(); + + if (!bttvLiveUpdates) { qCDebug(chatterinoBttv) << "Skipping initialization of Live Updates as it's disabled"; @@ -993,8 +1012,8 @@ void Application::initBttvLiveUpdates() // We can safely ignore these signal connections since the twitch object will always // be destroyed before the Application - std::ignore = this->twitch->bttvLiveUpdates->signals_.emoteAdded.connect( - [&](const auto &data) { + std::ignore = + bttvLiveUpdates->signals_.emoteAdded.connect([&](const auto &data) { auto chan = this->twitch->getChannelOrEmptyByID(data.channelID); postToThread([chan, data] { @@ -1004,8 +1023,8 @@ void Application::initBttvLiveUpdates() } }); }); - std::ignore = this->twitch->bttvLiveUpdates->signals_.emoteUpdated.connect( - [&](const auto &data) { + std::ignore = + bttvLiveUpdates->signals_.emoteUpdated.connect([&](const auto &data) { auto chan = this->twitch->getChannelOrEmptyByID(data.channelID); postToThread([chan, data] { @@ -1015,8 +1034,8 @@ void Application::initBttvLiveUpdates() } }); }); - std::ignore = this->twitch->bttvLiveUpdates->signals_.emoteRemoved.connect( - [&](const auto &data) { + std::ignore = + bttvLiveUpdates->signals_.emoteRemoved.connect([&](const auto &data) { auto chan = this->twitch->getChannelOrEmptyByID(data.channelID); postToThread([chan, data] { @@ -1026,12 +1045,14 @@ void Application::initBttvLiveUpdates() } }); }); - this->twitch->bttvLiveUpdates->start(); + bttvLiveUpdates->start(); } void Application::initSeventvEventAPI() { - if (!this->twitch->seventvEventAPI) + auto &seventvEventAPI = this->twitch->getSeventvEventAPI(); + + if (!seventvEventAPI) { qCDebug(chatterinoSeventvEventAPI) << "Skipping initialization as the EventAPI is disabled"; @@ -1040,8 +1061,8 @@ void Application::initSeventvEventAPI() // We can safely ignore these signal connections since the twitch object will always // be destroyed before the Application - std::ignore = this->twitch->seventvEventAPI->signals_.emoteAdded.connect( - [&](const auto &data) { + std::ignore = + seventvEventAPI->signals_.emoteAdded.connect([&](const auto &data) { postToThread([this, data] { this->twitch->forEachSeventvEmoteSet( data.emoteSetID, [data](TwitchChannel &chan) { @@ -1049,8 +1070,8 @@ void Application::initSeventvEventAPI() }); }); }); - std::ignore = this->twitch->seventvEventAPI->signals_.emoteUpdated.connect( - [&](const auto &data) { + std::ignore = + seventvEventAPI->signals_.emoteUpdated.connect([&](const auto &data) { postToThread([this, data] { this->twitch->forEachSeventvEmoteSet( data.emoteSetID, [data](TwitchChannel &chan) { @@ -1058,8 +1079,8 @@ void Application::initSeventvEventAPI() }); }); }); - std::ignore = this->twitch->seventvEventAPI->signals_.emoteRemoved.connect( - [&](const auto &data) { + std::ignore = + seventvEventAPI->signals_.emoteRemoved.connect([&](const auto &data) { postToThread([this, data] { this->twitch->forEachSeventvEmoteSet( data.emoteSetID, [data](TwitchChannel &chan) { @@ -1067,15 +1088,15 @@ void Application::initSeventvEventAPI() }); }); }); - std::ignore = this->twitch->seventvEventAPI->signals_.userUpdated.connect( - [&](const auto &data) { + std::ignore = + seventvEventAPI->signals_.userUpdated.connect([&](const auto &data) { this->twitch->forEachSeventvUser(data.userID, [data](TwitchChannel &chan) { chan.updateSeventvUser(data); }); }); - this->twitch->seventvEventAPI->start(); + seventvEventAPI->start(); } Application *getApp() diff --git a/src/Application.hpp b/src/Application.hpp index f846ff00b..795a9f6d9 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -54,6 +54,7 @@ class FfzEmotes; class SeventvEmotes; class ILinkResolver; class IStreamerMode; +class IAbstractIrcServer; class IApplication { @@ -77,6 +78,7 @@ public: virtual HighlightController *getHighlights() = 0; virtual NotificationController *getNotifications() = 0; virtual ITwitchIrcServer *getTwitch() = 0; + virtual IAbstractIrcServer *getTwitchAbstract() = 0; virtual PubSub *getTwitchPubSub() = 0; virtual Logging *getChatLogger() = 0; virtual IChatterinoBadges *getChatterinoBadges() = 0; @@ -147,11 +149,7 @@ private: CommandController *const commands{}; NotificationController *const notifications{}; HighlightController *const highlights{}; - -public: - TwitchIrcServer *const twitch{}; - -private: + std::unique_ptr twitch; FfzBadges *const ffzBadges{}; SeventvBadges *const seventvBadges{}; UserDataController *const userData{}; @@ -191,6 +189,7 @@ public: NotificationController *getNotifications() override; HighlightController *getHighlights() override; ITwitchIrcServer *getTwitch() override; + IAbstractIrcServer *getTwitchAbstract() override; PubSub *getTwitchPubSub() override; Logging *getChatLogger() override; FfzBadges *getFfzBadges() override; diff --git a/src/controllers/commands/builtin/Misc.cpp b/src/controllers/commands/builtin/Misc.cpp index c0b62c2d9..e1940271a 100644 --- a/src/controllers/commands/builtin/Misc.cpp +++ b/src/controllers/commands/builtin/Misc.cpp @@ -390,9 +390,9 @@ QString popup(const CommandContext &ctx) } // Open channel passed as argument in a popup - auto *app = getApp(); - auto targetChannel = app->twitch->getOrAddChannel(target); - app->getWindows()->openInPopup(targetChannel); + auto targetChannel = + getIApp()->getTwitchAbstract()->getOrAddChannel(target); + getIApp()->getWindows()->openInPopup(targetChannel); return ""; } @@ -533,7 +533,8 @@ QString sendRawMessage(const CommandContext &ctx) if (ctx.channel->isTwitchChannel()) { - getApp()->twitch->sendRawMessage(ctx.words.mid(1).join(" ")); + getIApp()->getTwitchAbstract()->sendRawMessage( + ctx.words.mid(1).join(" ")); } else { @@ -566,7 +567,7 @@ QString injectFakeMessage(const CommandContext &ctx) } auto ircText = ctx.words.mid(1).join(" "); - getApp()->twitch->addFakeMessage(ircText); + getIApp()->getTwitchAbstract()->addFakeMessage(ircText); return ""; } @@ -667,7 +668,7 @@ QString openUsercard(const CommandContext &ctx) stripChannelName(channelName); ChannelPtr channelTemp = - getApp()->twitch->getChannelOrEmpty(channelName); + getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); if (channelTemp->isEmpty()) { diff --git a/src/controllers/commands/builtin/twitch/SendWhisper.cpp b/src/controllers/commands/builtin/twitch/SendWhisper.cpp index 6b4cc25bf..1d8046046 100644 --- a/src/controllers/commands/builtin/twitch/SendWhisper.cpp +++ b/src/controllers/commands/builtin/twitch/SendWhisper.cpp @@ -92,7 +92,7 @@ QString formatWhisperError(HelixWhisperError error, const QString &message) bool appendWhisperMessageWordsLocally(const QStringList &words) { - auto *app = getApp(); + auto *app = getIApp(); MessageBuilder b; @@ -177,7 +177,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) b->flags.set(MessageFlag::Whisper); auto messagexD = b.release(); - app->twitch->whispersChannel->addMessage(messagexD); + getIApp()->getTwitch()->getWhispersChannel()->addMessage(messagexD); auto overrideFlags = std::optional(messagexD->flags); overrideFlags->set(MessageFlag::DoNotLog); @@ -186,7 +186,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) !(getSettings()->streamerModeSuppressInlineWhispers && getIApp()->getStreamerMode()->isEnabled())) { - app->twitch->forEachChannel( + app->getTwitchAbstract()->forEachChannel( [&messagexD, overrideFlags](ChannelPtr _channel) { _channel->addMessage(messagexD, overrideFlags); }); diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 745cf383e..cfab7242f 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -124,7 +124,7 @@ void NotificationController::fetchFakeChannels() for (std::vector::size_type i = 0; i < channelMap[Platform::Twitch].raw().size(); i++) { - auto chan = getApp()->twitch->getChannelOrEmpty( + auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty( channelMap[Platform::Twitch].raw()[i]); if (chan->isEmpty()) { @@ -202,7 +202,7 @@ void NotificationController::checkStream(bool live, QString channelName) } MessageBuilder builder; TwitchMessageBuilder::liveMessage(channelName, &builder); - getApp()->twitch->liveChannel->addMessage(builder.release()); + getIApp()->getTwitch()->getLiveChannel()->addMessage(builder.release()); // Indicate that we have pushed notifications for this stream fakeTwitchChannels.push_back(channelName); @@ -217,7 +217,7 @@ void NotificationController::removeFakeChannel(const QString channelName) fakeTwitchChannels.erase(it); // "delete" old 'CHANNEL is live' message LimitedQueueSnapshot snapshot = - getApp()->twitch->liveChannel->getMessageSnapshot(); + getIApp()->getTwitch()->getLiveChannel()->getMessageSnapshot(); int snapshotLength = snapshot.size(); // MSVC hates this code if the parens are not there diff --git a/src/controllers/plugins/api/ChannelRef.cpp b/src/controllers/plugins/api/ChannelRef.cpp index 986fbbac3..1e592d0db 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()->twitch->getChannelOrEmpty(name); + auto chn = getIApp()->getTwitchAbstract()->getChannelOrEmpty(name); lua::push(L, chn); return 1; } @@ -324,7 +324,7 @@ int ChannelRef::get_by_twitch_id(lua_State *L) lua_pushnil(L); return 1; } - auto chn = getApp()->twitch->getChannelOrEmptyByID(id); + auto chn = getIApp()->getTwitch()->getChannelOrEmptyByID(id); lua::push(L, chn); return 1; diff --git a/src/providers/irc/AbstractIrcServer.hpp b/src/providers/irc/AbstractIrcServer.hpp index 7a0e1ee63..0b626f9e0 100644 --- a/src/providers/irc/AbstractIrcServer.hpp +++ b/src/providers/irc/AbstractIrcServer.hpp @@ -17,7 +17,24 @@ class Channel; using ChannelPtr = std::shared_ptr; class RatelimitBucket; -class AbstractIrcServer : public QObject +class IAbstractIrcServer +{ +public: + virtual void connect() = 0; + + virtual void sendRawMessage(const QString &rawMessage) = 0; + + virtual ChannelPtr getOrAddChannel(const QString &dirtyChannelName) = 0; + virtual ChannelPtr getChannelOrEmpty(const QString &dirtyChannelName) = 0; + + virtual void addFakeMessage(const QString &data) = 0; + + virtual void addGlobalSystemMessage(const QString &messageText) = 0; + + virtual void forEachChannel(std::function func) = 0; +}; + +class AbstractIrcServer : public IAbstractIrcServer, public QObject { public: enum ConnectionType { Read = 1, Write = 2, Both = 3 }; @@ -33,27 +50,27 @@ public: void initializeIrc(); // connection - void connect(); + void connect() final; void disconnect(); void sendMessage(const QString &channelName, const QString &message); - virtual void sendRawMessage(const QString &rawMessage); + void sendRawMessage(const QString &rawMessage) override; // channels - ChannelPtr getOrAddChannel(const QString &dirtyChannelName); - ChannelPtr getChannelOrEmpty(const QString &dirtyChannelName); + ChannelPtr getOrAddChannel(const QString &dirtyChannelName) final; + ChannelPtr getChannelOrEmpty(const QString &dirtyChannelName) final; std::vector> getChannels(); // signals pajlada::Signals::NoArgSignal connected; pajlada::Signals::NoArgSignal disconnected; - void addFakeMessage(const QString &data); + void addFakeMessage(const QString &data) final; - void addGlobalSystemMessage(const QString &messageText); + void addGlobalSystemMessage(const QString &messageText) final; // iteration - void forEachChannel(std::function func); + void forEachChannel(std::function func) final; protected: AbstractIrcServer(); diff --git a/src/providers/irc/IrcServer.cpp b/src/providers/irc/IrcServer.cpp index 8d54d79f7..c90211fcb 100644 --- a/src/providers/irc/IrcServer.cpp +++ b/src/providers/irc/IrcServer.cpp @@ -244,7 +244,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message) if (highlighted && showInMentions) { - getApp()->twitch->mentionsChannel->addMessage(msg); + getIApp()->getTwitch()->getMentionsChannel()->addMessage(msg); } } else diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 9dd2d7a4b..d0600b8fa 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -13,6 +13,7 @@ #include "messages/MessageColor.hpp" #include "messages/MessageElement.hpp" #include "messages/MessageThread.hpp" +#include "providers/irc/AbstractIrcServer.hpp" #include "providers/twitch/ChannelPointReward.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchAccountManager.hpp" @@ -169,7 +170,7 @@ void updateReplyParticipatedStatus(const QVariantMap &tags, } ChannelPtr channelOrEmptyByTarget(const QString &target, - TwitchIrcServer &server) + IAbstractIrcServer &server) { QString channelName; if (!trimChannelName(target, channelName)) @@ -677,9 +678,10 @@ std::vector IrcMessageHandler::parseMessageWithReply( } void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, - TwitchIrcServer &server) + ITwitchIrcServer &twitchServer, + IAbstractIrcServer &abstractIrcServer) { - auto chan = channelOrEmptyByTarget(message->target(), server); + auto chan = channelOrEmptyByTarget(message->target(), abstractIrcServer); if (chan->isEmpty()) { return; @@ -710,8 +712,8 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, // https://mm2pl.github.io/emoji_rfc.pdf for more details this->addMessage( message, chan, - message->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), server, - false, message->isAction()); + message->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), + twitchServer, false, message->isAction()); if (message->tags().contains(u"pinned-chat-paid-amount"_s)) { @@ -733,7 +735,7 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message) { return; } - auto chan = getApp()->twitch->getChannelOrEmpty(chanName); + auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); auto *twitchChannel = dynamic_cast(chan.get()); if (!twitchChannel) @@ -795,7 +797,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) } // get channel - auto chan = getApp()->twitch->getChannelOrEmpty(chanName); + auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); if (chan->isEmpty()) { @@ -839,7 +841,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) } // get channel - auto chan = getApp()->twitch->getChannelOrEmpty(chanName); + auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName); if (chan->isEmpty()) { @@ -888,7 +890,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) return; } - auto c = getApp()->twitch->getChannelOrEmpty(channelName); + auto c = getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); if (c->isEmpty()) { return; @@ -943,7 +945,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) args.isReceivedWhisper = true; - auto *c = getApp()->twitch->whispersChannel.get(); + auto *c = getIApp()->getTwitch()->getWhispersChannel().get(); TwitchMessageBuilder builder( c, ircMessage, args, @@ -959,11 +961,11 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) MessagePtr message = builder.build(); builder.triggerHighlights(); - getApp()->twitch->lastUserThatWhisperedMe.set(builder.userName); + getIApp()->getTwitch()->setLastUserThatWhisperedMe(builder.userName); if (message->flags.has(MessageFlag::ShowInMentions)) { - getApp()->twitch->mentionsChannel->addMessage(message); + getIApp()->getTwitch()->getMentionsChannel()->addMessage(message); } c->addMessage(message); @@ -976,15 +978,16 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage) !(getSettings()->streamerModeSuppressInlineWhispers && getIApp()->getStreamerMode()->isEnabled())) { - getApp()->twitch->forEachChannel( + getIApp()->getTwitchAbstract()->forEachChannel( [&message, overrideFlags](ChannelPtr channel) { channel->addMessage(message, overrideFlags); }); } } -void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, - TwitchIrcServer &server) +void IrcMessageHandler::handleUserNoticeMessage( + Communi::IrcMessage *message, ITwitchIrcServer &twitchServer, + IAbstractIrcServer &abstractIrcServer) { auto tags = message->tags(); auto parameters = message->parameters(); @@ -997,7 +1000,7 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, content = parameters[1]; } - auto chn = server.getChannelOrEmpty(target); + auto chn = abstractIrcServer.getChannelOrEmpty(target); if (isIgnoredMessage({ .message = content, .twitchUserID = tags.value("user-id").toString(), @@ -1013,7 +1016,7 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, // Messages are not required, so they might be empty if (!content.isEmpty()) { - this->addMessage(message, chn, content, server, true, false); + this->addMessage(message, chn, content, twitchServer, true, false); } } @@ -1090,7 +1093,7 @@ void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, return; } - auto chan = server.getChannelOrEmpty(channelName); + auto chan = abstractIrcServer.getChannelOrEmpty(channelName); if (!chan->isEmpty()) { @@ -1111,7 +1114,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) { // Notice wasn't targeted at a single channel, send to all twitch // channels - getApp()->twitch->forEachChannelAndSpecialChannels( + getIApp()->getTwitch()->forEachChannelAndSpecialChannels( [msg](const auto &c) { c->addMessage(msg); }); @@ -1119,7 +1122,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) return; } - auto channel = getApp()->twitch->getChannelOrEmpty(channelName); + auto channel = + getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName); if (channel->isEmpty()) { @@ -1202,8 +1206,8 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) { - auto channel = - getApp()->twitch->getChannelOrEmpty(message->parameter(0).remove(0, 1)); + auto channel = getIApp()->getTwitchAbstract()->getChannelOrEmpty( + message->parameter(0).remove(0, 1)); auto *twitchChannel = dynamic_cast(channel.get()); if (!twitchChannel) @@ -1225,8 +1229,8 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message) void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message) { - auto channel = - getApp()->twitch->getChannelOrEmpty(message->parameter(0).remove(0, 1)); + auto channel = getIApp()->getTwitchAbstract()->getChannelOrEmpty( + message->parameter(0).remove(0, 1)); auto *twitchChannel = dynamic_cast(channel.get()); if (!twitchChannel) @@ -1311,7 +1315,7 @@ void IrcMessageHandler::setSimilarityFlags(const MessagePtr &message, void IrcMessageHandler::addMessage(Communi::IrcMessage *message, const ChannelPtr &chan, const QString &originalContent, - TwitchIrcServer &server, bool isSub, + ITwitchIrcServer &server, bool isSub, bool isAction) { if (chan->isEmpty()) @@ -1446,7 +1450,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message, if (highlighted && showInMentions) { - server.mentionsChannel->addMessage(msg); + server.getMentionsChannel()->addMessage(msg); } chan->addMessage(msg); diff --git a/src/providers/twitch/IrcMessageHandler.hpp b/src/providers/twitch/IrcMessageHandler.hpp index 26c21f6da..60dbacaf3 100644 --- a/src/providers/twitch/IrcMessageHandler.hpp +++ b/src/providers/twitch/IrcMessageHandler.hpp @@ -9,7 +9,8 @@ namespace chatterino { -class TwitchIrcServer; +class IAbstractIrcServer; +class ITwitchIrcServer; class Channel; using ChannelPtr = std::shared_ptr; struct Message; @@ -38,7 +39,8 @@ public: std::vector &otherLoaded); void handlePrivMessage(Communi::IrcPrivateMessage *message, - TwitchIrcServer &server); + ITwitchIrcServer &twitchServer, + IAbstractIrcServer &abstractIrcServer); void handleRoomStateMessage(Communi::IrcMessage *message); void handleClearChatMessage(Communi::IrcMessage *message); @@ -48,7 +50,8 @@ public: void handleWhisperMessage(Communi::IrcMessage *ircMessage); void handleUserNoticeMessage(Communi::IrcMessage *message, - TwitchIrcServer &server); + ITwitchIrcServer &twitchServer, + IAbstractIrcServer &abstractIrcServer); void handleNoticeMessage(Communi::IrcNoticeMessage *message); @@ -56,7 +59,7 @@ public: void handlePartMessage(Communi::IrcMessage *message); void addMessage(Communi::IrcMessage *message, const ChannelPtr &chan, - const QString &originalContent, TwitchIrcServer &server, + const QString &originalContent, ITwitchIrcServer &server, bool isSub, bool isAction); private: diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index c478b9191..4339d6c2e 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -176,7 +176,8 @@ TwitchChannel::TwitchChannel(const QString &name) TwitchMessageBuilder::liveMessage(this->getDisplayName(), &builder2); builder2.message().id = this->roomId(); - getApp()->twitch->liveChannel->addMessage(builder2.release()); + getIApp()->getTwitch()->getLiveChannel()->addMessage( + builder2.release()); // Notify on all channels with a ping sound if (getSettings()->notificationOnAnyChannel && @@ -198,7 +199,7 @@ TwitchChannel::TwitchChannel(const QString &name) // "delete" old 'CHANNEL is live' message LimitedQueueSnapshot snapshot = - getApp()->twitch->liveChannel->getMessageSnapshot(); + getIApp()->getTwitch()->getLiveChannel()->getMessageSnapshot(); int snapshotLength = snapshot.size(); // MSVC hates this code if the parens are not there @@ -237,17 +238,18 @@ TwitchChannel::~TwitchChannel() return; } - getApp()->twitch->dropSeventvChannel(this->seventvUserID_, - this->seventvEmoteSetID_); + getIApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_, + this->seventvEmoteSetID_); - if (getApp()->twitch->bttvLiveUpdates) + if (getIApp()->getTwitch()->getBTTVLiveUpdates()) { - getApp()->twitch->bttvLiveUpdates->partChannel(this->roomId()); + getIApp()->getTwitch()->getBTTVLiveUpdates()->partChannel( + this->roomId()); } - if (getApp()->twitch->seventvEventAPI) + if (getIApp()->getTwitch()->getSeventvEventAPI()) { - getApp()->twitch->seventvEventAPI->unsubscribeTwitchChannel( + getIApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel( this->roomId()); } } @@ -425,7 +427,7 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward) << "] Channel point reward added:" << reward.id << "," << reward.title << "," << reward.isUserInputRequired; - auto *server = getApp()->twitch; + auto *server = getIApp()->getTwitch(); auto it = std::remove_if( this->waitingRedemptions_.begin(), this->waitingRedemptions_.end(), [&](const QueuedRedemption &msg) { @@ -776,7 +778,7 @@ bool TwitchChannel::canReconnect() const void TwitchChannel::reconnect() { - getApp()->twitch->connect(); + getIApp()->getTwitchAbstract()->connect(); } QString TwitchChannel::roomId() const @@ -891,7 +893,7 @@ const QString &TwitchChannel::seventvEmoteSetID() const void TwitchChannel::joinBttvChannel() const { - if (getApp()->twitch->bttvLiveUpdates) + if (getIApp()->getTwitch()->getBTTVLiveUpdates()) { const auto currentAccount = getIApp()->getAccounts()->twitch.getCurrent(); @@ -900,8 +902,8 @@ void TwitchChannel::joinBttvChannel() const { userName = currentAccount->getUserName(); } - getApp()->twitch->bttvLiveUpdates->joinChannel(this->roomId(), - userName); + getIApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel( + this->roomId(), userName); } } @@ -1048,14 +1050,14 @@ void TwitchChannel::updateSeventvData(const QString &newUserID, this->seventvUserID_ = newUserID; this->seventvEmoteSetID_ = newEmoteSetID; runInGuiThread([this, oldUserID, oldEmoteSetID]() { - if (getApp()->twitch->seventvEventAPI) + if (getIApp()->getTwitch()->getSeventvEventAPI()) { - getApp()->twitch->seventvEventAPI->subscribeUser( + getIApp()->getTwitch()->getSeventvEventAPI()->subscribeUser( this->seventvUserID_, this->seventvEmoteSetID_); if (oldUserID || oldEmoteSetID) { - getApp()->twitch->dropSeventvChannel( + getIApp()->getTwitch()->dropSeventvChannel( oldUserID.value_or(QString()), oldEmoteSetID.value_or(QString())); } @@ -1251,7 +1253,8 @@ void TwitchChannel::loadRecentMessages() tc->addRecentChatter(msg->displayName); } - getApp()->twitch->mentionsChannel->fillInMissingMessages(msgs); + getIApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages( + msgs); }, [weak]() { auto shared = weak.lock(); @@ -1841,9 +1844,9 @@ void TwitchChannel::updateSevenTVActivity() void TwitchChannel::listenSevenTVCosmetics() const { - if (getApp()->twitch->seventvEventAPI) + if (getIApp()->getTwitch()->getSeventvEventAPI()) { - getApp()->twitch->seventvEventAPI->subscribeTwitchChannel( + getIApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel( this->roomId()); } } diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index f591e8f31..e318d45af 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -263,7 +263,7 @@ std::shared_ptr TwitchIrcServer::createChannel( void TwitchIrcServer::privateMessageReceived( Communi::IrcPrivateMessage *message) { - IrcMessageHandler::instance().handlePrivMessage(message, *this); + IrcMessageHandler::instance().handlePrivMessage(message, *this, *this); } void TwitchIrcServer::readConnectionMessageReceived( @@ -310,7 +310,7 @@ void TwitchIrcServer::readConnectionMessageReceived( } else if (command == "USERNOTICE") { - handler.handleUserNoticeMessage(message, *this); + handler.handleUserNoticeMessage(message, *this, *this); } else if (command == "NOTICE") { @@ -645,16 +645,56 @@ void TwitchIrcServer::onReplySendRequested( sent = true; } +std::unique_ptr &TwitchIrcServer::getBTTVLiveUpdates() +{ + return this->bttvLiveUpdates; +} + +std::unique_ptr &TwitchIrcServer::getSeventvEventAPI() +{ + return this->seventvEventAPI; +} + const IndirectChannel &TwitchIrcServer::getWatchingChannel() const { return this->watchingChannel; } +void TwitchIrcServer::setWatchingChannel(ChannelPtr newWatchingChannel) +{ + this->watchingChannel.reset(newWatchingChannel); +} + +ChannelPtr TwitchIrcServer::getWhispersChannel() const +{ + return this->whispersChannel; +} + +ChannelPtr TwitchIrcServer::getMentionsChannel() const +{ + return this->mentionsChannel; +} + +ChannelPtr TwitchIrcServer::getLiveChannel() const +{ + return this->liveChannel; +} + +ChannelPtr TwitchIrcServer::getAutomodChannel() const +{ + return this->automodChannel; +} + QString TwitchIrcServer::getLastUserThatWhisperedMe() const { return this->lastUserThatWhisperedMe.get(); } +void TwitchIrcServer::setLastUserThatWhisperedMe(const QString &user) +{ + this->lastUserThatWhisperedMe.set(user); +} + void TwitchIrcServer::reloadBTTVGlobalEmotes() { getIApp()->getBttvEmotes()->loadEmotes(); diff --git a/src/providers/twitch/TwitchIrcServer.hpp b/src/providers/twitch/TwitchIrcServer.hpp index 5fef49084..15e3af990 100644 --- a/src/providers/twitch/TwitchIrcServer.hpp +++ b/src/providers/twitch/TwitchIrcServer.hpp @@ -27,9 +27,27 @@ class ITwitchIrcServer public: virtual ~ITwitchIrcServer() = default; + virtual void forEachChannelAndSpecialChannels( + std::function func) = 0; + + virtual std::shared_ptr getChannelOrEmptyByID( + const QString &channelID) = 0; + + virtual void dropSeventvChannel(const QString &userID, + const QString &emoteSetID) = 0; + + virtual std::unique_ptr &getBTTVLiveUpdates() = 0; + virtual std::unique_ptr &getSeventvEventAPI() = 0; + virtual const IndirectChannel &getWatchingChannel() const = 0; + virtual void setWatchingChannel(ChannelPtr newWatchingChannel) = 0; + virtual ChannelPtr getWhispersChannel() const = 0; + virtual ChannelPtr getMentionsChannel() const = 0; + virtual ChannelPtr getLiveChannel() const = 0; + virtual ChannelPtr getAutomodChannel() const = 0; virtual QString getLastUserThatWhisperedMe() const = 0; + virtual void setLastUserThatWhisperedMe(const QString &user) = 0; // Update this interface with TwitchIrcServer methods as needed }; @@ -44,9 +62,11 @@ public: void initialize(Settings &settings, const Paths &paths) override; - void forEachChannelAndSpecialChannels(std::function func); + void forEachChannelAndSpecialChannels( + std::function func) override; - std::shared_ptr getChannelOrEmptyByID(const QString &channelID); + std::shared_ptr getChannelOrEmptyByID( + const QString &channelID) override; void reloadBTTVGlobalEmotes(); void reloadAllBTTVChannelEmotes(); @@ -68,8 +88,10 @@ public: * It's currently not possible to share emote sets among users, * but it's a commonly requested feature. */ - void dropSeventvChannel(const QString &userID, const QString &emoteSetID); + void dropSeventvChannel(const QString &userID, + const QString &emoteSetID) override; +private: Atomic lastUserThatWhisperedMe; const ChannelPtr whispersChannel; @@ -81,9 +103,19 @@ public: std::unique_ptr bttvLiveUpdates; std::unique_ptr seventvEventAPI; +public: + std::unique_ptr &getBTTVLiveUpdates() override; + std::unique_ptr &getSeventvEventAPI() override; + const IndirectChannel &getWatchingChannel() const override; + void setWatchingChannel(ChannelPtr newWatchingChannel) override; + ChannelPtr getWhispersChannel() const override; + ChannelPtr getMentionsChannel() const override; + ChannelPtr getLiveChannel() const override; + ChannelPtr getAutomodChannel() const override; QString getLastUserThatWhisperedMe() const override; + void setLastUserThatWhisperedMe(const QString &user) override; protected: void initializeConnection(IrcConnection *connection, diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index 6150cd8fa..524913ef8 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -236,14 +236,13 @@ void NativeMessagingServer::ReceiverThread::handleSelect( } postToThread([=] { - auto *app = getApp(); - if (!name.isEmpty()) { - auto channel = app->twitch->getOrAddChannel(name); - if (app->twitch->watchingChannel.get() != channel) + auto channel = + getIApp()->getTwitchAbstract()->getOrAddChannel(name); + if (getIApp()->getTwitch()->getWatchingChannel().get() != channel) { - app->twitch->watchingChannel.reset(channel); + getIApp()->getTwitch()->setWatchingChannel(channel); } } @@ -253,7 +252,8 @@ void NativeMessagingServer::ReceiverThread::handleSelect( auto *window = AttachedWindow::getForeground(args); if (!name.isEmpty()) { - window->setChannel(app->twitch->getOrAddChannel(name)); + window->setChannel( + getIApp()->getTwitchAbstract()->getOrAddChannel(name)); } #endif } @@ -294,8 +294,6 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels) { assertInGuiThread(); - auto *app = getApp(); - std::vector updated; updated.reserve(twitchChannels.size()); for (const auto &value : twitchChannels) @@ -306,7 +304,8 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels) continue; } // the deduping is done on the extension side - updated.emplace_back(app->twitch->getOrAddChannel(name)); + updated.emplace_back( + getIApp()->getTwitchAbstract()->getOrAddChannel(name)); } // This will destroy channels that aren't used anymore. diff --git a/src/singletons/StreamerMode.cpp b/src/singletons/StreamerMode.cpp index 4eda9e3bd..5b8b4402b 100644 --- a/src/singletons/StreamerMode.cpp +++ b/src/singletons/StreamerMode.cpp @@ -74,7 +74,7 @@ bool isBroadcasterSoftwareActive() shouldShowTimeoutWarning = false; postToThread([] { - getApp()->twitch->addGlobalSystemMessage( + getIApp()->getTwitchAbstract()->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()->twitch->addGlobalSystemMessage( + getIApp()->getTwitchAbstract()->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 695869288..1e0f78451 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -688,27 +688,28 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor) if (descriptor.type_ == "twitch") { - return app->twitch->getOrAddChannel(descriptor.channelName_); + return getIApp()->getTwitchAbstract()->getOrAddChannel( + descriptor.channelName_); } else if (descriptor.type_ == "mentions") { - return app->twitch->mentionsChannel; + return getIApp()->getTwitch()->getMentionsChannel(); } else if (descriptor.type_ == "watching") { - return app->twitch->watchingChannel; + return getIApp()->getTwitch()->getWatchingChannel(); } else if (descriptor.type_ == "whispers") { - return app->twitch->whispersChannel; + return getIApp()->getTwitch()->getWhispersChannel(); } else if (descriptor.type_ == "live") { - return app->twitch->liveChannel; + return getIApp()->getTwitch()->getLiveChannel(); } else if (descriptor.type_ == "automod") { - return app->twitch->automodChannel; + return getIApp()->getTwitch()->getAutomodChannel(); } else if (descriptor.type_ == "irc") { @@ -717,7 +718,8 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor) } else if (descriptor.type_ == "misc") { - return app->twitch->getChannelOrEmpty(descriptor.channelName_); + return getIApp()->getTwitchAbstract()->getChannelOrEmpty( + descriptor.channelName_); } return Channel::getEmpty(); diff --git a/src/widgets/FramelessEmbedWindow.cpp b/src/widgets/FramelessEmbedWindow.cpp index cf61c9bd4..9735edcee 100644 --- a/src/widgets/FramelessEmbedWindow.cpp +++ b/src/widgets/FramelessEmbedWindow.cpp @@ -54,7 +54,8 @@ bool FramelessEmbedWindow::nativeEvent(const QByteArray &eventType, auto channelName = root.value("channel-name").toString(); this->split_->setChannel( - getApp()->twitch->getOrAddChannel(channelName)); + getIApp()->getTwitchAbstract()->getOrAddChannel( + channelName)); } } } diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index a9b0995dd..a1a646c4b 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -254,7 +254,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleMiscMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->twitch->addFakeMessage(msg); + getIApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -262,7 +262,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleCheerMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->twitch->addFakeMessage(msg); + getIApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -270,7 +270,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleLinkMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->twitch->addFakeMessage(msg); + getIApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -286,7 +286,8 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) oMessage->toInner() ->toInner(); - app->twitch->addFakeMessage(getSampleChannelRewardIRCMessage()); + getIApp()->getTwitchAbstract()->addFakeMessage( + getSampleChannelRewardIRCMessage()); getIApp()->getTwitchPubSub()->pointReward.redeemed.invoke( oInnerMessage->data.value("redemption").toObject()); alt = !alt; @@ -309,7 +310,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleEmoteTestMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->twitch->addFakeMessage(msg); + getIApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); @@ -317,7 +318,7 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions) const auto &messages = getSampleSubMessages(); static int index = 0; const auto &msg = messages[index++ % messages.size()]; - getApp()->twitch->addFakeMessage(msg); + getIApp()->getTwitchAbstract()->addFakeMessage(msg); return ""; }); #endif @@ -480,8 +481,8 @@ void Window::addShortcuts() splitContainer = this->notebook_->getOrAddSelectedPage(); } Split *split = new Split(splitContainer); - split->setChannel( - getApp()->twitch->getOrAddChannel(si.channelName)); + split->setChannel(getIApp()->getTwitchAbstract()->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 febd38276..d482bb121 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -375,35 +375,33 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const return this->selectedChannel_; } - auto *app = getApp(); - switch (this->ui_.notebook->getSelectedIndex()) { case TAB_TWITCH: { if (this->ui_.twitch.channel->isChecked()) { - return app->twitch->getOrAddChannel( + return getIApp()->getTwitchAbstract()->getOrAddChannel( this->ui_.twitch.channelName->text().trimmed()); } else if (this->ui_.twitch.watching->isChecked()) { - return app->twitch->watchingChannel; + return getIApp()->getTwitch()->getWatchingChannel(); } else if (this->ui_.twitch.mentions->isChecked()) { - return app->twitch->mentionsChannel; + return getIApp()->getTwitch()->getMentionsChannel(); } else if (this->ui_.twitch.whispers->isChecked()) { - return app->twitch->whispersChannel; + return getIApp()->getTwitch()->getWhispersChannel(); } else if (this->ui_.twitch.live->isChecked()) { - return app->twitch->liveChannel; + return getIApp()->getTwitch()->getLiveChannel(); } else if (this->ui_.twitch.automod->isChecked()) { - return app->twitch->automodChannel; + return getIApp()->getTwitch()->getAutomodChannel(); } } break; diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index fff4fefc1..d519cdcfc 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -298,21 +298,23 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split) menu->addAction( "Open channel in a new popup window", this, [loginName] { - auto *app = getApp(); + auto *app = getIApp(); auto &window = app->getWindows()->createWindow( WindowType::Popup, true); auto *split = window.getNotebook() .getOrAddSelectedPage() ->appendNewSplit(false); - split->setChannel(app->twitch->getOrAddChannel( - loginName.toLower())); + split->setChannel( + app->getTwitchAbstract()->getOrAddChannel( + loginName.toLower())); }); menu->addAction( "Open channel in a new tab", this, [loginName] { ChannelPtr channel = - getApp()->twitch->getOrAddChannel( - loginName); + getIApp() + ->getTwitchAbstract() + ->getOrAddChannel(loginName); auto &nb = getApp() ->getWindows() ->getMainWindow() diff --git a/src/widgets/dialogs/switcher/NewPopupItem.cpp b/src/widgets/dialogs/switcher/NewPopupItem.cpp index ac4c45a9c..d4bc01bbd 100644 --- a/src/widgets/dialogs/switcher/NewPopupItem.cpp +++ b/src/widgets/dialogs/switcher/NewPopupItem.cpp @@ -21,7 +21,8 @@ NewPopupItem::NewPopupItem(const QString &channelName) void NewPopupItem::action() { - auto channel = getApp()->twitch->getOrAddChannel(this->channelName_); + auto channel = + getIApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_); getIApp()->getWindows()->openInPopup(channel); } diff --git a/src/widgets/dialogs/switcher/NewTabItem.cpp b/src/widgets/dialogs/switcher/NewTabItem.cpp index c264785b2..967c14aca 100644 --- a/src/widgets/dialogs/switcher/NewTabItem.cpp +++ b/src/widgets/dialogs/switcher/NewTabItem.cpp @@ -26,7 +26,8 @@ void NewTabItem::action() SplitContainer *container = nb.addPage(true); Split *split = new Split(container); - split->setChannel(getApp()->twitch->getOrAddChannel(this->channelName_)); + split->setChannel( + getIApp()->getTwitchAbstract()->getOrAddChannel(this->channelName_)); container->insertSplit(split); } diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index ed636cca4..00469e0a9 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1383,17 +1383,20 @@ MessageElementFlags ChannelView::getFlags() const { flags.set(MessageElementFlag::ModeratorTools); } - if (this->underlyingChannel_ == app->twitch->mentionsChannel || - this->underlyingChannel_ == app->twitch->liveChannel || - this->underlyingChannel_ == app->twitch->automodChannel) + if (this->underlyingChannel_ == + getIApp()->getTwitch()->getMentionsChannel() || + this->underlyingChannel_ == + getIApp()->getTwitch()->getLiveChannel() || + this->underlyingChannel_ == + getIApp()->getTwitch()->getAutomodChannel()) { flags.set(MessageElementFlag::ChannelName); flags.unset(MessageElementFlag::ChannelPointReward); } } - if (this->sourceChannel_ == app->twitch->mentionsChannel || - this->sourceChannel_ == app->twitch->automodChannel) + if (this->sourceChannel_ == getIApp()->getTwitch()->getMentionsChannel() || + this->sourceChannel_ == getIApp()->getTwitch()->getAutomodChannel()) { flags.set(MessageElementFlag::ChannelName); } @@ -1546,8 +1549,8 @@ void ChannelView::drawMessages(QPainter &painter, const QRect &area) .canvasWidth = this->width(), .isWindowFocused = this->window() == QApplication::activeWindow(), - .isMentions = - this->underlyingChannel_ == getApp()->twitch->mentionsChannel, + .isMentions = this->underlyingChannel_ == + getIApp()->getTwitch()->getMentionsChannel(), .y = int(-(messagesSnapshot[start]->getHeight() * (fmod(this->scrollBar_->getRelativeCurrentValue(), 1)))), @@ -2707,8 +2710,8 @@ void ChannelView::showUserInfoPopup(const QString &userName, auto *userPopup = new UserInfoPopup(getSettings()->autoCloseUserPopup, this->split_); - auto contextChannel = - getApp()->twitch->getChannelOrEmpty(alternativePopoutChannel); + auto contextChannel = getIApp()->getTwitchAbstract()->getChannelOrEmpty( + alternativePopoutChannel); auto openingChannel = this->hasSourceChannel() ? this->sourceChannel_ : this->underlyingChannel_; userPopup->setData(userName, contextChannel, openingChannel); diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index e21e9809e..9d27b5d08 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -570,7 +570,7 @@ void GeneralPage::initLayout(GeneralPageView &layout) // as an official description from 7TV devs is best s.showUnlistedSevenTVEmotes.connect( []() { - getApp()->twitch->forEachChannelAndSpecialChannels( + getIApp()->getTwitch()->forEachChannelAndSpecialChannels( [](const auto &c) { if (c->isTwitchChannel()) { diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 1e34aefbf..2be5bff57 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -272,7 +272,7 @@ Split::Split(QWidget *parent) std::ignore = this->view_->openChannelIn.connect( [this](QString twitchChannel, FromTwitchLinkOpenChannelIn openIn) { ChannelPtr channel = - getApp()->twitch->getOrAddChannel(twitchChannel); + getIApp()->getTwitchAbstract()->getOrAddChannel(twitchChannel); switch (openIn) { case FromTwitchLinkOpenChannelIn::Split: