diff --git a/src/controllers/moderationactions/ModerationActions.cpp b/src/controllers/moderationactions/ModerationActions.cpp index 68070f6b..27cd5de3 100644 --- a/src/controllers/moderationactions/ModerationActions.cpp +++ b/src/controllers/moderationactions/ModerationActions.cpp @@ -17,12 +17,16 @@ void ModerationActions::initialize(Settings &settings, Paths &paths) assert(!this->initialized_); this->initialized_ = true; - for (auto &val : this->setting_.getValue()) { + this->setting_ = + std::make_unique>>( + "/moderation/actions"); + + for (auto &val : this->setting_->getValue()) { this->items.insertItem(val); } this->items.delayedItemsChanged.connect([this] { // - this->setting_.setValue(this->items.getVector()); + this->setting_->setValue(this->items.getVector()); }); } diff --git a/src/controllers/moderationactions/ModerationActions.hpp b/src/controllers/moderationactions/ModerationActions.hpp index d5e510f1..08314eb2 100644 --- a/src/controllers/moderationactions/ModerationActions.hpp +++ b/src/controllers/moderationactions/ModerationActions.hpp @@ -25,8 +25,7 @@ public: ModerationActionModel *createModel(QObject *parent); private: - ChatterinoSetting> setting_ = { - "/moderation/actions"}; + std::unique_ptr>> setting_; bool initialized_ = false; }; diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index 70c7cdbd..cf32bd41 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -3,6 +3,7 @@ #include "common/Common.hpp" #include "common/NetworkRequest.hpp" #include "debug/Log.hpp" +#include "messages/Emote.hpp" #include "messages/Image.hpp" #include "messages/ImageSet.hpp" #include "providers/twitch/TwitchChannel.hpp" @@ -89,12 +90,12 @@ BttvEmotes::BttvEmotes() { } -std::shared_ptr BttvEmotes::global() const +std::shared_ptr BttvEmotes::emotes() const { return this->global_.get(); } -boost::optional BttvEmotes::global(const EmoteName &name) const +boost::optional BttvEmotes::emote(const EmoteName &name) const { auto emotes = this->global_.get(); auto it = emotes->find(name); @@ -103,7 +104,7 @@ boost::optional BttvEmotes::global(const EmoteName &name) const return it->second; } -void BttvEmotes::loadGlobal() +void BttvEmotes::loadEmotes() { auto request = NetworkRequest(QString(globalEmoteApiUrl)); diff --git a/src/providers/bttv/BttvEmotes.hpp b/src/providers/bttv/BttvEmotes.hpp index ff480941..c82cb67a 100644 --- a/src/providers/bttv/BttvEmotes.hpp +++ b/src/providers/bttv/BttvEmotes.hpp @@ -1,13 +1,16 @@ #pragma once -#include #include - +#include "boost/optional.hpp" +#include "common/Aliases.hpp" #include "common/Atomic.hpp" -#include "messages/Emote.hpp" namespace chatterino { +struct Emote; +using EmotePtr = std::shared_ptr; +class EmoteMap; + class BttvEmotes final { static constexpr const char *globalEmoteApiUrl = @@ -18,9 +21,9 @@ class BttvEmotes final public: BttvEmotes(); - std::shared_ptr global() const; - boost::optional global(const EmoteName &name) const; - void loadGlobal(); + std::shared_ptr emotes() const; + boost::optional emote(const EmoteName &name) const; + void loadEmotes(); static void loadChannel(const QString &channelName, std::function callback); diff --git a/src/providers/emoji/Emojis.cpp b/src/providers/emoji/Emojis.cpp index d0403e75..18ce1813 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -104,12 +104,10 @@ void Emojis::load() void Emojis::loadEmojis() { - std::map toneNames; - toneNames["1F3FB"] = "tone1"; - toneNames["1F3FC"] = "tone2"; - toneNames["1F3FD"] = "tone3"; - toneNames["1F3FE"] = "tone4"; - toneNames["1F3FF"] = "tone5"; + auto toneNames = std::map{ + {"1F3FB", "tone1"}, {"1F3FC", "tone2"}, {"1F3FD", "tone3"}, + {"1F3FE", "tone4"}, {"1F3FF", "tone5"}, + }; QFile file(":/emoji.json"); file.open(QFile::ReadOnly); @@ -234,27 +232,12 @@ void Emojis::loadEmojiSet() // {"Google", "https://cdn.jsdelivr.net/npm/emoji-datasource-google@4.0.4/img/google/64/"}, // {"Messenger", "https://cdn.jsdelivr.net/npm/emoji-datasource-messenger@4.0.4/img/messenger/64/"}, - // {"EmojiOne 2", "https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.6/assets/png/"}, - // {"EmojiOne 3", "https://braize.pajlada.com/emoji/img/emojione/64/"}, - // {"Twitter", "https://braize.pajlada.com/emoji/img/twitter/64/"}, - // {"Facebook", "https://braize.pajlada.com/emoji/img/facebook/64/"}, - // {"Apple", "https://braize.pajlada.com/emoji/img/apple/64/"}, - // {"Google", "https://braize.pajlada.com/emoji/img/google/64/"}, - // {"Messenger", "https://braize.pajlada.com/emoji/img/messenger/64/"}, - {"EmojiOne 3", "https://pajbot.com/static/emoji/img/emojione/64/"}, {"Twitter", "https://pajbot.com/static/emoji/img/twitter/64/"}, {"Facebook", "https://pajbot.com/static/emoji/img/facebook/64/"}, {"Apple", "https://pajbot.com/static/emoji/img/apple/64/"}, {"Google", "https://pajbot.com/static/emoji/img/google/64/"}, {"Messenger", "https://pajbot.com/static/emoji/img/messenger/64/"}, - -// {"EmojiOne 3", "https://cdn.fourtf.com/emoji/emojione/64/"}, -// {"Twitter", "https://cdn.fourtf.com/emoji/twitter/64/"}, -// {"Facebook", "https://cdn.fourtf.com/emoji/facebook/64/"}, -// {"Apple", "https://cdn.fourtf.com/emoji/apple/64/"}, -// {"Google", "https://cdn.fourtf.com/emoji/google/64/"}, -// {"Messenger", "https://cdn.fourtf.com/emoji/messenger/64/"}, }; // clang-format on diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index c22fe91f..f8be4baa 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -5,6 +5,7 @@ #include "common/NetworkRequest.hpp" #include "common/Outcome.hpp" #include "debug/Log.hpp" +#include "messages/Emote.hpp" #include "messages/Image.hpp" namespace chatterino { @@ -109,12 +110,12 @@ FfzEmotes::FfzEmotes() { } -std::shared_ptr FfzEmotes::global() const +std::shared_ptr FfzEmotes::emotes() const { return this->global_.get(); } -boost::optional FfzEmotes::global(const EmoteName &name) const +boost::optional FfzEmotes::emote(const EmoteName &name) const { auto emotes = this->global_.get(); auto it = emotes->find(name); @@ -122,7 +123,7 @@ boost::optional FfzEmotes::global(const EmoteName &name) const return boost::none; } -void FfzEmotes::loadGlobal() +void FfzEmotes::loadEmotes() { QString url("https://api.frankerfacez.com/v1/set/global"); @@ -131,7 +132,7 @@ void FfzEmotes::loadGlobal() request.setTimeout(30000); request.onSuccess([this](auto result) -> Outcome { - auto emotes = this->global(); + auto emotes = this->emotes(); auto pair = parseGlobalEmotes(result.parseJson(), *emotes); if (pair.first) this->global_.set( diff --git a/src/providers/ffz/FfzEmotes.hpp b/src/providers/ffz/FfzEmotes.hpp index cc75b09b..8214cbf8 100644 --- a/src/providers/ffz/FfzEmotes.hpp +++ b/src/providers/ffz/FfzEmotes.hpp @@ -1,24 +1,27 @@ #pragma once #include +#include "boost/optional.hpp" +#include "common/Aliases.hpp" #include "common/Atomic.hpp" -#include "messages/Emote.hpp" namespace chatterino { +struct Emote; +using EmotePtr = std::shared_ptr; +class EmoteMap; + class FfzEmotes final { static constexpr const char *globalEmoteApiUrl = "https://api.frankerfacez.com/v1/set/global"; - static constexpr const char *channelEmoteApiUrl = - "https://api.betterttv.net/2/channels/"; public: FfzEmotes(); - std::shared_ptr global() const; - boost::optional global(const EmoteName &name) const; - void loadGlobal(); + std::shared_ptr emotes() const; + boost::optional emote(const EmoteName &name) const; + void loadEmotes(); static void loadChannel(const QString &channelName, std::function callback); diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 0bb7ffe9..6413629f 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -51,13 +51,16 @@ auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel) } } // namespace -TwitchChannel::TwitchChannel(const QString &name) +TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv, + FfzEmotes &ffz) : Channel(name, Channel::Type::Twitch) - , bttvEmotes_(std::make_shared()) - , ffzEmotes_(std::make_shared()) , subscriptionUrl_("https://www.twitch.tv/subs/" + name) , channelUrl_("https://twitch.tv/" + name) , popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name) + , globalBttv_(bttv) + , globalFfz_(ffz) + , bttvEmotes_(std::make_shared()) + , ffzEmotes_(std::make_shared()) , mod_(false) { log("[TwitchChannel:{}] Opened", name); @@ -290,6 +293,16 @@ TwitchChannel::accessStreamStatus() const return this->streamStatus_.accessConst(); } +const BttvEmotes &TwitchChannel::globalBttv() const +{ + return this->globalBttv_; +} + +const FfzEmotes &TwitchChannel::globalFfz() const +{ + return this->globalFfz_; +} + boost::optional TwitchChannel::bttvEmote(const EmoteName &name) const { auto emotes = this->bttvEmotes_.get(); diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index 940da72b..a444d26e 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -19,6 +19,9 @@ struct Emote; using EmotePtr = std::shared_ptr; class EmoteMap; +class FfzEmotes; +class BttvEmotes; + class TwitchServer; class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder @@ -60,25 +63,28 @@ public: void addJoinedUser(const QString &user); void addPartedUser(const QString &user); - // Twitch data bool isLive() const; virtual bool isMod() const override; void setMod(bool value); virtual bool isBroadcaster() const override; + // Data + const QString &subscriptionUrl(); + const QString &channelUrl(); + const QString &popoutPlayerUrl(); QString roomId() const; void setRoomId(const QString &id); AccessGuard accessRoomModes() const; void setRoomModes(const RoomModes &roomModes_); AccessGuard accessStreamStatus() const; + // Emotes + const BttvEmotes &globalBttv() const; + const FfzEmotes &globalFfz() const; boost::optional bttvEmote(const EmoteName &name) const; boost::optional ffzEmote(const EmoteName &name) const; std::shared_ptr bttvEmotes() const; std::shared_ptr ffzEmotes() const; - const QString &subscriptionUrl(); - const QString &channelUrl(); - const QString &popoutPlayerUrl(); boost::optional getTwitchBadge(const QString &set, const QString &version) const; @@ -109,7 +115,8 @@ private: std::vector cheerEmotes; }; - explicit TwitchChannel(const QString &channelName); + explicit TwitchChannel(const QString &channelName, BttvEmotes &bttv, + FfzEmotes &ffz); // Methods void refreshLiveStatus(); @@ -124,16 +131,19 @@ private: void loadBadges(); void loadCheerEmotes(); - // Twitch data + // Data + const QString subscriptionUrl_; + const QString channelUrl_; + const QString popoutPlayerUrl_; UniqueAccess streamStatus_; UniqueAccess userState_; UniqueAccess roomModes_; + // Emotes + BttvEmotes &globalBttv_; + FfzEmotes &globalFfz_; Atomic> bttvEmotes_; Atomic> ffzEmotes_; - const QString subscriptionUrl_; - const QString channelUrl_; - const QString popoutPlayerUrl_; bool mod_ = false; UniqueAccess roomID_; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 67cd2998..5b4cef19 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -640,12 +640,11 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) auto flags = MessageElementFlags(); auto emote = boost::optional{}; - if ((emote = getApp()->emotes->bttv.global(name))) { + if ((emote = this->twitchChannel->globalBttv().emote(name))) { flags = MessageElementFlag::BttvEmote; - } else if (twitchChannel && - (emote = this->twitchChannel->bttvEmote(name))) { + } else if ((emote = this->twitchChannel->bttvEmote(name))) { flags = MessageElementFlag::BttvEmote; - } else if ((emote = getApp()->emotes->ffz.global(name))) { + } else if ((emote = this->twitchChannel->globalFfz().emote(name))) { flags = MessageElementFlag::FfzEmote; } else if (twitchChannel && (emote = this->twitchChannel->ffzEmote(name))) { flags = MessageElementFlag::FfzEmote; diff --git a/src/providers/twitch/TwitchServer.cpp b/src/providers/twitch/TwitchServer.cpp index e9325443..bb7b16fd 100644 --- a/src/providers/twitch/TwitchServer.cpp +++ b/src/providers/twitch/TwitchServer.cpp @@ -40,6 +40,9 @@ void TwitchServer::initialize(Settings &settings, Paths &paths) { getApp()->accounts->twitch.currentUserChanged.connect( [this]() { postToThread([this] { this->connect(); }); }); + + this->bttv.loadEmotes(); + this->ffz.loadEmotes(); } void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, @@ -80,8 +83,8 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, std::shared_ptr TwitchServer::createChannel(const QString &channelName) { - auto channel = - std::shared_ptr(new TwitchChannel(channelName)); + auto channel = std::shared_ptr( + new TwitchChannel(channelName, this->bttv, this->ffz)); channel->refreshChannelEmotes(); channel->sendMessageSignal.connect( diff --git a/src/providers/twitch/TwitchServer.hpp b/src/providers/twitch/TwitchServer.hpp index 72c4078b..127c2f62 100644 --- a/src/providers/twitch/TwitchServer.hpp +++ b/src/providers/twitch/TwitchServer.hpp @@ -4,6 +4,8 @@ #include "common/Channel.hpp" #include "common/Singleton.hpp" #include "pajlada/signals/signalholder.hpp" +#include "providers/bttv/BttvEmotes.hpp" +#include "providers/ffz/FfzEmotes.hpp" #include "providers/irc/AbstractIrcServer.hpp" #include @@ -66,6 +68,8 @@ private: std::chrono::steady_clock::time_point lastErrorTimeAmount_; bool singleConnection_ = false; + BttvEmotes bttv; + FfzEmotes ffz; pajlada::Signals::SignalHolder signalHolder_; }; diff --git a/src/singletons/Emotes.cpp b/src/singletons/Emotes.cpp index cfc23f6d..9916d204 100644 --- a/src/singletons/Emotes.cpp +++ b/src/singletons/Emotes.cpp @@ -15,8 +15,6 @@ void Emotes::initialize(Settings &settings, Paths &paths) [] { getApp()->accounts->twitch.getCurrent()->loadEmotes(); }); this->emojis.load(); - this->bttv.loadGlobal(); - this->ffz.loadGlobal(); this->gifTimer.initialize(); } diff --git a/src/singletons/Emotes.hpp b/src/singletons/Emotes.hpp index e991fe67..fc475d75 100644 --- a/src/singletons/Emotes.hpp +++ b/src/singletons/Emotes.hpp @@ -25,8 +25,6 @@ public: bool isIgnoredEmote(const QString &emote); TwitchEmotes twitch; - BttvEmotes bttv; - FfzEmotes ffz; Emojis emojis; GIFTimer gifTimer; diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 92435065..ade2a88a 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -125,8 +125,10 @@ void EmotePopup::loadChannel(ChannelPtr _channel) *globalChannel, *subChannel); // global - addEmotes(*globalChannel, *getApp()->emotes->bttv.global(), "BetterTTV"); - addEmotes(*globalChannel, *getApp()->emotes->ffz.global(), "FrankerFaceZ"); + addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(), + "BetterTTV"); + addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(), + "FrankerFaceZ"); // channel addEmotes(*channelChannel, *twitchChannel->bttvEmotes(), "BetterTTV");