mirror-chatterino2/src/ircmanager.hpp

93 lines
2.6 KiB
C++
Raw Normal View History

#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"
#include <IrcMessage>
#include <QMap>
#include <QMutex>
#include <QNetworkAccessManager>
#include <QString>
#include <pajlada/signals/signal.hpp>
2017-01-03 21:19:33 +01:00
#include <memory>
#include <mutex>
2017-01-18 21:30:23 +01:00
namespace chatterino {
class ChannelManager;
class Resources;
class EmoteManager;
class WindowManager;
2017-04-12 17:46:44 +02:00
class IrcManager : public QObject
2017-01-03 21:19:33 +01:00
{
2017-04-12 17:46:44 +02:00
Q_OBJECT
2017-01-03 21:19:33 +01:00
2017-04-12 17:46:44 +02:00
public:
IrcManager(ChannelManager &_channelManager, Resources &_resources, EmoteManager &_emoteManager,
WindowManager &_windowManager);
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);
void sendMessage(const QString &channelName, const 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-04-12 17:46:44 +02:00
const twitch::TwitchUser &getUser() const;
void setUser(const twitch::TwitchUser &account);
2017-01-17 00:15:44 +01:00
pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage;
2017-01-03 21:19:33 +01:00
private:
ChannelManager &channelManager;
Resources &resources;
EmoteManager &emoteManager;
WindowManager &windowManager;
2017-01-03 21:19:33 +01:00
2017-04-12 17:46:44 +02:00
// variables
twitch::TwitchUser _account;
pajlada::Settings::Setting<std::string> currentUser;
std::shared_ptr<Communi::IrcConnection> writeConnection = nullptr;
std::shared_ptr<Communi::IrcConnection> readConnection = nullptr;
std::mutex connectionMutex;
uint32_t connectionGeneration = 0;
2017-01-04 15:12:31 +01:00
2017-04-12 17:46:44 +02:00
QMap<QString, bool> _twitchBlockedUsers;
QMutex _twitchBlockedUsersMutex;
2017-01-03 21:19:33 +01:00
QNetworkAccessManager networkAccessManager;
2017-01-03 22:08:20 +01:00
2017-04-12 17:46:44 +02:00
// methods
Communi::IrcConnection *createConnection(bool doRead);
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-04-12 17:46:44 +02:00
void privateMessageReceived(Communi::IrcPrivateMessage *message);
void messageReceived(Communi::IrcMessage *message);
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-01-03 21:19:33 +01:00
};
} // namespace chatterino