diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d97e2d1..0e5f934c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ - Bugfix: Fixed announcements not showing up in mentions tab. (#5857) - Bugfix: Fixed the reply button showing for inline whispers and announcements. (#5863) - Bugfix: Fixed suspicious user treatment update messages not being searchable. (#5865) -- Dev: Add initial experimental EventSub support. (#5837) +- Dev: Add initial experimental EventSub support. (#5837, #5895) - Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784) - Dev: Updated Conan dependencies. (#5776) - Dev: Disable QT keywords (i.e. `emit`, `slots`, and `signals`). (#5882) diff --git a/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/helpers.hpp b/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/helpers.hpp deleted file mode 100644 index ee906c9b..00000000 --- a/lib/twitch-eventsub-ws/include/twitch-eventsub-ws/helpers.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include -#include -#include - -namespace chatterino::eventsub::lib { - -template -std::optional readMember(const boost::json::object &obj, - std::string_view key) -{ - const auto *it = obj.find(key); - - if (it == obj.end()) - { - // No member with the key found - std::cerr << "No member with the key " << key << " found\n"; - return std::nullopt; - } - - const auto result = boost::json::try_value_to(it->value()); - if (!result.has_value()) - { - std::cerr << key << " could not be deserialized to the desired type\n"; - // Member could not be serialized to this type - return std::nullopt; - } - - return result.value(); -} - -} // namespace chatterino::eventsub::lib diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 15d70f9b..3fe39864 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -461,8 +461,6 @@ CommandController::CommandController(const Paths &paths) this->registerCommand("/debug-test", &commands::debugTest); - this->registerCommand("/debug-eventsub", &commands::debugEventSub); - this->registerCommand("/shield", &commands::shieldModeOn); this->registerCommand("/shieldoff", &commands::shieldModeOff); diff --git a/src/controllers/commands/builtin/chatterino/Debugging.cpp b/src/controllers/commands/builtin/chatterino/Debugging.cpp index b11d0c0c..3dad9f68 100644 --- a/src/controllers/commands/builtin/chatterino/Debugging.cpp +++ b/src/controllers/commands/builtin/chatterino/Debugging.cpp @@ -9,7 +9,6 @@ #include "messages/Message.hpp" #include "messages/MessageBuilder.hpp" #include "messages/MessageElement.hpp" -#include "providers/twitch/eventsub/Controller.hpp" #include "providers/twitch/PubSubActions.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchIrcServer.hpp" @@ -190,57 +189,4 @@ QString debugTest(const CommandContext &ctx) return ""; } -QString debugEventSub(const CommandContext &ctx) -{ - (void)ctx; - - if (ctx.twitchChannel == nullptr) - { - return ""; - } - - // purposefully subscribe multiple times to ensure we can't sub too many times - // or create too many connections - - static eventsub::SubscriptionHandle handle1; - - handle1 = getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{ - .subscriptionType = "channel.ban", - .subscriptionVersion = "1", - .conditions = - { - { - "broadcaster_user_id", - ctx.twitchChannel->roomId(), - }, - }, - }); - auto handle2 = - getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{ - .subscriptionType = "channel.ban", - .subscriptionVersion = "1", - .conditions = - { - { - "broadcaster_user_id", - ctx.twitchChannel->roomId(), - }, - }, - }); - auto handle3 = - getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{ - .subscriptionType = "channel.ban", - .subscriptionVersion = "1", - .conditions = - { - { - "broadcaster_user_id", - ctx.twitchChannel->roomId(), - }, - }, - }); - - return ""; -} - } // namespace chatterino::commands diff --git a/src/controllers/commands/builtin/chatterino/Debugging.hpp b/src/controllers/commands/builtin/chatterino/Debugging.hpp index 2c02dcb2..0cfa448e 100644 --- a/src/controllers/commands/builtin/chatterino/Debugging.hpp +++ b/src/controllers/commands/builtin/chatterino/Debugging.hpp @@ -24,6 +24,4 @@ QString forceImageUnload(const CommandContext &ctx); QString debugTest(const CommandContext &ctx); -QString debugEventSub(const CommandContext &ctx); - } // namespace chatterino::commands diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 82793066..8d0a6478 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -1473,18 +1473,6 @@ void TwitchChannel::refreshPubSub() { getApp()->getTwitchPubSub()->listenToAutomod(roomId); getApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId); - this->eventSubChannelBanHandle = - getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{ - .subscriptionType = "channel.ban", - .subscriptionVersion = "1", - .conditions = - { - { - "broadcaster_user_id", - roomId, - }, - }, - }); this->eventSubChannelModerateHandle = getApp()->getEventSub()->subscribe(eventsub::SubscriptionRequest{ @@ -1505,7 +1493,7 @@ void TwitchChannel::refreshPubSub() } else { - this->eventSubChannelBanHandle.reset(); + this->eventSubChannelModerateHandle.reset(); } getApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId); } diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index aa91399e..8cd1c434 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -500,7 +500,6 @@ private: pajlada::Signals::SignalHolder signalHolder_; std::vector bSignals_; - eventsub::SubscriptionHandle eventSubChannelBanHandle; eventsub::SubscriptionHandle eventSubChannelModerateHandle; friend class TwitchIrcServer; diff --git a/src/providers/twitch/eventsub/Controller.hpp b/src/providers/twitch/eventsub/Controller.hpp index a218575b..113f4f12 100644 --- a/src/providers/twitch/eventsub/Controller.hpp +++ b/src/providers/twitch/eventsub/Controller.hpp @@ -31,10 +31,6 @@ public: /// /// If no open connection has room for this subscription, this function will /// create a new connection and queue up the subscription to run again after X seconds. - /// - /// TODO: Return a SubscriptionHandle that handles unsubscriptions - /// Dupe subscriptions should return shared subscription handles - /// So no more owners of the subscription handle means we send an unsubscribe request [[nodiscard]] virtual SubscriptionHandle subscribe( const SubscriptionRequest &request) = 0; }; diff --git a/src/providers/twitch/eventsub/SubscriptionHandle.cpp b/src/providers/twitch/eventsub/SubscriptionHandle.cpp index fb5b3bf2..175743fc 100644 --- a/src/providers/twitch/eventsub/SubscriptionHandle.cpp +++ b/src/providers/twitch/eventsub/SubscriptionHandle.cpp @@ -8,7 +8,7 @@ namespace chatterino::eventsub { RawSubscriptionHandle::RawSubscriptionHandle(SubscriptionRequest request_) : request(std::move(request_)) { - // getApp()->getEventSub()->addRef(request); + // The reference is added by the EventSub controller } RawSubscriptionHandle::~RawSubscriptionHandle() diff --git a/src/providers/twitch/eventsub/SubscriptionHandle.hpp b/src/providers/twitch/eventsub/SubscriptionHandle.hpp index 1676543f..1d8fe584 100644 --- a/src/providers/twitch/eventsub/SubscriptionHandle.hpp +++ b/src/providers/twitch/eventsub/SubscriptionHandle.hpp @@ -14,6 +14,10 @@ struct RawSubscriptionHandle { ~RawSubscriptionHandle(); }; +/// Keeps a reference count of a specific subscription +/// +/// If no more references exist of a specific subscription, we send an +/// unsubscription request using SubscriptionHandle = std::unique_ptr; } // namespace chatterino::eventsub