fixed chatterino badges (#698)

* fixed chatterino badges
This commit is contained in:
apa420 2018-09-16 17:27:51 +02:00 committed by pajlada
parent e332564e01
commit 56aac47fde
5 changed files with 53 additions and 41 deletions

View file

@ -9,6 +9,7 @@
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
#include "providers/bttv/BttvEmotes.hpp" #include "providers/bttv/BttvEmotes.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/ffz/FfzEmotes.hpp" #include "providers/ffz/FfzEmotes.hpp"
#include "providers/twitch/PubsubClient.hpp" #include "providers/twitch/PubsubClient.hpp"
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
@ -52,6 +53,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, taggedUsers(&this->emplace<TaggedUsersController>()) , taggedUsers(&this->emplace<TaggedUsersController>())
, moderationActions(&this->emplace<ModerationActions>()) , moderationActions(&this->emplace<ModerationActions>())
, twitch2(&this->emplace<TwitchServer>()) , twitch2(&this->emplace<TwitchServer>())
, chatterinoBadges(&this->emplace<ChatterinoBadges>())
, logging(&this->emplace<Logging>()) , logging(&this->emplace<Logging>())
{ {
this->instance = this; this->instance = this;

View file

@ -26,6 +26,7 @@ class Emotes;
class Settings; class Settings;
class Fonts; class Fonts;
class Resources2; class Resources2;
class ChatterinoBadges;
class Application class Application
{ {
@ -60,6 +61,7 @@ public:
TaggedUsersController *const taggedUsers{}; TaggedUsersController *const taggedUsers{};
ModerationActions *const moderationActions{}; ModerationActions *const moderationActions{};
TwitchServer *const twitch2{}; TwitchServer *const twitch2{};
ChatterinoBadges *const chatterinoBadges{};
/*[[deprecated]]*/ Logging *const logging{}; /*[[deprecated]]*/ Logging *const logging{};

View file

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

View file

@ -1,25 +1,30 @@
#pragma once #pragma once
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <common/Singleton.hpp>
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include <map>
#include <vector>
namespace chatterino { namespace chatterino {
struct Emote; struct Emote;
using EmotePtr = std::shared_ptr<const Emote>; using EmotePtr = std::shared_ptr<const Emote>;
class ChatterinoBadges class ChatterinoBadges : public Singleton
{ {
public: public:
virtual void initialize(Settings &settings, Paths &paths) override;
ChatterinoBadges(); ChatterinoBadges();
boost::optional<EmotePtr> getBadge(const UserName &username); boost::optional<EmotePtr> getBadge(const UserName &username);
private: private:
void loadChatterinoBadges(); void loadChatterinoBadges();
std::map<QString, int> badgeMap;
// UniqueAccess<EmoteCache<UserName>> badges; std::vector<EmotePtr> emotes;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -7,6 +7,7 @@
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "providers/LinkResolver.hpp" #include "providers/LinkResolver.hpp"
#include "providers/chatterino/ChatterinoBadges.hpp"
#include "providers/twitch/TwitchBadges.hpp" #include "providers/twitch/TwitchBadges.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "singletons/Emotes.hpp" #include "singletons/Emotes.hpp"
@ -796,20 +797,12 @@ void TwitchMessageBuilder::appendTwitchBadges()
void TwitchMessageBuilder::appendChatterinoBadges() void TwitchMessageBuilder::appendChatterinoBadges()
{ {
// auto app = getApp(); auto chatterinoBadgePtr =
getApp()->chatterinoBadges->getBadge({this->userName});
// auto &badges = app->resources->chatterinoBadges; if (chatterinoBadgePtr) {
// auto it = badges.find(this->userName.toStdString()); this->emplace<EmoteElement>(*chatterinoBadgePtr,
MessageElementFlag::BadgeChatterino);
// if (it == badges.end()) { }
// return;
// }
// const auto badge = it->second;
// this->emplace<ImageElement>(badge->image,
// MessageElementFlag::BadgeChatterino)
// ->setTooltip(QString::fromStdString(badge->tooltip));
} }
Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string) Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)