mirror-chatterino2/src/providers/twitch/TwitchChannel.hpp

132 lines
3.3 KiB
C++
Raw Normal View History

#pragma once
2018-02-05 15:11:50 +01:00
#include <IrcConnection>
2018-06-26 15:33:51 +02:00
#include "common/Channel.hpp"
#include "common/Common.hpp"
2018-06-26 17:20:03 +02:00
#include "common/MutexValue.hpp"
2018-06-28 19:46:45 +02:00
#include "singletons/Emotes.hpp"
2018-06-26 14:09:39 +02:00
#include "util/ConcurrentMap.hpp"
#include <pajlada/signals/signalholder.hpp>
#include <mutex>
namespace chatterino {
2018-02-05 15:11:50 +01:00
class TwitchServer;
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
{
public:
struct StreamStatus {
bool live = false;
bool rerun = false;
unsigned viewerCount = 0;
QString title;
QString game;
QString uptime;
QString streamType;
};
struct UserState {
bool mod;
bool broadcaster;
};
2018-05-24 08:58:34 +02:00
struct RoomModes {
bool submode = false;
bool r9k = false;
bool emoteOnly = false;
// int folowerOnly = 0;
int slowMode = 0;
QString broadcasterLang;
};
bool isEmpty() const override;
bool canSendMessage() const override;
void sendMessage(const QString &message) override;
2018-07-14 14:24:18 +02:00
bool isLive() const;
virtual bool isMod() const override;
2018-01-17 18:36:12 +01:00
void setMod(bool value);
virtual bool isBroadcaster() const override;
2018-01-17 17:17:26 +01:00
2018-07-14 14:24:18 +02:00
QString getRoomID() const;
void setRoomID(const QString &id);
RoomModes getRoomModes();
void setRoomModes(const RoomModes &roomModes_);
StreamStatus getStreamStatus() const;
void addRecentChatter(const std::shared_ptr<Message> &message) final;
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
2018-07-14 14:24:18 +02:00
struct NameOptions {
QString displayName;
QString localizedName;
};
void refreshChannelEmotes();
2018-06-26 17:06:17 +02:00
const std::shared_ptr<EmoteMap> bttvChannelEmotes;
const std::shared_ptr<EmoteMap> ffzChannelEmotes;
const QString subscriptionURL;
const QString channelURL;
const QString popoutPlayerURL;
2018-07-14 14:24:18 +02:00
pajlada::Signals::NoArgSignal roomIDChanged;
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::NoArgSignal userStateChanged;
2018-05-24 08:58:34 +02:00
pajlada::Signals::NoArgSignal roomModesChanged;
private:
2018-02-05 15:11:50 +01:00
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
2018-07-14 14:24:18 +02:00
void initializeLiveStatusTimer(int intervalMS);
void refreshLiveStatus();
2018-07-14 14:24:18 +02:00
void refreshPubsub();
void refreshViewerList();
bool parseViewerList(const QJsonObject &jsonRoot);
void loadRecentMessages();
bool parseRecentMessages(const QJsonObject &jsonRoot);
void setLive(bool newLiveStatus);
2018-07-06 19:23:47 +02:00
mutable std::mutex streamStatusMutex_;
StreamStatus streamStatus_;
2018-07-06 19:23:47 +02:00
mutable std::mutex userStateMutex_;
UserState userState_;
2018-07-06 19:23:47 +02:00
bool mod_ = false;
QByteArray messageSuffix_;
QString lastSentMessage_;
RoomModes roomModes_;
std::mutex roomModeMutex_;
2018-07-14 14:24:18 +02:00
MutexValue<QString> roomID_;
2018-01-17 17:17:26 +01:00
2018-07-06 19:23:47 +02:00
QObject object_;
std::mutex joinedUserMutex_;
QStringList joinedUsers_;
bool joinedUsersMergeQueued_ = false;
std::mutex partedUserMutex_;
QStringList partedUsers_;
bool partedUsersMergeQueued_ = false;
2018-07-06 19:23:47 +02:00
Communi::IrcConnection *readConnection_ = nullptr;
2018-07-06 19:23:47 +02:00
// Key = login name
std::map<QString, NameOptions> recentChatters_;
std::mutex recentChattersMutex_;
2018-02-05 15:11:50 +01:00
2018-07-14 14:24:18 +02:00
QTimer liveStatusTimer_;
QTimer chattersListTimer_;
2018-02-05 15:11:50 +01:00
friend class TwitchServer;
};
} // namespace chatterino