Refactored loading emotes and emotesets (#2539)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -8,6 +8,28 @@ namespace chatterino {
|
||||
|
||||
static Kraken *instance = nullptr;
|
||||
|
||||
void Kraken::getUserEmotes(TwitchAccount *account,
|
||||
ResultCallback<KrakenEmoteSets> successCallback,
|
||||
KrakenFailureCallback failureCallback)
|
||||
{
|
||||
this->makeRequest(QString("users/%1/emotes").arg(account->getUserId()), {})
|
||||
.authorizeTwitchV5(account->getOAuthClient(), account->getOAuthToken())
|
||||
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
|
||||
auto data = result.parseJson();
|
||||
|
||||
KrakenEmoteSets emoteSets(data);
|
||||
|
||||
successCallback(emoteSets);
|
||||
|
||||
return Success;
|
||||
})
|
||||
.onError([failureCallback](NetworkResult /*result*/) {
|
||||
// TODO: make better xd
|
||||
failureCallback();
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
NetworkRequest Kraken::makeRequest(QString url, QUrlQuery urlQuery)
|
||||
{
|
||||
assert(!url.startsWith("/"));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
@@ -14,11 +15,22 @@ using KrakenFailureCallback = std::function<void()>;
|
||||
template <typename... T>
|
||||
using ResultCallback = std::function<void(T...)>;
|
||||
|
||||
struct KrakenChannel {
|
||||
const QString status;
|
||||
struct KrakenEmoteSets {
|
||||
const QJsonObject emoteSets;
|
||||
|
||||
KrakenChannel(QJsonObject jsonObject)
|
||||
: status(jsonObject.value("status").toString())
|
||||
KrakenEmoteSets(QJsonObject jsonObject)
|
||||
: emoteSets(jsonObject.value("emoticon_sets").toObject())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct KrakenEmote {
|
||||
const QString code;
|
||||
const QString id;
|
||||
|
||||
KrakenEmote(QJsonObject jsonObject)
|
||||
: code(jsonObject.value("code").toString())
|
||||
, id(QString::number(jsonObject.value("id").toInt()))
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -26,6 +38,11 @@ struct KrakenChannel {
|
||||
class Kraken final : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
// https://dev.twitch.tv/docs/v5/reference/users#get-user-emotes
|
||||
void getUserEmotes(TwitchAccount *account,
|
||||
ResultCallback<KrakenEmoteSets> successCallback,
|
||||
KrakenFailureCallback failureCallback);
|
||||
|
||||
void update(QString clientId, QString oauthToken);
|
||||
|
||||
static void initialize();
|
||||
|
||||
Reference in New Issue
Block a user