From 155b40985bcded283efb898f373eaaeeb7fec09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Sat, 12 Dec 2020 16:15:49 +0100 Subject: [PATCH] Made emote tooltips use author's displayName consistently (#2267) --- CHANGELOG.md | 1 + src/providers/bttv/BttvEmotes.cpp | 32 +++++++++++++++----------- src/providers/bttv/BttvEmotes.hpp | 3 ++- src/providers/ffz/FfzEmotes.cpp | 7 +++--- src/providers/twitch/TwitchChannel.cpp | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7056da7d..8ba9e5c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Major: Added "Channel Filters". See https://wiki.chatterino.com/Filters/ for how they work or how to configure them. (#1748, #2083, #2090, #2200) - Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001) +- Minor: Made BetterTTV emote tooltips use authors' display name. (#2267) - Minor: Added Ctrl + 1/2/3/... and Ctrl+9 shortcuts to Emote Popup (activated with Ctrl+E). They work exactly the same as shortcuts in main window. (#2263) - Minor: Added reconnect link to the "You are banned" message. (#2266) - Minor: Improved search popup window titles. (#2268) diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index e3943a4b1..bea6221ae 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -56,7 +56,7 @@ namespace { ImageSet{Image::fromUrl(getEmoteLinkV3(id, "1x"), 1), Image::fromUrl(getEmoteLinkV3(id, "2x"), 0.5), Image::fromUrl(getEmoteLinkV3(id, "3x"), 0.25)}, - Tooltip{name.string + "
Global BetterTTV Emote"}, + Tooltip{name.string + "
Global BetterTTV Emote"}, Url{emoteLinkFormat.arg(id.string)}, }); @@ -66,12 +66,13 @@ namespace { return {Success, std::move(emotes)}; } - std::pair parseChannelEmotes(const QJsonObject &jsonRoot, - const QString &userName) + std::pair parseChannelEmotes( + const QJsonObject &jsonRoot, const QString &channelDisplayName) { auto emotes = EmoteMap(); - auto innerParse = [&jsonRoot, &emotes, &userName](const char *key) { + auto innerParse = [&jsonRoot, &emotes, + &channelDisplayName](const char *key) { auto jsonEmotes = jsonRoot.value(key).toArray(); for (auto jsonEmote_ : jsonEmotes) { @@ -81,9 +82,8 @@ namespace { auto name = EmoteName{jsonEmote.value("code").toString()}; auto author = EmoteAuthor{jsonEmote.value("user") .toObject() - .value("name") + .value("displayName") .toString()}; - // emoteObject.value("imageType").toString(); auto emote = Emote({ name, @@ -92,10 +92,13 @@ namespace { Image::fromUrl(getEmoteLinkV3(id, "2x"), 0.5), Image::fromUrl(getEmoteLinkV3(id, "3x"), 0.25), }, - Tooltip{name.string + "
Channel BetterTTV Emote" + - ((author.string.isEmpty()) - ? "
By: " + userName.toUtf8() - : "
By: " + author.string)}, + Tooltip{ + QString("%1
%2 BetterTTV Emote
By: %3") + .arg(name.string) + // when author is empty, it is a channel emote created by the broadcaster + .arg(author.string.isEmpty() ? "Channel" : "Shared") + .arg(author.string.isEmpty() ? channelDisplayName + : author.string)}, Url{emoteLinkFormat.arg(id.string)}, }); @@ -149,15 +152,18 @@ void BttvEmotes::loadEmotes() } void BttvEmotes::loadChannel(std::weak_ptr channel, - const QString &channelId, const QString &userName, + const QString &channelId, + const QString &channelDisplayName, std::function callback, bool manualRefresh) { NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelId) .timeout(3000) - .onSuccess([callback = std::move(callback), channel, &userName, + .onSuccess([callback = std::move(callback), channel, + &channelDisplayName, manualRefresh](auto result) -> Outcome { - auto pair = parseChannelEmotes(result.parseJson(), userName); + auto pair = + parseChannelEmotes(result.parseJson(), channelDisplayName); if (pair.first) callback(std::move(pair.second)); if (auto shared = channel.lock(); manualRefresh) diff --git a/src/providers/bttv/BttvEmotes.hpp b/src/providers/bttv/BttvEmotes.hpp index 72b21aef4..81a86bca5 100644 --- a/src/providers/bttv/BttvEmotes.hpp +++ b/src/providers/bttv/BttvEmotes.hpp @@ -26,7 +26,8 @@ public: boost::optional emote(const EmoteName &name) const; void loadEmotes(); static void loadChannel(std::weak_ptr channel, - const QString &channelId, const QString &userName, + const QString &channelId, + const QString &channelDisplayName, std::function callback, bool manualRefresh); diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index 7812d86f4..aa376f2c2 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -68,7 +68,7 @@ namespace { auto emote = Emote(); fillInEmoteData(urls, name, - name.string + "
Global FFZ Emote", emote); + name.string + "
Global FFZ Emote", emote); emote.homePage = Url{QString("https://www.frankerfacez.com/emoticon/%1-%2") .arg(id.string) @@ -137,8 +137,9 @@ namespace { Emote emote; fillInEmoteData(urls, name, - name.string + "
Channel FFZ Emote" + - "
By: " + author.string, + QString("%1
Channel FFZ Emote
By: %2") + .arg(name.string) + .arg(author.string), emote); emote.homePage = Url{QString("https://www.frankerfacez.com/emoticon/%1-%2") diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 7bd0169fb..5b3029690 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -241,7 +241,7 @@ void TwitchChannel::setLocalizedName(const QString &name) void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh) { BttvEmotes::loadChannel( - weakOf(this), this->roomId(), this->getName(), + weakOf(this), this->roomId(), this->getLocalizedName(), [this, weak = weakOf(this)](auto &&emoteMap) { if (auto shared = weak.lock()) this->bttvEmotes_.set(