mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
parent
e332564e01
commit
56aac47fde
5 changed files with 53 additions and 41 deletions
|
@ -9,6 +9,7 @@
|
|||
#include "debug/Log.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/chatterino/ChatterinoBadges.hpp"
|
||||
#include "providers/ffz/FfzEmotes.hpp"
|
||||
#include "providers/twitch/PubsubClient.hpp"
|
||||
#include "providers/twitch/TwitchServer.hpp"
|
||||
|
@ -52,6 +53,7 @@ Application::Application(Settings &_settings, Paths &_paths)
|
|||
, taggedUsers(&this->emplace<TaggedUsersController>())
|
||||
, moderationActions(&this->emplace<ModerationActions>())
|
||||
, twitch2(&this->emplace<TwitchServer>())
|
||||
, chatterinoBadges(&this->emplace<ChatterinoBadges>())
|
||||
, logging(&this->emplace<Logging>())
|
||||
{
|
||||
this->instance = this;
|
||||
|
|
|
@ -26,6 +26,7 @@ class Emotes;
|
|||
class Settings;
|
||||
class Fonts;
|
||||
class Resources2;
|
||||
class ChatterinoBadges;
|
||||
|
||||
class Application
|
||||
{
|
||||
|
@ -60,6 +61,7 @@ public:
|
|||
TaggedUsersController *const taggedUsers{};
|
||||
ModerationActions *const moderationActions{};
|
||||
TwitchServer *const twitch2{};
|
||||
ChatterinoBadges *const chatterinoBadges{};
|
||||
|
||||
/*[[deprecated]]*/ Logging *const logging{};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,25 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <common/Singleton.hpp>
|
||||
|
||||
#include "common/Aliases.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
|
||||
class ChatterinoBadges
|
||||
class ChatterinoBadges : public Singleton
|
||||
{
|
||||
public:
|
||||
virtual void initialize(Settings &settings, Paths &paths) override;
|
||||
ChatterinoBadges();
|
||||
|
||||
boost::optional<EmotePtr> getBadge(const UserName &username);
|
||||
|
||||
private:
|
||||
void loadChatterinoBadges();
|
||||
|
||||
// UniqueAccess<EmoteCache<UserName>> badges;
|
||||
std::map<QString, int> badgeMap;
|
||||
std::vector<EmotePtr> emotes;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "debug/Log.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "providers/LinkResolver.hpp"
|
||||
#include "providers/chatterino/ChatterinoBadges.hpp"
|
||||
#include "providers/twitch/TwitchBadges.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
|
@ -796,20 +797,12 @@ void TwitchMessageBuilder::appendTwitchBadges()
|
|||
|
||||
void TwitchMessageBuilder::appendChatterinoBadges()
|
||||
{
|
||||
// auto app = getApp();
|
||||
|
||||
// auto &badges = app->resources->chatterinoBadges;
|
||||
// auto it = badges.find(this->userName.toStdString());
|
||||
|
||||
// if (it == badges.end()) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const auto badge = it->second;
|
||||
|
||||
// this->emplace<ImageElement>(badge->image,
|
||||
// MessageElementFlag::BadgeChatterino)
|
||||
// ->setTooltip(QString::fromStdString(badge->tooltip));
|
||||
auto chatterinoBadgePtr =
|
||||
getApp()->chatterinoBadges->getBadge({this->userName});
|
||||
if (chatterinoBadgePtr) {
|
||||
this->emplace<EmoteElement>(*chatterinoBadgePtr,
|
||||
MessageElementFlag::BadgeChatterino);
|
||||
}
|
||||
}
|
||||
|
||||
Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
|
||||
|
|
Loading…
Reference in a new issue