From c176d836af079b3b0c72d5b6449dd3fc1bea7fd5 Mon Sep 17 00:00:00 2001 From: hemirt Date: Thu, 25 Oct 2018 21:51:55 +0200 Subject: [PATCH] render bttv/ffz global emotes in incoming whispers, bttv/ffz/twitch (#824) emotes in outgoing whispers --- .../commands/CommandController.cpp | 38 ++++++++++++++++--- src/providers/twitch/TwitchMessageBuilder.cpp | 20 +++++++++- src/providers/twitch/TwitchServer.cpp | 9 +++++ src/providers/twitch/TwitchServer.hpp | 3 ++ 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 3c13d5c94..754640952 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -148,14 +148,40 @@ QString CommandController::execCommand(const QString &text, ChannelPtr channel, MessageColor::Text, FontStyle::ChatMediumBold); - QString rest = ""; - - for (int i = 2; i < words.length(); i++) - { - rest += words[i] + " "; + const auto &acc = app->accounts->twitch.getCurrent(); + const auto &accemotes = *acc->accessEmotes(); + const auto &bttvemotes = app->twitch.server->getBttvEmotes(); + const auto &ffzemotes = app->twitch.server->getFfzEmotes(); + auto flags = MessageElementFlags(); + auto emote = boost::optional{}; + for (int i = 2; i < words.length(); i++) { + { // twitch emote + auto it = accemotes.emotes.find({words[i]}); + if (it != accemotes.emotes.end()) { + b.emplace( + it->second, MessageElementFlag::TwitchEmote); + continue; + } + } // twitch emote + { // bttv/ffz emote + { + if ((emote = bttvemotes.emote({words[i]}))) { + flags = MessageElementFlag::BttvEmote; + } else if ((emote = ffzemotes.emote({words[i]}))) { + flags = MessageElementFlag::FfzEmote; + } + if (emote) { + b.emplace(emote.get(), flags); + continue; + } + } // bttv/ffz emote + { // text + b.emplace(words[i], + MessageElementFlag::Text); + } // text + } } - b.emplace(rest, MessageElementFlag::Text); b->flags.set(MessageFlag::DoNotTriggerNotification); auto messagexD = b.release(); diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 159e94b4a..1f17728ca 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -10,6 +10,7 @@ #include "providers/chatterino/ChatterinoBadges.hpp" #include "providers/twitch/TwitchBadges.hpp" #include "providers/twitch/TwitchChannel.hpp" +#include "providers/twitch/TwitchServer.hpp" #include "singletons/Emotes.hpp" #include "singletons/Resources.hpp" #include "singletons/Settings.hpp" @@ -986,8 +987,23 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) { // Special channels, like /whispers and /channels return here // This means they will not render any BTTV or FFZ emotes - if (this->twitchChannel == nullptr) - { + if (this->twitchChannel == nullptr) { + auto *app = getApp(); + const auto &bttvemotes = app->twitch.server->getBttvEmotes(); + const auto &ffzemotes = app->twitch.server->getFfzEmotes(); + auto flags = MessageElementFlags(); + auto emote = boost::optional{}; + { // bttv/ffz emote + if ((emote = bttvemotes.emote(name))) { + flags = MessageElementFlag::BttvEmote; + } else if ((emote = ffzemotes.emote(name))) { + flags = MessageElementFlag::FfzEmote; + } + if (emote) { + this->emplace(emote.get(), flags); + return Success; + } + } // bttv/ffz emote return Failure; } diff --git a/src/providers/twitch/TwitchServer.cpp b/src/providers/twitch/TwitchServer.cpp index c8b3427e2..d9544fff3 100644 --- a/src/providers/twitch/TwitchServer.cpp +++ b/src/providers/twitch/TwitchServer.cpp @@ -288,4 +288,13 @@ void TwitchServer::onMessageSendRequested(TwitchChannel *channel, sent = true; } +const BttvEmotes &TwitchServer::getBttvEmotes() const +{ + return this->bttv; +} +const FfzEmotes &TwitchServer::getFfzEmotes() const +{ + return this->ffz; +} + } // namespace chatterino diff --git a/src/providers/twitch/TwitchServer.hpp b/src/providers/twitch/TwitchServer.hpp index 60026a142..da67196b1 100644 --- a/src/providers/twitch/TwitchServer.hpp +++ b/src/providers/twitch/TwitchServer.hpp @@ -40,6 +40,9 @@ public: PubSub *pubsub; + const BttvEmotes &getBttvEmotes() const; + const FfzEmotes &getFfzEmotes() const; + protected: virtual void initializeConnection(IrcConnection *connection, bool isRead, bool isWrite) override;