2022-11-13 12:07:41 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "providers/liveupdates/BasicPubSubClient.hpp"
|
|
|
|
#include "providers/liveupdates/BasicPubSubManager.hpp"
|
|
|
|
#include "util/QStringHash.hpp"
|
|
|
|
|
|
|
|
#include <pajlada/signals/signal.hpp>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2023-02-04 13:42:52 +01:00
|
|
|
namespace seventv::eventapi {
|
|
|
|
struct Subscription;
|
|
|
|
struct Dispatch;
|
|
|
|
struct EmoteAddDispatch;
|
|
|
|
struct EmoteUpdateDispatch;
|
|
|
|
struct EmoteRemoveDispatch;
|
|
|
|
struct UserConnectionUpdateDispatch;
|
2023-07-29 11:49:44 +02:00
|
|
|
struct CosmeticCreateDispatch;
|
|
|
|
struct EntitlementCreateDeleteDispatch;
|
2023-02-04 13:42:52 +01:00
|
|
|
} // namespace seventv::eventapi
|
2022-12-31 15:41:01 +01:00
|
|
|
|
2023-07-29 11:49:44 +02:00
|
|
|
class SeventvBadges;
|
|
|
|
|
2023-02-04 13:42:52 +01:00
|
|
|
class SeventvEventAPI
|
|
|
|
: public BasicPubSubManager<seventv::eventapi::Subscription>
|
2022-11-13 12:07:41 +01:00
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
using Signal =
|
|
|
|
pajlada::Signals::Signal<T>; // type-id is vector<T, Alloc<T>>
|
|
|
|
|
|
|
|
public:
|
|
|
|
SeventvEventAPI(QString host,
|
|
|
|
std::chrono::milliseconds defaultHeartbeatInterval =
|
|
|
|
std::chrono::milliseconds(25000));
|
|
|
|
|
|
|
|
struct {
|
2023-02-04 13:42:52 +01:00
|
|
|
Signal<seventv::eventapi::EmoteAddDispatch> emoteAdded;
|
|
|
|
Signal<seventv::eventapi::EmoteUpdateDispatch> emoteUpdated;
|
|
|
|
Signal<seventv::eventapi::EmoteRemoveDispatch> emoteRemoved;
|
|
|
|
Signal<seventv::eventapi::UserConnectionUpdateDispatch> userUpdated;
|
2022-11-13 12:07:41 +01:00
|
|
|
} signals_; // NOLINT(readability-identifier-naming)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribes to a user and emote-set
|
|
|
|
* if not already subscribed.
|
|
|
|
*
|
|
|
|
* @param userID 7TV user-id, may be empty.
|
|
|
|
* @param emoteSetID 7TV emote-set-id, may be empty.
|
|
|
|
*/
|
|
|
|
void subscribeUser(const QString &userID, const QString &emoteSetID);
|
2023-07-29 11:49:44 +02:00
|
|
|
/**
|
|
|
|
* Subscribes to cosmetics and entitlements in a Twitch channel
|
|
|
|
* if not already subscribed.
|
|
|
|
*
|
|
|
|
* @param id Twitch channel id
|
|
|
|
*/
|
|
|
|
void subscribeTwitchChannel(const QString &id);
|
2022-11-13 12:07:41 +01:00
|
|
|
|
|
|
|
/** Unsubscribes from a user by its 7TV user id */
|
|
|
|
void unsubscribeUser(const QString &id);
|
|
|
|
/** Unsubscribes from an emote-set by its id */
|
|
|
|
void unsubscribeEmoteSet(const QString &id);
|
2023-07-29 11:49:44 +02:00
|
|
|
/** Unsubscribes from cosmetics and entitlements in a Twitch channel */
|
|
|
|
void unsubscribeTwitchChannel(const QString &id);
|
2022-11-13 12:07:41 +01:00
|
|
|
|
|
|
|
protected:
|
2023-02-04 13:42:52 +01:00
|
|
|
std::shared_ptr<BasicPubSubClient<seventv::eventapi::Subscription>>
|
2022-11-13 12:07:41 +01:00
|
|
|
createClient(liveupdates::WebsocketClient &client,
|
|
|
|
websocketpp::connection_hdl hdl) override;
|
|
|
|
void onMessage(
|
|
|
|
websocketpp::connection_hdl hdl,
|
2023-02-04 13:42:52 +01:00
|
|
|
BasicPubSubManager<seventv::eventapi::Subscription>::WebsocketMessagePtr
|
2022-11-13 12:07:41 +01:00
|
|
|
msg) override;
|
|
|
|
|
|
|
|
private:
|
2023-02-04 13:42:52 +01:00
|
|
|
void handleDispatch(const seventv::eventapi::Dispatch &dispatch);
|
2022-11-13 12:07:41 +01:00
|
|
|
|
2023-02-04 13:42:52 +01:00
|
|
|
void onEmoteSetUpdate(const seventv::eventapi::Dispatch &dispatch);
|
|
|
|
void onUserUpdate(const seventv::eventapi::Dispatch &dispatch);
|
2023-07-29 11:49:44 +02:00
|
|
|
void onCosmeticCreate(
|
|
|
|
const seventv::eventapi::CosmeticCreateDispatch &cosmetic);
|
|
|
|
void onEntitlementCreate(
|
|
|
|
const seventv::eventapi::EntitlementCreateDeleteDispatch &entitlement);
|
|
|
|
void onEntitlementDelete(
|
|
|
|
const seventv::eventapi::EntitlementCreateDeleteDispatch &entitlement);
|
2023-02-04 13:42:52 +01:00
|
|
|
|
|
|
|
/** emote-set ids */
|
2022-11-13 12:07:41 +01:00
|
|
|
std::unordered_set<QString> subscribedEmoteSets_;
|
2023-02-04 13:42:52 +01:00
|
|
|
/** user ids */
|
2022-11-13 12:07:41 +01:00
|
|
|
std::unordered_set<QString> subscribedUsers_;
|
2023-07-29 11:49:44 +02:00
|
|
|
/** Twitch channel ids */
|
|
|
|
std::unordered_set<QString> subscribedTwitchChannels_;
|
2022-11-13 12:07:41 +01:00
|
|
|
std::chrono::milliseconds heartbeatInterval_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace chatterino
|