refactor: load Twitch emotes from Helix (#5239)
This commit is contained in:
@@ -266,18 +266,18 @@ struct HelixEmoteSetData {
|
||||
};
|
||||
|
||||
struct HelixChannelEmote {
|
||||
const QString emoteId;
|
||||
const QString id;
|
||||
const QString name;
|
||||
const QString type;
|
||||
const QString setId;
|
||||
const QString url;
|
||||
const QString setID;
|
||||
const QString ownerID;
|
||||
|
||||
explicit HelixChannelEmote(QJsonObject jsonObject)
|
||||
: emoteId(jsonObject.value("id").toString())
|
||||
, name(jsonObject.value("name").toString())
|
||||
, type(jsonObject.value("emote_type").toString())
|
||||
, setId(jsonObject.value("emote_set_id").toString())
|
||||
, url(TWITCH_EMOTE_TEMPLATE.arg(this->emoteId, u"3.0"))
|
||||
explicit HelixChannelEmote(const QJsonObject &jsonObject)
|
||||
: id(jsonObject["id"].toString())
|
||||
, name(jsonObject["name"].toString())
|
||||
, type(jsonObject["emote_type"].toString())
|
||||
, setID(jsonObject["emote_set_id"].toString())
|
||||
, ownerID(jsonObject["owner_id"].toString())
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -438,6 +438,22 @@ struct HelixSentMessage {
|
||||
}
|
||||
};
|
||||
|
||||
struct HelixFollowedChannel {
|
||||
QString broadcasterID;
|
||||
QString broadcasterLogin;
|
||||
QString broadcasterName;
|
||||
QDateTime followedAt;
|
||||
|
||||
explicit HelixFollowedChannel(const QJsonObject &jsonObject)
|
||||
: broadcasterID(jsonObject["broadcaster_id"].toString())
|
||||
, broadcasterLogin(jsonObject["broadcaster_login"].toString())
|
||||
, broadcasterName(jsonObject["broadcaster_name"].toString())
|
||||
, followedAt(QDateTime::fromString(jsonObject["followed_at"].toString(),
|
||||
Qt::ISODate))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct HelixSendMessageArgs {
|
||||
QString broadcasterID;
|
||||
QString senderID;
|
||||
@@ -786,6 +802,10 @@ struct HelixError {
|
||||
|
||||
using HelixGetChannelBadgesError = HelixGetGlobalBadgesError;
|
||||
|
||||
struct HelixPaginationState {
|
||||
bool done;
|
||||
};
|
||||
|
||||
class IHelix
|
||||
{
|
||||
public:
|
||||
@@ -1112,6 +1132,21 @@ public:
|
||||
ResultCallback<HelixSentMessage> successCallback,
|
||||
FailureCallback<HelixSendMessageError, QString> failureCallback) = 0;
|
||||
|
||||
/// https://dev.twitch.tv/docs/api/reference/#get-user-emotes
|
||||
virtual void getUserEmotes(
|
||||
QString userID, QString broadcasterID,
|
||||
ResultCallback<std::vector<HelixChannelEmote>, HelixPaginationState>
|
||||
pageCallback,
|
||||
FailureCallback<QString> failureCallback,
|
||||
CancellationToken &&token) = 0;
|
||||
|
||||
/// https://dev.twitch.tv/docs/api/reference/#get-followed-channels
|
||||
/// (non paginated)
|
||||
virtual void getFollowedChannel(
|
||||
QString userID, QString broadcasterID,
|
||||
ResultCallback<std::optional<HelixFollowedChannel>> successCallback,
|
||||
FailureCallback<QString> failureCallback) = 0;
|
||||
|
||||
virtual void update(QString clientId, QString oauthToken) = 0;
|
||||
|
||||
protected:
|
||||
@@ -1440,6 +1475,21 @@ public:
|
||||
ResultCallback<HelixSentMessage> successCallback,
|
||||
FailureCallback<HelixSendMessageError, QString> failureCallback) final;
|
||||
|
||||
/// https://dev.twitch.tv/docs/api/reference/#get-user-emotes
|
||||
void getUserEmotes(
|
||||
QString userID, QString broadcasterID,
|
||||
ResultCallback<std::vector<HelixChannelEmote>, HelixPaginationState>
|
||||
pageCallback,
|
||||
FailureCallback<QString> failureCallback,
|
||||
CancellationToken &&token) final;
|
||||
|
||||
/// https://dev.twitch.tv/docs/api/reference/#get-followed-channels
|
||||
/// (non paginated)
|
||||
void getFollowedChannel(
|
||||
QString userID, QString broadcasterID,
|
||||
ResultCallback<std::optional<HelixFollowedChannel>> successCallback,
|
||||
FailureCallback<QString> failureCallback) final;
|
||||
|
||||
void update(QString clientId, QString oauthToken) final;
|
||||
|
||||
static void initialize();
|
||||
@@ -1494,7 +1544,9 @@ private:
|
||||
/// Paginate the `url` endpoint and use `baseQuery` as the starting point for pagination.
|
||||
/// @param onPage returns true while a new page is expected. Once false is returned, pagination will stop.
|
||||
void paginate(const QString &url, const QUrlQuery &baseQuery,
|
||||
std::function<bool(const QJsonObject &)> onPage,
|
||||
std::function<bool(const QJsonObject &,
|
||||
const HelixPaginationState &state)>
|
||||
onPage,
|
||||
std::function<void(NetworkResult)> onError,
|
||||
CancellationToken &&token);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user