Remove experimental IRC support (#5547)
This commit is contained in:
@@ -2,12 +2,18 @@
|
||||
|
||||
#include "common/Atomic.hpp"
|
||||
#include "common/Channel.hpp"
|
||||
#include "providers/irc/AbstractIrcServer.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "providers/irc/IrcConnection2.hpp"
|
||||
#include "util/RatelimitBucket.hpp"
|
||||
|
||||
#include <IrcMessage>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
#include <pajlada/signals/signalholder.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
namespace chatterino {
|
||||
@@ -18,11 +24,30 @@ class TwitchChannel;
|
||||
class BttvEmotes;
|
||||
class FfzEmotes;
|
||||
class SeventvEmotes;
|
||||
class RatelimitBucket;
|
||||
|
||||
class ITwitchIrcServer
|
||||
{
|
||||
public:
|
||||
ITwitchIrcServer() = default;
|
||||
virtual ~ITwitchIrcServer() = default;
|
||||
ITwitchIrcServer(const ITwitchIrcServer &) = delete;
|
||||
ITwitchIrcServer(ITwitchIrcServer &&) = delete;
|
||||
ITwitchIrcServer &operator=(const ITwitchIrcServer &) = delete;
|
||||
ITwitchIrcServer &operator=(ITwitchIrcServer &&) = delete;
|
||||
|
||||
virtual void connect() = 0;
|
||||
|
||||
virtual void sendRawMessage(const QString &rawMessage) = 0;
|
||||
|
||||
virtual ChannelPtr getOrAddChannel(const QString &dirtyChannelName) = 0;
|
||||
virtual ChannelPtr getChannelOrEmpty(const QString &dirtyChannelName) = 0;
|
||||
|
||||
virtual void addFakeMessage(const QString &data) = 0;
|
||||
|
||||
virtual void addGlobalSystemMessage(const QString &messageText) = 0;
|
||||
|
||||
virtual void forEachChannel(std::function<void(ChannelPtr)> func) = 0;
|
||||
|
||||
virtual void forEachChannelAndSpecialChannels(
|
||||
std::function<void(ChannelPtr)> func) = 0;
|
||||
@@ -46,9 +71,14 @@ public:
|
||||
// Update this interface with TwitchIrcServer methods as needed
|
||||
};
|
||||
|
||||
class TwitchIrcServer final : public AbstractIrcServer, public ITwitchIrcServer
|
||||
class TwitchIrcServer final : public ITwitchIrcServer, public QObject
|
||||
{
|
||||
public:
|
||||
enum class ConnectionType {
|
||||
Read,
|
||||
Write,
|
||||
};
|
||||
|
||||
TwitchIrcServer();
|
||||
~TwitchIrcServer() override = default;
|
||||
|
||||
@@ -88,6 +118,25 @@ public:
|
||||
void dropSeventvChannel(const QString &userID,
|
||||
const QString &emoteSetID) override;
|
||||
|
||||
void addFakeMessage(const QString &data) override;
|
||||
|
||||
void addGlobalSystemMessage(const QString &messageText) override;
|
||||
|
||||
// iteration
|
||||
void forEachChannel(std::function<void(ChannelPtr)> func) override;
|
||||
|
||||
void connect() override;
|
||||
void disconnect();
|
||||
|
||||
void sendMessage(const QString &channelName, const QString &message);
|
||||
void sendRawMessage(const QString &rawMessage) override;
|
||||
|
||||
ChannelPtr getOrAddChannel(const QString &dirtyChannelName) override;
|
||||
|
||||
ChannelPtr getChannelOrEmpty(const QString &dirtyChannelName) override;
|
||||
|
||||
void open(ConnectionType type);
|
||||
|
||||
private:
|
||||
Atomic<QString> lastUserThatWhisperedMe;
|
||||
|
||||
@@ -109,19 +158,21 @@ public:
|
||||
void setLastUserThatWhisperedMe(const QString &user) override;
|
||||
|
||||
protected:
|
||||
void initializeConnection(IrcConnection *connection,
|
||||
ConnectionType type) override;
|
||||
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
|
||||
void initializeConnection(IrcConnection *connection, ConnectionType type);
|
||||
std::shared_ptr<Channel> createChannel(const QString &channelName);
|
||||
|
||||
void privateMessageReceived(Communi::IrcPrivateMessage *message) override;
|
||||
void readConnectionMessageReceived(Communi::IrcMessage *message) override;
|
||||
void writeConnectionMessageReceived(Communi::IrcMessage *message) override;
|
||||
void privateMessageReceived(Communi::IrcPrivateMessage *message);
|
||||
void readConnectionMessageReceived(Communi::IrcMessage *message);
|
||||
void writeConnectionMessageReceived(Communi::IrcMessage *message);
|
||||
|
||||
std::shared_ptr<Channel> getCustomChannel(
|
||||
const QString &channelname) override;
|
||||
void onReadConnected(IrcConnection *connection);
|
||||
void onWriteConnected(IrcConnection *connection);
|
||||
void onDisconnected();
|
||||
void markChannelsConnected();
|
||||
|
||||
QString cleanChannelName(const QString &dirtyChannelName) override;
|
||||
bool hasSeparateWriteConnection() const override;
|
||||
std::shared_ptr<Channel> getCustomChannel(const QString &channelname);
|
||||
|
||||
QString cleanChannelName(const QString &dirtyChannelName);
|
||||
|
||||
private:
|
||||
void onMessageSendRequested(const std::shared_ptr<TwitchChannel> &channel,
|
||||
@@ -132,6 +183,23 @@ private:
|
||||
|
||||
bool prepareToSend(const std::shared_ptr<TwitchChannel> &channel);
|
||||
|
||||
QMap<QString, std::weak_ptr<Channel>> channels;
|
||||
std::mutex channelMutex;
|
||||
|
||||
QObjectPtr<IrcConnection> writeConnection_ = nullptr;
|
||||
QObjectPtr<IrcConnection> readConnection_ = nullptr;
|
||||
|
||||
// Our rate limiting bucket for the Twitch join rate limits
|
||||
// https://dev.twitch.tv/docs/irc/guide#rate-limits
|
||||
QObjectPtr<RatelimitBucket> joinBucket_;
|
||||
|
||||
QTimer reconnectTimer_;
|
||||
int falloffCounter_ = 1;
|
||||
|
||||
std::mutex connectionMutex_;
|
||||
|
||||
pajlada::Signals::SignalHolder connections_;
|
||||
|
||||
std::mutex lastMessageMutex_;
|
||||
std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_;
|
||||
std::queue<std::chrono::steady_clock::time_point> lastMessageMod_;
|
||||
|
||||
Reference in New Issue
Block a user