PubSub system (#346)

* Add websocketpp dependency

* Initial pubsub commit

Renamed selection min and max variables to selectionMin and selectionMax
to bypass windows min/max macros being stupid.

TwitchAccount is now initialized with its User ID. It cannot be changed
after it has been initialized.

* Update openssl folder

* Update installation instructions

* Split up websocketpp dependency to its own code only and openssl.pri

* Add missing include to asio steady_timer

* Update dependencies for linux
This commit is contained in:
pajlada
2018-04-15 15:09:31 +02:00
committed by GitHub
parent d5097e71a3
commit 23cf8cc484
33 changed files with 1502 additions and 68 deletions
+2 -6
View File
@@ -6,10 +6,11 @@ namespace providers {
namespace twitch {
TwitchAccount::TwitchAccount(const QString &_username, const QString &_oauthToken,
const QString &_oauthClient)
const QString &_oauthClient, const QString &_userID)
: oauthClient(_oauthClient)
, oauthToken(_oauthToken)
, userName(_username)
, userId(_userID)
, _isAnon(_username == ANONYMOUS_USERNAME)
{
}
@@ -34,11 +35,6 @@ const QString &TwitchAccount::getUserId() const
return this->userId;
}
void TwitchAccount::setUserId(const QString &id)
{
this->userId = id;
}
bool TwitchAccount::setOAuthClient(const QString &newClientID)
{
if (this->oauthClient.compare(newClientID) == 0) {
+3 -3
View File
@@ -10,14 +10,14 @@ namespace twitch {
class TwitchAccount
{
public:
TwitchAccount(const QString &username, const QString &oauthToken, const QString &oauthClient);
TwitchAccount(const QString &username, const QString &oauthToken, const QString &oauthClient,
const QString &_userID);
const QString &getUserName() const;
const QString &getOAuthToken() const;
const QString &getOAuthClient() const;
const QString &getUserId() const;
void setUserId(const QString &id);
// Attempts to update the users OAuth Client ID
// Returns true if the value has changed, otherwise false
@@ -34,8 +34,8 @@ public:
private:
QString oauthClient;
QString oauthToken;
QString userId;
QString userName;
QString userId;
const bool _isAnon;
};
@@ -10,7 +10,7 @@ namespace twitch {
TwitchAccountManager::TwitchAccountManager()
{
this->anonymousUser.reset(new TwitchAccount(ANONYMOUS_USERNAME, "", ""));
this->anonymousUser.reset(new TwitchAccount(ANONYMOUS_USERNAME, "", "", ""));
this->currentUsername.connect([this](const auto &newValue, auto) {
QString newUsername(QString::fromStdString(newValue));
@@ -175,11 +175,8 @@ TwitchAccountManager::AddUserResponse TwitchAccountManager::addUser(
}
}
auto newUser =
std::make_shared<TwitchAccount>(userData.username, userData.oauthToken, userData.clientID);
// Set users User ID without the uid prefix
newUser->setUserId(userData.userID);
auto newUser = std::make_shared<TwitchAccount>(userData.username, userData.oauthToken,
userData.clientID, userData.userID);
std::lock_guard<std::mutex> lock(this->mutex);
+29
View File
@@ -3,9 +3,12 @@
#include "debug/log.hpp"
#include "messages/message.hpp"
#include "providers/twitch/twitchmessagebuilder.hpp"
#include "singletons/accountmanager.hpp"
#include "singletons/emotemanager.hpp"
#include "singletons/ircmanager.hpp"
#include "singletons/pubsubmanager.hpp"
#include "singletons/settingsmanager.hpp"
#include "util/posttothread.hpp"
#include "util/urlfetch.hpp"
#include <IrcConnection>
@@ -40,6 +43,32 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection
this->refreshLiveStatus(); //
});
this->managedConnect(singletons::AccountManager::getInstance().Twitch.userChanged,
[this]() { this->setMod(false); });
auto refreshPubSubState = [this]() {
const auto &x = this;
if (!this->hasModRights()) {
return;
}
if (this->roomID.isEmpty()) {
return;
}
auto account = singletons::AccountManager::getInstance().Twitch.getCurrent();
if (account && !account->getUserId().isEmpty()) {
singletons::PubSubManager::getInstance().ListenToChannelModerationActions(this->roomID,
account);
}
};
this->userStateChanged.connect(refreshPubSubState);
this->roomIDchanged.connect(refreshPubSubState);
this->managedConnect(singletons::AccountManager::getInstance().Twitch.userChanged,
refreshPubSubState);
refreshPubSubState();
this->fetchMessages.connect([this] {
this->fetchRecentMessages(); //
});
+11 -1
View File
@@ -8,6 +8,8 @@
#include "singletons/ircmanager.hpp"
#include "util/concurrentmap.hpp"
#include <pajlada/signals/signalholder.hpp>
#include <mutex>
namespace chatterino {
@@ -16,7 +18,7 @@ namespace twitch {
class TwitchServer;
class TwitchChannel final : public Channel
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
{
QTimer *liveStatusTimer;
QTimer *chattersListTimer;
@@ -31,6 +33,11 @@ public:
QString uptime;
};
struct UserState {
bool mod;
bool broadcaster;
};
~TwitchChannel() final;
void reloadChannelEmotes();
@@ -88,6 +95,9 @@ private:
mutable std::mutex streamStatusMutex;
StreamStatus streamStatus;
mutable std::mutex userStateMutex;
UserState userState;
void fetchRecentMessages();
bool mod;
@@ -606,7 +606,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
}
} else if (badge.startsWith("subscriber/")) {
if (channelResources.loaded == false) {
qDebug() << "Channel resources are not loaded, can't add the subscriber badge";
// qDebug() << "Channel resources are not loaded, can't add the subscriber badge";
continue;
}
+2 -2
View File
@@ -1,11 +1,11 @@
#pragma once
#include <memory>
#include "providers/irc/abstractircserver.hpp"
#include "providers/twitch/twitchaccount.hpp"
#include "providers/twitch/twitchchannel.hpp"
#include <memory>
namespace chatterino {
namespace providers {
namespace twitch {