Show visual feedback when BTTV and FFZ emotes are loaded (#1671)

Upon joining a channel or pressing F5, BTTV and FFZ emotes are
(re)loaded. This change adds visual feedback of the network requests and
their outcome, in the form of a system message in the associated
channel's chat window. 

Non-error messages are suppressed when joining a
channel (which automatically loads emotes).
This commit is contained in:
thekalio
2020-05-16 06:43:44 -04:00
committed by GitHub
parent dd5455d1cf
commit 56d09ac198
8 changed files with 88 additions and 26 deletions
+24 -5
View File
@@ -6,6 +6,8 @@
#include "common/Outcome.hpp"
#include "messages/Emote.hpp"
#include "messages/Image.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/TwitchChannel.hpp"
namespace chatterino {
namespace {
@@ -182,8 +184,10 @@ void FfzEmotes::loadEmotes()
}
void FfzEmotes::loadChannel(
const QString &channelId, std::function<void(EmoteMap &&)> emoteCallback,
std::function<void(boost::optional<EmotePtr>)> modBadgeCallback)
std::weak_ptr<Channel> channel, const QString &channelId,
std::function<void(EmoteMap &&)> emoteCallback,
std::function<void(boost::optional<EmotePtr>)> modBadgeCallback,
bool manualRefresh)
{
qDebug() << "[FFZEmotes] Reload FFZ Channel Emotes for channel"
<< channelId;
@@ -192,32 +196,47 @@ void FfzEmotes::loadChannel(
.timeout(20000)
.onSuccess([emoteCallback = std::move(emoteCallback),
modBadgeCallback =
std::move(modBadgeCallback)](auto result) -> Outcome {
modBadgeCallback = std::move(modBadgeCallback), channel,
manualRefresh](auto result) -> Outcome {
auto json = result.parseJson();
auto emoteMap = parseChannelEmotes(json);
auto modBadge = parseModBadge(json);
emoteCallback(std::move(emoteMap));
modBadgeCallback(std::move(modBadge));
if (auto shared = channel.lock(); manualRefresh)
shared->addMessage(
makeSystemMessage("FrankerFaceZ channel emotes reloaded."));
return Success;
})
.onError([channelId](NetworkResult result) {
.onError([channelId, channel, manualRefresh](NetworkResult result) {
auto shared = channel.lock();
if (!shared)
return;
if (result.status() == 203)
{
// User does not have any FFZ emotes
if (manualRefresh)
shared->addMessage(makeSystemMessage(
"This channel has no FrankerFaceZ channel emotes."));
}
else if (result.status() == NetworkResult::timedoutStatus)
{
// TODO: Auto retry in case of a timeout, with a delay
qDebug() << "Fetching FFZ emotes for channel" << channelId
<< "failed due to timeout";
shared->addMessage(
makeSystemMessage("Failed to fetch FrankerFaceZ channel "
"emotes. (timed out)"));
}
else
{
qDebug() << "Error fetching FFZ emotes for channel" << channelId
<< ", error" << result.status();
shared->addMessage(
makeSystemMessage("Failed to fetch FrankerFaceZ channel "
"emotes. (unknown error)"));
}
})
.execute();