From 5e3412c3bb00e11746f3a17f51e75c2cc836eba8 Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 3 Feb 2025 19:18:08 +0100 Subject: [PATCH] =?UTF-8?q?chore(pubsub):=20remove=20unused=20whisper=20co?= =?UTF-8?q?de=20=F0=9F=91=B7=F0=9F=8F=BB=E2=80=8D=E2=99=80=EF=B8=8F=20(#58?= =?UTF-8?q?98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/CMakeLists.txt | 2 - src/providers/twitch/PubSubManager.cpp | 58 +------------------ src/providers/twitch/PubSubManager.hpp | 16 ----- src/providers/twitch/PubSubMessages.hpp | 1 - .../twitch/pubsubmessages/Whisper.cpp | 40 ------------- .../twitch/pubsubmessages/Whisper.hpp | 55 ------------------ tests/src/TwitchPubSubClient.cpp | 38 ------------ 8 files changed, 2 insertions(+), 209 deletions(-) delete mode 100644 src/providers/twitch/pubsubmessages/Whisper.cpp delete mode 100644 src/providers/twitch/pubsubmessages/Whisper.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index bad35e7c..1616e804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Bugfix: Ensure miniaudio backend exits even if it doesn't exit cleanly. (#5896) - Dev: Add initial experimental EventSub support. (#5837, #5895) - Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784) +- Dev: Removed unused PubSub whisper code. (#5898) - Dev: Updated Conan dependencies. (#5776) - Dev: Disable QT keywords (i.e. `emit`, `slots`, and `signals`). (#5882) - Dev: Replaced usage of `parseTime` with `serverReceivedTime` for clearchat messages. (#5824, #5855) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d72d3ee1..e621676d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -454,8 +454,6 @@ set(SOURCE_FILES providers/twitch/pubsubmessages/Message.hpp providers/twitch/pubsubmessages/Unlisten.cpp providers/twitch/pubsubmessages/Unlisten.hpp - providers/twitch/pubsubmessages/Whisper.cpp - providers/twitch/pubsubmessages/Whisper.hpp providers/twitch/api/Helix.cpp providers/twitch/api/Helix.hpp diff --git a/src/providers/twitch/PubSubManager.cpp b/src/providers/twitch/PubSubManager.cpp index dd57a165..542795b3 100644 --- a/src/providers/twitch/PubSubManager.cpp +++ b/src/providers/twitch/PubSubManager.cpp @@ -616,30 +616,6 @@ void PubSub::stop() this->thread->detach(); } -bool PubSub::listenToWhispers() -{ - if (this->userID_.isEmpty()) - { - qCDebug(chatterinoPubSub) - << "Unable to listen to whispers topic, no user logged in"; - return false; - } - - static const QString topicFormat("whispers.%1"); - auto topic = topicFormat.arg(this->userID_); - - qCDebug(chatterinoPubSub) << "Listen to whispers" << topic; - - this->listenToTopic(topic); - - return true; -} - -void PubSub::unlistenWhispers() -{ - this->unlistenPrefix("whispers."); -} - void PubSub::listenToChannelModerationActions(const QString &channelID) { if (this->userID_.isEmpty()) @@ -1108,39 +1084,7 @@ void PubSub::handleMessageResponse(const PubSubMessageMessage &message) { QString topic = message.topic; - if (topic.startsWith("whispers.")) - { - auto oInnerMessage = message.toInner(); - if (!oInnerMessage) - { - return; - } - auto whisperMessage = *oInnerMessage; - - switch (whisperMessage.type) - { - case PubSubWhisperMessage::Type::WhisperReceived: { - this->whisper.received.invoke(whisperMessage); - } - break; - case PubSubWhisperMessage::Type::WhisperSent: { - this->whisper.sent.invoke(whisperMessage); - } - break; - case PubSubWhisperMessage::Type::Thread: { - // Handle thread? - } - break; - - case PubSubWhisperMessage::Type::INVALID: - default: { - qCDebug(chatterinoPubSub) - << "Invalid whisper type:" << whisperMessage.typeString; - } - break; - } - } - else if (topic.startsWith("chat_moderator_actions.")) + if (topic.startsWith("chat_moderator_actions.")) { auto oInnerMessage = message.toInner(); diff --git a/src/providers/twitch/PubSubManager.hpp b/src/providers/twitch/PubSubManager.hpp index bb21e658..ddce5129 100644 --- a/src/providers/twitch/PubSubManager.hpp +++ b/src/providers/twitch/PubSubManager.hpp @@ -129,26 +129,10 @@ public: Signal automodInfoMessage; } moderation; - struct { - // Parsing should be done in PubSubManager as well, - // but for now we just send the raw data - Signal received; - Signal sent; - } whisper; - struct { Signal redeemed; } pointReward; - /** - * Listen to incoming whispers for the currently logged in user. - * This topic is relevant for everyone. - * - * PubSub topic: whispers.{currentUserID} - */ - bool listenToWhispers(); - void unlistenWhispers(); - /** * Listen to moderation actions in the given channel. * This topic is relevant for everyone. diff --git a/src/providers/twitch/PubSubMessages.hpp b/src/providers/twitch/PubSubMessages.hpp index 48c4066b..7828422b 100644 --- a/src/providers/twitch/PubSubMessages.hpp +++ b/src/providers/twitch/PubSubMessages.hpp @@ -8,4 +8,3 @@ #include "providers/twitch/pubsubmessages/LowTrustUsers.hpp" // IWYU pragma: export #include "providers/twitch/pubsubmessages/Message.hpp" // IWYU pragma: export #include "providers/twitch/pubsubmessages/Unlisten.hpp" // IWYU pragma: export -#include "providers/twitch/pubsubmessages/Whisper.hpp" // IWYU pragma: export diff --git a/src/providers/twitch/pubsubmessages/Whisper.cpp b/src/providers/twitch/pubsubmessages/Whisper.cpp deleted file mode 100644 index 2001b8cc..00000000 --- a/src/providers/twitch/pubsubmessages/Whisper.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "providers/twitch/pubsubmessages/Whisper.hpp" - -#include "util/QMagicEnum.hpp" - -namespace chatterino { - -PubSubWhisperMessage::PubSubWhisperMessage(const QJsonObject &root) - : typeString(root.value("type").toString()) -{ - auto oType = qmagicenum::enumCast(this->typeString); - if (oType.has_value()) - { - this->type = oType.value(); - } - - // Parse information from data_object - auto data = root.value("data_object").toObject(); - - this->messageID = data.value("message_id").toString(); - this->id = data.value("id").toInt(); - this->threadID = data.value("thread_id").toString(); - this->body = data.value("body").toString(); - auto fromID = data.value("from_id"); - if (fromID.isString()) - { - this->fromUserID = fromID.toString(); - } - else - { - this->fromUserID = QString::number(data.value("from_id").toInt()); - } - - auto tags = data.value("tags").toObject(); - - this->fromUserLogin = tags.value("login").toString(); - this->fromUserDisplayName = tags.value("display_name").toString(); - this->fromUserColor = QColor(tags.value("color").toString()); -} - -} // namespace chatterino diff --git a/src/providers/twitch/pubsubmessages/Whisper.hpp b/src/providers/twitch/pubsubmessages/Whisper.hpp deleted file mode 100644 index 979cb6a1..00000000 --- a/src/providers/twitch/pubsubmessages/Whisper.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace chatterino { - -struct PubSubWhisperMessage { - enum class Type { - WhisperReceived, - WhisperSent, - Thread, - - INVALID, - }; - - QString typeString; - Type type = Type::INVALID; - - QString messageID; - int id; - QString threadID; - QString body; - QString fromUserID; - QString fromUserLogin; - QString fromUserDisplayName; - QColor fromUserColor; - - PubSubWhisperMessage() = default; - explicit PubSubWhisperMessage(const QJsonObject &root); -}; - -} // namespace chatterino - -template <> -constexpr magic_enum::customize::customize_t - magic_enum::customize::enum_name( - chatterino::PubSubWhisperMessage::Type value) noexcept -{ - switch (value) - { - case chatterino::PubSubWhisperMessage::Type::WhisperReceived: - return "whisper_received"; - - case chatterino::PubSubWhisperMessage::Type::WhisperSent: - return "whisper_sent"; - - case chatterino::PubSubWhisperMessage::Type::Thread: - return "thread"; - default: - return default_tag; - } -} diff --git a/tests/src/TwitchPubSubClient.cpp b/tests/src/TwitchPubSubClient.cpp index e195d937..3ca90943 100644 --- a/tests/src/TwitchPubSubClient.cpp +++ b/tests/src/TwitchPubSubClient.cpp @@ -2,7 +2,6 @@ #include "providers/twitch/PubSubClient.hpp" #include "providers/twitch/PubSubManager.hpp" #include "providers/twitch/pubsubmessages/AutoMod.hpp" -#include "providers/twitch/pubsubmessages/Whisper.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "Test.hpp" @@ -22,7 +21,6 @@ using namespace std::chrono_literals; * Server sends RECONNECT message to us, we should reconnect (INCOMPLETE, leaving for now since if we just ignore it and Twitch disconnects us we should already handle it properly) * Listen that required authentication, but authentication is missing (COMPLETE) * Listen that required authentication, but authentication is wrong (COMPLETE) - * Incoming Whisper message (COMPLETE) * Incoming AutoMod message * Incoming ChannelPoints message * Incoming ChatModeratorAction message (COMPLETE) @@ -260,42 +258,6 @@ TEST(TwitchPubSubClient, ExceedTopicLimitSingleStep) ASSERT_EQ(pubSub.diag.connectionsFailed, 0); } -TEST(TwitchPubSubClient, ReceivedWhisper) -{ - FTest pubSub("/receive-whisper", 1s); - - pubSub.start(); - - ReceivedMessage aReceivedWhisper; - - std::ignore = pubSub.whisper.received.connect( - [&aReceivedWhisper](const auto &whisperMessage) { - aReceivedWhisper = whisperMessage; - }); - - pubSub.listenToWhispers(); - - std::this_thread::sleep_for(150ms); - - ASSERT_EQ(pubSub.diag.connectionsOpened, 1); - ASSERT_EQ(pubSub.diag.connectionsClosed, 0); - ASSERT_EQ(pubSub.diag.connectionsFailed, 0); - ASSERT_EQ(pubSub.diag.messagesReceived, 3); - ASSERT_EQ(pubSub.diag.listenResponses, 1); - - ASSERT_TRUE(aReceivedWhisper); - - ASSERT_EQ(aReceivedWhisper->body, QString("me Kappa")); - ASSERT_EQ(aReceivedWhisper->fromUserLogin, QString("pajbot")); - ASSERT_EQ(aReceivedWhisper->fromUserID, QString("82008718")); - - pubSub.stop(); - - ASSERT_EQ(pubSub.diag.connectionsOpened, 1); - ASSERT_EQ(pubSub.diag.connectionsClosed, 1); - ASSERT_EQ(pubSub.diag.connectionsFailed, 0); -} - TEST(TwitchPubSubClient, ModeratorActionsUserBanned) { FTest pubSub("/moderator-actions-user-banned", 1s);