Improve Twitch PubSub connection reliability (#3643)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2022-05-07 17:22:39 +02:00
committed by GitHub
parent 4aa5b04e37
commit f97780d84e
64 changed files with 3094 additions and 2126 deletions
+16 -8
View File
@@ -28,7 +28,8 @@
#ifndef NDEBUG
# include <rapidjson/document.h>
# include "providers/twitch/PubsubClient.hpp"
# include "providers/twitch/PubSubManager.hpp"
# include "providers/twitch/PubSubMessages.hpp"
# include "util/SampleCheerMessages.hpp"
# include "util/SampleLinks.hpp"
#endif
@@ -56,10 +57,10 @@ Window::Window(WindowType type)
this->addMenuBar();
#endif
this->signalHolder_.managedConnect(
getApp()->accounts->twitch.currentUserChanged, [this] {
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([this] {
this->onAccountSelected();
});
}));
this->onAccountSelected();
if (type == WindowType::Main)
@@ -284,17 +285,24 @@ void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
static bool alt = true;
if (alt)
{
doc.Parse(channelRewardMessage);
auto oMessage = parsePubSubBaseMessage(channelRewardMessage);
auto oInnerMessage =
oMessage->toInner<PubSubMessageMessage>()
->toInner<PubSubCommunityPointsChannelV1Message>();
app->twitch->addFakeMessage(channelRewardIRCMessage);
app->twitch->pubsub->signals_.pointReward.redeemed.invoke(
doc["data"]["message"]["data"]["redemption"]);
oInnerMessage->data.value("redemption").toObject());
alt = !alt;
}
else
{
doc.Parse(channelRewardMessage2);
auto oMessage = parsePubSubBaseMessage(channelRewardMessage2);
auto oInnerMessage =
oMessage->toInner<PubSubMessageMessage>()
->toInner<PubSubCommunityPointsChannelV1Message>();
app->twitch->pubsub->signals_.pointReward.redeemed.invoke(
doc["data"]["message"]["data"]["redemption"]);
oInnerMessage->data.value("redemption").toObject());
alt = !alt;
}
return "";
+2
View File
@@ -2,6 +2,7 @@
#include "widgets/BaseWindow.hpp"
#include <boost/signals2.hpp>
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
@@ -48,6 +49,7 @@ private:
std::shared_ptr<UpdateDialog> updateDialogHandle_;
pajlada::Signals::SignalHolder signalHolder_;
std::vector<boost::signals2::scoped_connection> bSignals_;
friend class Notebook;
};
+3
View File
@@ -167,6 +167,9 @@ AboutPage::AboutPage()
addLicense(form.getElement(), "lrucache",
"https://github.com/lamerman/cpp-lru-cache",
":/licenses/lrucache.txt");
addLicense(form.getElement(), "magic_enum",
"https://github.com/Neargye/magic_enum",
":/licenses/magic_enum.txt");
}
// Attributions
+3 -3
View File
@@ -103,10 +103,10 @@ Split::Split(QWidget *parent)
this->input_->ui_.textEdit->installEventFilter(parent);
// update placeholder text on Twitch account change and channel change
this->signalHolder_.managedConnect(
getApp()->accounts->twitch.currentUserChanged, [this] {
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([this] {
this->updateInputPlaceholder();
});
}));
this->signalHolder_.managedConnect(channelChanged, [this] {
this->updateInputPlaceholder();
});
+2
View File
@@ -10,6 +10,7 @@
#include <QShortcut>
#include <QVBoxLayout>
#include <QWidget>
#include <boost/signals2.hpp>
namespace chatterino {
@@ -151,6 +152,7 @@ private:
pajlada::Signals::Connection indirectChannelChangedConnection_;
pajlada::Signals::SignalHolder signalHolder_;
std::vector<boost::signals2::scoped_connection> bSignals_;
public slots:
void addSibling();
+3 -3
View File
@@ -204,10 +204,10 @@ SplitHeader::SplitHeader(Split *_split)
this->handleChannelChanged();
});
this->managedConnections_.managedConnect(
getApp()->accounts->twitch.currentUserChanged, [this] {
this->bSignals_.emplace_back(
getApp()->accounts->twitch.currentUserChanged.connect([this] {
this->updateModerationModeIcon();
});
}));
auto _ = [this](const auto &, const auto &) {
this->updateChannelText();
+5 -3
View File
@@ -2,15 +2,16 @@
#include "widgets/BaseWidget.hpp"
#include <QElapsedTimer>
#include <QMenu>
#include <QPoint>
#include <memory>
#include <boost/signals2.hpp>
#include <pajlada/settings/setting.hpp>
#include <pajlada/signals/connection.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <vector>
#include <QElapsedTimer>
#include <memory>
#include <vector>
namespace chatterino {
@@ -85,6 +86,7 @@ private:
pajlada::Signals::NoArgSignal modeUpdateRequested_;
pajlada::Signals::SignalHolder managedConnections_;
pajlada::Signals::SignalHolder channelConnections_;
std::vector<boost::signals2::scoped_connection> bSignals_;
public slots:
void reloadChannelEmotes();