Split parseChannelResponse into two functions: parseModBadge and

parseChannelEmotes
This commit is contained in:
Rasmus Karlsson 2019-09-08 13:57:24 +02:00 committed by fourtf
parent 862164bc2b
commit 94048595f6

View file

@ -79,12 +79,11 @@ namespace {
return {Success, std::move(emotes)}; return {Success, std::move(emotes)};
} }
std::tuple<Outcome, EmoteMap, boost::optional<EmotePtr>>
parseChannelResponse(const QJsonObject &jsonRoot) boost::optional<EmotePtr> parseModBadge(const QJsonObject &jsonRoot)
{ {
boost::optional<EmotePtr> modBadge; boost::optional<EmotePtr> modBadge;
// Parse mod badge
auto room = jsonRoot.value("room").toObject(); auto room = jsonRoot.value("room").toObject();
auto modUrls = room.value("mod_urls").toObject(); auto modUrls = room.value("mod_urls").toObject();
if (!modUrls.isEmpty()) if (!modUrls.isEmpty())
@ -108,8 +107,11 @@ namespace {
modBadge1x, modBadge1x,
}); });
} }
return modBadge;
}
// Parse emotes EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot)
{
auto jsonSets = jsonRoot.value("sets").toObject(); auto jsonSets = jsonRoot.value("sets").toObject();
auto emotes = EmoteMap(); auto emotes = EmoteMap();
@ -139,7 +141,7 @@ namespace {
} }
} }
return {Success, std::move(emotes), modBadge}; return emotes;
} }
} // namespace } // namespace
@ -192,17 +194,14 @@ void FfzEmotes::loadChannel(
.onSuccess([emoteCallback = std::move(emoteCallback), .onSuccess([emoteCallback = std::move(emoteCallback),
modBadgeCallback = modBadgeCallback =
std::move(modBadgeCallback)](auto result) -> Outcome { std::move(modBadgeCallback)](auto result) -> Outcome {
auto [success, emoteMap, modBadge] = auto json = result.parseJson();
parseChannelResponse(result.parseJson()); auto emoteMap = parseChannelEmotes(json);
if (!success) auto modBadge = parseModBadge(json);
{
return success;
}
emoteCallback(std::move(emoteMap)); emoteCallback(std::move(emoteMap));
modBadgeCallback(std::move(modBadge)); modBadgeCallback(std::move(modBadge));
return success; return Success;
}) })
.onError([channelId](int result) { .onError([channelId](int result) {
if (result == 203) if (result == 203)