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

159 lines
4.2 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-07-15 20:28:54 +02:00
#include "common/UniqueAccess.hpp"
2018-08-02 14:23:27 +02:00
#include "messages/Emote.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>
2018-08-02 14:23:27 +02:00
#include <unordered_map>
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;
};
2018-07-15 20:28:54 +02:00
void refreshChannelEmotes();
2018-01-17 17:17:26 +01:00
2018-07-15 20:28:54 +02:00
// Channel methods
virtual bool isEmpty() const override;
virtual bool canSendMessage() const override;
virtual void sendMessage(const QString &message) override;
2018-07-14 14:24:18 +02:00
2018-07-15 20:28:54 +02:00
// Auto completion
void addRecentChatter(const std::shared_ptr<Message> &message) final;
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
2018-07-15 20:28:54 +02:00
// Twitch data
bool isLive() const;
virtual bool isMod() const override;
void setMod(bool value);
virtual bool isBroadcaster() const override;
2018-07-14 14:24:18 +02:00
2018-07-15 20:28:54 +02:00
QString getRoomId() const;
void setRoomId(const QString &id);
const AccessGuard<RoomModes> accessRoomModes() const;
void setRoomModes(const RoomModes &roomModes_);
const AccessGuard<StreamStatus> accessStreamStatus() const;
2018-08-02 14:23:27 +02:00
boost::optional<EmotePtr> getBttvEmote(const EmoteName &name) const;
boost::optional<EmotePtr> getFfzEmote(const EmoteName &name) const;
AccessGuard<const EmoteMap> accessBttvEmotes() const;
AccessGuard<const EmoteMap> accessFfzEmotes() const;
2018-07-15 20:28:54 +02:00
const QString &getSubscriptionUrl();
const QString &getChannelUrl();
const QString &getPopoutPlayerUrl();
2018-08-02 14:23:27 +02:00
boost::optional<EmotePtr> getTwitchBadge(const QString &set, const QString &version) const;
2018-07-15 20:28:54 +02:00
// Signals
pajlada::Signals::NoArgSignal roomIdChanged;
2018-07-14 14:24:18 +02:00
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::NoArgSignal userStateChanged;
2018-05-24 08:58:34 +02:00
pajlada::Signals::NoArgSignal roomModesChanged;
private:
2018-07-15 20:28:54 +02:00
struct NameOptions {
QString displayName;
QString localizedName;
};
2018-08-02 14:23:27 +02:00
struct CheerEmote {
// a Cheermote indicates one tier
QColor color;
int minBits;
EmotePtr animatedEmote;
EmotePtr staticEmote;
};
struct CheerEmoteSet {
QRegularExpression regex;
std::vector<CheerEmote> cheerEmotes;
};
explicit TwitchChannel(const QString &channelName);
2018-02-05 15:11:50 +01:00
2018-07-15 20:28:54 +02:00
// Methods
void refreshLiveStatus();
2018-08-02 14:23:27 +02:00
Outcome parseLiveStatus(const rapidjson::Document &document);
2018-07-14 14:24:18 +02:00
void refreshPubsub();
void refreshViewerList();
2018-08-02 14:23:27 +02:00
Outcome parseViewerList(const QJsonObject &jsonRoot);
2018-07-14 14:24:18 +02:00
void loadRecentMessages();
2018-08-02 14:23:27 +02:00
Outcome parseRecentMessages(const QJsonObject &jsonRoot);
2018-07-14 14:24:18 +02:00
void setLive(bool newLiveStatus);
2018-08-02 14:23:27 +02:00
void loadBadges();
void loadCheerEmotes();
2018-07-15 20:28:54 +02:00
// Twitch data
UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<UserState> userState_;
UniqueAccess<RoomModes> roomModes_;
2018-08-02 14:23:27 +02:00
UniqueAccess<EmoteMap> bttvEmotes_;
UniqueAccess<EmoteMap> ffzEmotes_;
2018-07-15 20:28:54 +02:00
const QString subscriptionUrl_;
const QString channelUrl_;
const QString popoutPlayerUrl_;
2018-07-06 19:23:47 +02:00
bool mod_ = false;
2018-07-14 14:24:18 +02:00
MutexValue<QString> roomID_;
2018-01-17 17:17:26 +01:00
2018-07-15 20:28:54 +02:00
UniqueAccess<QStringList> joinedUsers_;
2018-07-06 19:23:47 +02:00
bool joinedUsersMergeQueued_ = false;
2018-07-15 20:28:54 +02:00
UniqueAccess<QStringList> partedUsers_;
2018-07-06 19:23:47 +02:00
bool partedUsersMergeQueued_ = false;
2018-08-02 14:23:27 +02:00
// "subscribers": { "0": ... "3": ... "6": ...
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>> badgeSets_;
std::vector<CheerEmoteSet> cheerEmoteSets_;
2018-07-15 20:28:54 +02:00
// --
QByteArray messageSuffix_;
QString lastSentMessage_;
QObject lifetimeGuard_;
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