From 6ef515a0e29bf804c5c3620eee6eabe1596eb307 Mon Sep 17 00:00:00 2001 From: Auro <35087590+MrAuro@users.noreply.github.com> Date: Sun, 21 Mar 2021 09:27:28 -0400 Subject: [PATCH] Added system message if no bttv emotes found instead of "unknown error" (#2542) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paweł Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/providers/bttv/BttvEmotes.cpp | 27 ++++++++++++++++++++++----- src/providers/ffz/FfzEmotes.cpp | 26 +++++++++++++++++++++----- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e64b4b2d9..94cf8615b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ - Bugfix: Fixed hidden tooltips when always on top is active (#2384) - Bugfix: Fix CLI arguments (`--help`, `--version`, `--channels`) not being respected (#2368, #2190) - Bugfix: Fix Twitch cheer emotes not displaying tooltips when hovered (#2434, #2503) +- Bugfix: Fix BTTV/FFZ channel emotes saying unknown error when no emotes found (#2542) - Bugfix: Fix directory not opening when clicking "Open AppData Directory" setting button on macOS (#2531, #2537) - Dev: Updated minimum required Qt framework version to 5.12. (#2210) - Dev: Migrated `Kraken::getUser` to Helix (#2260) diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index bea6221ae..b3e89b544 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -15,6 +15,9 @@ namespace chatterino { namespace { + const QString CHANNEL_HAS_NO_EMOTES( + "This channel has no BetterTTV channel emotes."); + QString emoteLinkFormat("https://betterttv.com/emotes/%1"); Url getEmoteLink(QString urlTemplate, const EmoteId &id, @@ -164,23 +167,37 @@ void BttvEmotes::loadChannel(std::weak_ptr channel, manualRefresh](auto result) -> Outcome { auto pair = parseChannelEmotes(result.parseJson(), channelDisplayName); + bool hasEmotes = false; if (pair.first) + { + hasEmotes = !pair.second.empty(); callback(std::move(pair.second)); + } if (auto shared = channel.lock(); manualRefresh) - shared->addMessage( - makeSystemMessage("BetterTTV channel emotes reloaded.")); + { + if (hasEmotes) + { + shared->addMessage(makeSystemMessage( + "BetterTTV channel emotes reloaded.")); + } + else + { + shared->addMessage( + makeSystemMessage(CHANNEL_HAS_NO_EMOTES)); + } + } return pair.first; }) .onError([channelId, channel, manualRefresh](auto result) { auto shared = channel.lock(); if (!shared) return; - if (result.status() == 203) + if (result.status() == 404) { // User does not have any BTTV emotes if (manualRefresh) - shared->addMessage(makeSystemMessage( - "This channel has no BetterTTV channel emotes.")); + shared->addMessage( + makeSystemMessage(CHANNEL_HAS_NO_EMOTES)); } else if (result.status() == NetworkResult::timedoutStatus) { diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index aa376f2c2..f032ab44f 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -12,6 +12,10 @@ namespace chatterino { namespace { + + const QString CHANNEL_HAS_NO_EMOTES( + "This channel has no FrankerFaceZ channel emotes."); + Url getEmoteLink(const QJsonObject &urls, const QString &emoteScale) { auto emote = urls.value(emoteScale); @@ -210,11 +214,23 @@ void FfzEmotes::loadChannel( auto emoteMap = parseChannelEmotes(json); auto modBadge = parseModBadge(json); + bool hasEmotes = !emoteMap.empty(); + emoteCallback(std::move(emoteMap)); modBadgeCallback(std::move(modBadge)); if (auto shared = channel.lock(); manualRefresh) - shared->addMessage( - makeSystemMessage("FrankerFaceZ channel emotes reloaded.")); + { + if (hasEmotes) + { + shared->addMessage(makeSystemMessage( + "FrankerFaceZ channel emotes reloaded.")); + } + else + { + shared->addMessage( + makeSystemMessage(CHANNEL_HAS_NO_EMOTES)); + } + } return Success; }) @@ -222,12 +238,12 @@ void FfzEmotes::loadChannel( auto shared = channel.lock(); if (!shared) return; - if (result.status() == 203) + if (result.status() == 404) { // User does not have any FFZ emotes if (manualRefresh) - shared->addMessage(makeSystemMessage( - "This channel has no FrankerFaceZ channel emotes.")); + shared->addMessage( + makeSystemMessage(CHANNEL_HAS_NO_EMOTES)); } else if (result.status() == NetworkResult::timedoutStatus) {