2017-06-06 15:57:54 +02:00
|
|
|
#pragma once
|
2017-01-03 21:19:33 +01:00
|
|
|
|
|
|
|
#define TWITCH_MAX_MESSAGELENGTH 500
|
|
|
|
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/message.hpp"
|
|
|
|
#include "twitch/twitchuser.hpp"
|
2017-01-16 03:15:07 +01:00
|
|
|
|
2017-12-16 17:14:38 +01:00
|
|
|
#include <ircconnection.h>
|
2017-01-16 03:15:07 +01:00
|
|
|
#include <IrcMessage>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QString>
|
2017-06-26 16:41:20 +02:00
|
|
|
#include <pajlada/signals/signal.hpp>
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-03-11 11:32:19 +01:00
|
|
|
#include <memory>
|
2017-06-06 16:13:41 +02:00
|
|
|
#include <mutex>
|
2017-03-11 11:32:19 +01:00
|
|
|
|
2017-01-18 21:30:23 +01:00
|
|
|
namespace chatterino {
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
class ChannelManager;
|
|
|
|
class Resources;
|
2017-12-31 00:50:07 +01:00
|
|
|
class AccountManager;
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
class IrcManager : public QObject
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
2017-12-31 00:50:07 +01:00
|
|
|
// Q_OBJECT
|
|
|
|
|
|
|
|
IrcManager(ChannelManager &channelManager, Resources &resources,
|
|
|
|
AccountManager &accountManager);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
public:
|
2017-12-31 00:50:07 +01:00
|
|
|
static IrcManager &getInstance();
|
2017-01-29 13:23:22 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void connect();
|
|
|
|
void disconnect();
|
|
|
|
|
2017-01-04 15:12:31 +01:00
|
|
|
bool isTwitchBlockedUser(QString const &username);
|
2017-01-11 18:52:09 +01:00
|
|
|
bool tryAddIgnoredUser(QString const &username, QString &errorMessage);
|
2017-01-04 15:12:31 +01:00
|
|
|
void addIgnoredUser(QString const &username);
|
2017-01-11 18:52:09 +01:00
|
|
|
bool tryRemoveIgnoredUser(QString const &username, QString &errorMessage);
|
2017-01-04 15:12:31 +01:00
|
|
|
void removeIgnoredUser(QString const &username);
|
|
|
|
|
2017-12-17 15:34:07 +01:00
|
|
|
void sendMessage(const QString &channelName, QString message);
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-06-06 16:06:13 +02:00
|
|
|
void joinChannel(const QString &channelName);
|
|
|
|
void partChannel(const QString &channelName);
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-12-16 17:14:38 +01:00
|
|
|
void setUser(std::shared_ptr<twitch::TwitchUser> newAccount);
|
2017-01-17 00:15:44 +01:00
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage;
|
2017-12-28 00:03:52 +01:00
|
|
|
void privateMessageReceived(Communi::IrcPrivateMessage *message);
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
Communi::IrcConnection *getReadConnection();
|
|
|
|
|
|
|
|
private:
|
2017-06-13 21:13:58 +02:00
|
|
|
ChannelManager &channelManager;
|
|
|
|
Resources &resources;
|
2017-12-31 00:50:07 +01:00
|
|
|
AccountManager &accountManager;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
// variables
|
2017-12-16 02:21:06 +01:00
|
|
|
std::shared_ptr<twitch::TwitchUser> account = nullptr;
|
2017-08-19 15:37:56 +02:00
|
|
|
|
2017-12-16 17:14:38 +01:00
|
|
|
std::unique_ptr<Communi::IrcConnection> writeConnection = nullptr;
|
|
|
|
std::unique_ptr<Communi::IrcConnection> readConnection = nullptr;
|
2017-06-06 15:57:54 +02:00
|
|
|
|
2017-06-06 16:13:41 +02:00
|
|
|
std::mutex connectionMutex;
|
2017-01-04 15:12:31 +01:00
|
|
|
|
2017-09-21 12:15:01 +02:00
|
|
|
QMap<QString, bool> twitchBlockedUsers;
|
|
|
|
QMutex twitchBlockedUsersMutex;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-07-02 13:10:06 +02:00
|
|
|
QNetworkAccessManager networkAccessManager;
|
2017-01-03 22:08:20 +01:00
|
|
|
|
2017-12-16 17:14:38 +01:00
|
|
|
void initializeConnection(const std::unique_ptr<Communi::IrcConnection> &connection,
|
|
|
|
bool isReadConnection);
|
2017-06-06 15:57:54 +02:00
|
|
|
|
|
|
|
void refreshIgnoredUsers(const QString &username, const QString &oauthClient,
|
|
|
|
const QString &oauthToken);
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void beginConnecting();
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
void messageReceived(Communi::IrcMessage *message);
|
|
|
|
|
2017-12-16 19:46:27 +01:00
|
|
|
void writeConnectionMessageReceived(Communi::IrcMessage *message);
|
|
|
|
|
2017-06-16 10:01:21 +02:00
|
|
|
void handleRoomStateMessage(Communi::IrcMessage *message);
|
|
|
|
void handleClearChatMessage(Communi::IrcMessage *message);
|
|
|
|
void handleUserStateMessage(Communi::IrcMessage *message);
|
|
|
|
void handleWhisperMessage(Communi::IrcMessage *message);
|
|
|
|
void handleUserNoticeMessage(Communi::IrcMessage *message);
|
2017-09-23 19:23:10 +02:00
|
|
|
void handleModeMessage(Communi::IrcMessage *message);
|
2017-12-16 19:20:57 +01:00
|
|
|
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
2017-12-16 19:46:27 +01:00
|
|
|
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
|
2017-12-16 18:11:36 +01:00
|
|
|
|
|
|
|
void onConnected();
|
|
|
|
void onDisconnected();
|
2017-12-17 15:34:07 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QByteArray messageSuffix;
|
2017-01-03 21:19:33 +01:00
|
|
|
};
|
|
|
|
|
2017-06-06 15:57:54 +02:00
|
|
|
} // namespace chatterino
|