@@ -5,8 +5,18 @@
|
||||
#include <QJsonValue>
|
||||
#include <QThread>
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace chatterino {
|
||||
void ChatterinoBadges::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
this->loadChatterinoBadges();
|
||||
}
|
||||
|
||||
ChatterinoBadges::ChatterinoBadges()
|
||||
{
|
||||
@@ -14,41 +24,41 @@ ChatterinoBadges::ChatterinoBadges()
|
||||
|
||||
boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserName &username)
|
||||
{
|
||||
auto it = badgeMap.find(username.string);
|
||||
if (it != badgeMap.end()) {
|
||||
return emotes[it->second];
|
||||
}
|
||||
return boost::none;
|
||||
// return this->badges.access()->get(username);
|
||||
}
|
||||
|
||||
void ChatterinoBadges::loadChatterinoBadges()
|
||||
{
|
||||
// static QString url("https://fourtf.com/chatterino/badges.json");
|
||||
static QUrl url("https://fourtf.com/chatterino/badges.json");
|
||||
|
||||
// NetworkRequest req(url);
|
||||
// req.setCaller(QThread::currentThread());
|
||||
NetworkRequest req(url);
|
||||
req.setCaller(QThread::currentThread());
|
||||
|
||||
// req.onSuccess([this](auto result) {
|
||||
// auto jsonRoot = result.parseJson();
|
||||
// auto badges = this->badges.access();
|
||||
// auto replacement = badges->makeReplacment();
|
||||
req.onSuccess([this](auto result) -> Outcome {
|
||||
auto jsonRoot = result.parseJson();
|
||||
int index = 0;
|
||||
for (const auto &jsonBadge_ : jsonRoot.value("badges").toArray()) {
|
||||
auto jsonBadge = jsonBadge_.toObject();
|
||||
auto emote = Emote{
|
||||
EmoteName{}, ImageSet{Url{jsonBadge.value("image").toString()}},
|
||||
Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
|
||||
|
||||
// for (auto jsonBadge_ : jsonRoot.value("badges").toArray()) {
|
||||
// auto jsonBadge = jsonBadge_.toObject();
|
||||
emotes.push_back(std::make_shared<const Emote>(std::move(emote)));
|
||||
|
||||
// auto emote = Emote{
|
||||
// EmoteName{},
|
||||
// ImageSet{Url{jsonBadge.value("image").toString()}},
|
||||
// Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
|
||||
for (const auto &user : jsonBadge.value("users").toArray()) {
|
||||
badgeMap[user.toString()] = index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
||||
// for (auto jsonUser : jsonBadge.value("users").toArray()) {
|
||||
// replacement.add(UserName{jsonUser.toString()},
|
||||
// std::move(emote));
|
||||
// }
|
||||
// }
|
||||
return Success;
|
||||
});
|
||||
|
||||
// replacement.apply();
|
||||
// return Success;
|
||||
//});
|
||||
|
||||
// req.execute();
|
||||
req.execute();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user