2018-02-05 15:11:50 +01:00
|
|
|
#pragma once
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
#include "common/Atomic.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "common/Channel.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/irc/AbstractIrcServer.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-12-31 15:41:01 +01:00
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
|
|
|
|
2018-06-24 12:59:47 +02:00
|
|
|
#include <chrono>
|
2018-04-15 15:09:31 +02:00
|
|
|
#include <memory>
|
2018-06-06 18:57:22 +02:00
|
|
|
#include <queue>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
namespace chatterino {
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
class Settings;
|
|
|
|
class Paths;
|
2018-08-13 14:38:03 +02:00
|
|
|
class TwitchChannel;
|
2024-01-21 14:20:21 +01:00
|
|
|
class BttvEmotes;
|
|
|
|
class FfzEmotes;
|
|
|
|
class SeventvEmotes;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-05-21 12:10:49 +02:00
|
|
|
class ITwitchIrcServer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ITwitchIrcServer() = default;
|
|
|
|
|
2024-06-01 14:56:40 +02:00
|
|
|
virtual void forEachChannelAndSpecialChannels(
|
|
|
|
std::function<void(ChannelPtr)> func) = 0;
|
|
|
|
|
|
|
|
virtual std::shared_ptr<Channel> getChannelOrEmptyByID(
|
|
|
|
const QString &channelID) = 0;
|
|
|
|
|
|
|
|
virtual void dropSeventvChannel(const QString &userID,
|
|
|
|
const QString &emoteSetID) = 0;
|
|
|
|
|
2023-10-13 17:41:23 +02:00
|
|
|
virtual const IndirectChannel &getWatchingChannel() const = 0;
|
2024-06-01 14:56:40 +02:00
|
|
|
virtual void setWatchingChannel(ChannelPtr newWatchingChannel) = 0;
|
|
|
|
virtual ChannelPtr getWhispersChannel() const = 0;
|
|
|
|
virtual ChannelPtr getMentionsChannel() const = 0;
|
|
|
|
virtual ChannelPtr getLiveChannel() const = 0;
|
|
|
|
virtual ChannelPtr getAutomodChannel() const = 0;
|
2023-05-21 12:10:49 +02:00
|
|
|
|
2024-02-17 13:26:54 +01:00
|
|
|
virtual QString getLastUserThatWhisperedMe() const = 0;
|
2024-06-01 14:56:40 +02:00
|
|
|
virtual void setLastUserThatWhisperedMe(const QString &user) = 0;
|
2024-02-17 13:26:54 +01:00
|
|
|
|
2023-05-21 12:10:49 +02:00
|
|
|
// Update this interface with TwitchIrcServer methods as needed
|
|
|
|
};
|
|
|
|
|
2024-06-03 10:31:30 +02:00
|
|
|
class TwitchIrcServer final : public AbstractIrcServer, public ITwitchIrcServer
|
2018-02-05 15:11:50 +01:00
|
|
|
{
|
2018-04-30 20:35:01 +02:00
|
|
|
public:
|
2019-09-18 13:03:16 +02:00
|
|
|
TwitchIrcServer();
|
2023-10-25 18:13:48 +02:00
|
|
|
~TwitchIrcServer() override = default;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-06-03 10:31:30 +02:00
|
|
|
TwitchIrcServer(const TwitchIrcServer &) = delete;
|
|
|
|
TwitchIrcServer(TwitchIrcServer &&) = delete;
|
|
|
|
TwitchIrcServer &operator=(const TwitchIrcServer &) = delete;
|
|
|
|
TwitchIrcServer &operator=(TwitchIrcServer &&) = delete;
|
|
|
|
|
|
|
|
void initialize();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-06-01 14:56:40 +02:00
|
|
|
void forEachChannelAndSpecialChannels(
|
|
|
|
std::function<void(ChannelPtr)> func) override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-06-01 14:56:40 +02:00
|
|
|
std::shared_ptr<Channel> getChannelOrEmptyByID(
|
|
|
|
const QString &channelID) override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-08-28 12:20:47 +02:00
|
|
|
void reloadBTTVGlobalEmotes();
|
|
|
|
void reloadAllBTTVChannelEmotes();
|
|
|
|
void reloadFFZGlobalEmotes();
|
|
|
|
void reloadAllFFZChannelEmotes();
|
2022-10-16 13:22:17 +02:00
|
|
|
void reloadSevenTVGlobalEmotes();
|
|
|
|
void reloadAllSevenTVChannelEmotes();
|
2022-08-28 12:20:47 +02:00
|
|
|
|
2022-11-13 12:07:41 +01:00
|
|
|
/** Calls `func` with all twitch channels that have `emoteSetId` added. */
|
|
|
|
void forEachSeventvEmoteSet(const QString &emoteSetId,
|
|
|
|
std::function<void(TwitchChannel &)> func);
|
|
|
|
/** Calls `func` with all twitch channels where the seventv-user-id is `userId`. */
|
|
|
|
void forEachSeventvUser(const QString &userId,
|
|
|
|
std::function<void(TwitchChannel &)> func);
|
|
|
|
/**
|
|
|
|
* Checks if any channel still needs this `userID` or `emoteSetID`.
|
|
|
|
* If not, it unsubscribes from the respective messages.
|
|
|
|
*
|
|
|
|
* It's currently not possible to share emote sets among users,
|
|
|
|
* but it's a commonly requested feature.
|
|
|
|
*/
|
2024-06-01 14:56:40 +02:00
|
|
|
void dropSeventvChannel(const QString &userID,
|
|
|
|
const QString &emoteSetID) override;
|
2022-11-13 12:07:41 +01:00
|
|
|
|
2024-06-01 14:56:40 +02:00
|
|
|
private:
|
2018-08-11 14:20:53 +02:00
|
|
|
Atomic<QString> lastUserThatWhisperedMe;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
const ChannelPtr whispersChannel;
|
|
|
|
const ChannelPtr mentionsChannel;
|
2021-05-09 16:17:04 +02:00
|
|
|
const ChannelPtr liveChannel;
|
2023-12-03 23:07:30 +01:00
|
|
|
const ChannelPtr automodChannel;
|
2018-04-20 19:54:45 +02:00
|
|
|
IndirectChannel watchingChannel;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-06-01 14:56:40 +02:00
|
|
|
public:
|
2023-10-13 17:41:23 +02:00
|
|
|
const IndirectChannel &getWatchingChannel() const override;
|
2024-06-01 14:56:40 +02:00
|
|
|
void setWatchingChannel(ChannelPtr newWatchingChannel) override;
|
|
|
|
ChannelPtr getWhispersChannel() const override;
|
|
|
|
ChannelPtr getMentionsChannel() const override;
|
|
|
|
ChannelPtr getLiveChannel() const override;
|
|
|
|
ChannelPtr getAutomodChannel() const override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2024-02-17 13:26:54 +01:00
|
|
|
QString getLastUserThatWhisperedMe() const override;
|
2024-06-01 14:56:40 +02:00
|
|
|
void setLastUserThatWhisperedMe(const QString &user) override;
|
2024-02-17 13:26:54 +01:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
protected:
|
2023-10-25 18:13:48 +02:00
|
|
|
void initializeConnection(IrcConnection *connection,
|
|
|
|
ConnectionType type) override;
|
|
|
|
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
|
|
|
|
|
|
|
|
void privateMessageReceived(Communi::IrcPrivateMessage *message) override;
|
|
|
|
void readConnectionMessageReceived(Communi::IrcMessage *message) override;
|
|
|
|
void writeConnectionMessageReceived(Communi::IrcMessage *message) override;
|
|
|
|
|
|
|
|
std::shared_ptr<Channel> getCustomChannel(
|
2018-07-16 17:23:41 +02:00
|
|
|
const QString &channelname) override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-25 18:13:48 +02:00
|
|
|
QString cleanChannelName(const QString &dirtyChannelName) override;
|
|
|
|
bool hasSeparateWriteConnection() const override;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-25 13:53:55 +02:00
|
|
|
private:
|
2024-02-25 14:45:55 +01:00
|
|
|
void onMessageSendRequested(const std::shared_ptr<TwitchChannel> &channel,
|
|
|
|
const QString &message, bool &sent);
|
|
|
|
void onReplySendRequested(const std::shared_ptr<TwitchChannel> &channel,
|
|
|
|
const QString &message, const QString &replyId,
|
|
|
|
bool &sent);
|
2022-07-31 12:45:25 +02:00
|
|
|
|
2024-02-25 14:45:55 +01:00
|
|
|
bool prepareToSend(const std::shared_ptr<TwitchChannel> &channel);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-24 13:06:11 +02:00
|
|
|
std::mutex lastMessageMutex_;
|
|
|
|
std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_;
|
|
|
|
std::queue<std::chrono::steady_clock::time_point> lastMessageMod_;
|
|
|
|
std::chrono::steady_clock::time_point lastErrorTimeSpeed_;
|
|
|
|
std::chrono::steady_clock::time_point lastErrorTimeAmount_;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-07-16 17:23:41 +02:00
|
|
|
pajlada::Signals::SignalHolder signalHolder_;
|
2018-02-05 15:11:50 +01:00
|
|
|
};
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace chatterino
|