From c1af2c3faa54b145869d5bbd71d77f397aa78d12 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 28 Aug 2022 12:20:47 +0200 Subject: [PATCH] feat: add settings to toggle BTTV/FFZ global/channel emotes (#3935) * feat: add settings to disable BTTV/FFZ global/channel emotes * docs: add changelog entry * fix: capitalize `BTTV` and `FFZ` * fix: rename and move settings --- CHANGELOG.md | 1 + src/Application.cpp | 13 +++++++++ src/messages/Emote.hpp | 3 +++ src/providers/bttv/BttvEmotes.cpp | 7 +++++ src/providers/ffz/FfzEmotes.cpp | 7 +++++ src/providers/twitch/TwitchChannel.cpp | 12 +++++++++ src/providers/twitch/TwitchIrcServer.cpp | 33 +++++++++++++++++++++-- src/providers/twitch/TwitchIrcServer.hpp | 5 ++++ src/singletons/Settings.hpp | 5 ++++ src/widgets/dialogs/EmotePopup.cpp | 28 +++++++++++++------ src/widgets/settingspages/GeneralPage.cpp | 4 +++ 11 files changed, 108 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58636f507..9ed9a7339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Minor: Add Quick Switcher item to open a channel in a new popup window. (#3828) - Minor: Warn when parsing an environment variable fails. (#3904) - Minor: Load missing messages from Recent Messages API upon reconnecting (#3878, #3932) +- Minor: Add settings to toggle BTTV/FFZ global/channel emotes (#3935) - Bugfix: Fix crash that can occur when closing and quickly reopening a split, then running a command. (#3852) - Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716) - Bugfix: Fix crash that can occur when changing channels. (#3799) diff --git a/src/Application.cpp b/src/Application.cpp index f3889a712..a8963384c 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -179,6 +179,19 @@ int Application::run(QApplication &qtApp) this->windows->forceLayoutChannelViews(); }); + getSettings()->enableBTTVGlobalEmotes.connect([this] { + this->twitch->reloadBTTVGlobalEmotes(); + }); + getSettings()->enableBTTVChannelEmotes.connect([this] { + this->twitch->reloadAllBTTVChannelEmotes(); + }); + getSettings()->enableFFZGlobalEmotes.connect([this] { + this->twitch->reloadFFZGlobalEmotes(); + }); + getSettings()->enableFFZChannelEmotes.connect([this] { + this->twitch->reloadAllFFZChannelEmotes(); + }); + return qtApp.exec(); } diff --git a/src/messages/Emote.hpp b/src/messages/Emote.hpp index 143d3ea64..d7c19d238 100644 --- a/src/messages/Emote.hpp +++ b/src/messages/Emote.hpp @@ -34,6 +34,9 @@ using EmoteIdMap = std::unordered_map; using WeakEmoteMap = std::unordered_map>; using WeakEmoteIdMap = std::unordered_map>; +static const std::shared_ptr EMPTY_EMOTE_MAP = std::make_shared< + const EmoteMap>(); // NOLINT(cert-err58-cpp) -- assume this doesn't throw an exception + EmotePtr cachedOrMakeEmotePtr(Emote &&emote, const EmoteMap &cache); EmotePtr cachedOrMakeEmotePtr( Emote &&emote, diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index 1ec58af62..6785ecede 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -11,6 +11,7 @@ #include "messages/ImageSet.hpp" #include "messages/MessageBuilder.hpp" #include "providers/twitch/TwitchChannel.hpp" +#include "singletons/Settings.hpp" namespace chatterino { namespace { @@ -141,6 +142,12 @@ boost::optional BttvEmotes::emote(const EmoteName &name) const void BttvEmotes::loadEmotes() { + if (!Settings::instance().enableBTTVGlobalEmotes) + { + this->global_.set(EMPTY_EMOTE_MAP); + return; + } + NetworkRequest(QString(globalEmoteApiUrl)) .timeout(30000) .onSuccess([this](auto result) -> Outcome { diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index 5608a481e..25cba7d15 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -9,6 +9,7 @@ #include "messages/Image.hpp" #include "messages/MessageBuilder.hpp" #include "providers/twitch/TwitchChannel.hpp" +#include "singletons/Settings.hpp" namespace chatterino { namespace { @@ -181,6 +182,12 @@ boost::optional FfzEmotes::emote(const EmoteName &name) const void FfzEmotes::loadEmotes() { + if (!Settings::instance().enableFFZGlobalEmotes) + { + this->global_.set(EMPTY_EMOTE_MAP); + return; + } + QString url("https://api.frankerfacez.com/v1/set/global"); NetworkRequest(url) diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 044a8d068..317a86978 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -197,6 +197,12 @@ void TwitchChannel::setLocalizedName(const QString &name) void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh) { + if (!Settings::instance().enableBTTVChannelEmotes) + { + this->bttvEmotes_.set(EMPTY_EMOTE_MAP); + return; + } + BttvEmotes::loadChannel( weakOf(this), this->roomId(), this->getLocalizedName(), [this, weak = weakOf(this)](auto &&emoteMap) { @@ -209,6 +215,12 @@ void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh) void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh) { + if (!Settings::instance().enableFFZChannelEmotes) + { + this->ffzEmotes_.set(EMPTY_EMOTE_MAP); + return; + } + FfzEmotes::loadChannel( weakOf(this), this->roomId(), [this, weak = weakOf(this)](auto &&emoteMap) { diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 4110142c7..b052134db 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -52,8 +52,8 @@ void TwitchIrcServer::initialize(Settings &settings, Paths &paths) }); }); - this->bttv.loadEmotes(); - this->ffz.loadEmotes(); + this->reloadBTTVGlobalEmotes(); + this->reloadFFZGlobalEmotes(); /* Refresh all twitch channel's live status in bulk every 30 seconds after starting chatterino */ QObject::connect(&this->bulkLiveStatusTimer_, &QTimer::timeout, [=] { @@ -468,4 +468,33 @@ const FfzEmotes &TwitchIrcServer::getFfzEmotes() const return this->ffz; } +void TwitchIrcServer::reloadBTTVGlobalEmotes() +{ + this->bttv.loadEmotes(); +} + +void TwitchIrcServer::reloadAllBTTVChannelEmotes() +{ + this->forEachChannel([](const auto &chan) { + if (auto *channel = dynamic_cast(chan.get())) + { + channel->refreshBTTVChannelEmotes(false); + } + }); +} + +void TwitchIrcServer::reloadFFZGlobalEmotes() +{ + this->ffz.loadEmotes(); +} + +void TwitchIrcServer::reloadAllFFZChannelEmotes() +{ + this->forEachChannel([](const auto &chan) { + if (auto *channel = dynamic_cast(chan.get())) + { + channel->refreshFFZChannelEmotes(false); + } + }); +} } // namespace chatterino diff --git a/src/providers/twitch/TwitchIrcServer.hpp b/src/providers/twitch/TwitchIrcServer.hpp index 323581c63..7aa4212a5 100644 --- a/src/providers/twitch/TwitchIrcServer.hpp +++ b/src/providers/twitch/TwitchIrcServer.hpp @@ -33,6 +33,11 @@ public: void bulkRefreshLiveStatus(); + void reloadBTTVGlobalEmotes(); + void reloadAllBTTVChannelEmotes(); + void reloadFFZGlobalEmotes(); + void reloadAllFFZChannelEmotes(); + Atomic lastUserThatWhisperedMe; const ChannelPtr whispersChannel; diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 38863c114..40b0ef638 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -201,6 +201,11 @@ public: BoolSetting removeSpacesBetweenEmotes = { "/emotes/removeSpacesBetweenEmotes", false}; + BoolSetting enableBTTVGlobalEmotes = {"/emotes/bttv/global", true}; + BoolSetting enableBTTVChannelEmotes = {"/emotes/bttv/channel", true}; + BoolSetting enableFFZGlobalEmotes = {"/emotes/ffz/global", true}; + BoolSetting enableFFZChannelEmotes = {"/emotes/ffz/channel", true}; + /// Links BoolSetting linksDoubleClickOnly = {"/links/doubleClickToOpen", false}; BoolSetting linkInfoTooltip = {"/links/linkInfoTooltip", false}; diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 43de38b1a..317607480 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -349,16 +349,28 @@ void EmotePopup::loadChannel(ChannelPtr channel) *globalChannel, *subChannel, this->channel_->getName()); // global - addEmotes(*globalChannel, *getApp()->twitch->getBttvEmotes().emotes(), - "BetterTTV", MessageElementFlag::BttvEmote); - addEmotes(*globalChannel, *getApp()->twitch->getFfzEmotes().emotes(), - "FrankerFaceZ", MessageElementFlag::FfzEmote); + if (Settings::instance().enableBTTVGlobalEmotes) + { + addEmotes(*globalChannel, *getApp()->twitch->getBttvEmotes().emotes(), + "BetterTTV", MessageElementFlag::BttvEmote); + } + if (Settings::instance().enableFFZGlobalEmotes) + { + addEmotes(*globalChannel, *getApp()->twitch->getFfzEmotes().emotes(), + "FrankerFaceZ", MessageElementFlag::FfzEmote); + } // channel - addEmotes(*channelChannel, *this->twitchChannel_->bttvEmotes(), "BetterTTV", - MessageElementFlag::BttvEmote); - addEmotes(*channelChannel, *this->twitchChannel_->ffzEmotes(), - "FrankerFaceZ", MessageElementFlag::FfzEmote); + if (Settings::instance().enableBTTVChannelEmotes) + { + addEmotes(*channelChannel, *this->twitchChannel_->bttvEmotes(), + "BetterTTV", MessageElementFlag::BttvEmote); + } + if (Settings::instance().enableFFZChannelEmotes) + { + addEmotes(*channelChannel, *this->twitchChannel_->ffzEmotes(), + "FrankerFaceZ", MessageElementFlag::FfzEmote); + } this->globalEmotesView_->setChannel(globalChannel); this->subEmotesView_->setChannel(subChannel); diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index a09b6bdb6..b3ed259ab 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -346,6 +346,10 @@ void GeneralPage::initLayout(GeneralPageView &layout) "Google", }, s.emojiSet); + layout.addCheckbox("Show BTTV global emotes", s.enableBTTVGlobalEmotes); + layout.addCheckbox("Show BTTV channel emotes", s.enableBTTVChannelEmotes); + layout.addCheckbox("Show FFZ global emotes", s.enableFFZGlobalEmotes); + layout.addCheckbox("Show FFZ channel emotes", s.enableFFZChannelEmotes); layout.addTitle("Streamer Mode"); layout.addDescription(