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

181 lines
5.1 KiB
C++
Raw Normal View History

#pragma once
#include "common/Aliases.hpp"
2018-08-11 17:15:17 +02:00
#include "common/Atomic.hpp"
2018-06-26 15:33:51 +02:00
#include "common/Channel.hpp"
#include "common/Outcome.hpp"
2018-07-15 20:28:54 +02:00
#include "common/UniqueAccess.hpp"
2018-08-13 13:54:39 +02:00
#include "common/UsernameSet.hpp"
2018-10-25 21:53:03 +02:00
#include "providers/ffz/FfzModBadge.hpp"
2018-08-13 13:54:39 +02:00
#include "providers/twitch/TwitchEmotes.hpp"
2018-08-13 13:54:39 +02:00
#include <rapidjson/document.h>
#include <IrcConnection>
#include <QColor>
#include <QRegularExpression>
#include <boost/optional.hpp>
#include <mutex>
#include <pajlada/signals/signalholder.hpp>
2018-08-02 14:23:27 +02:00
#include <unordered_map>
namespace chatterino {
2018-08-29 19:25:37 +02:00
enum class HighlightState;
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap;
2018-08-14 17:45:17 +02:00
class TwitchBadges;
class FfzEmotes;
class BttvEmotes;
2018-02-05 15:11:50 +01:00
class TwitchServer;
2019-02-26 21:00:57 +01:00
class TwitchChannel : 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;
};
2018-05-24 08:58:34 +02:00
struct RoomModes {
bool submode = false;
bool r9k = false;
bool emoteOnly = false;
int followerOnly = -1;
2018-05-24 08:58:34 +02:00
int slowMode = 0;
QString broadcasterLang;
};
2018-08-13 13:54:39 +02:00
void initialize();
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;
virtual bool isMod() const override;
bool isVIP() const;
bool isStaff() const;
2018-07-15 20:28:54 +02:00
virtual bool isBroadcaster() const override;
virtual bool hasHighRateLimit() const override;
2018-07-14 14:24:18 +02:00
// Data
const QString &subscriptionUrl();
const QString &channelUrl();
const QString &popoutPlayerUrl();
2018-10-13 14:20:06 +02:00
virtual bool isLive() const override;
2018-08-11 17:15:17 +02:00
QString roomId() const;
2018-08-06 18:25:47 +02:00
AccessGuard<const RoomModes> accessRoomModes() const;
AccessGuard<const StreamStatus> accessStreamStatus() const;
2018-08-13 13:54:39 +02:00
AccessGuard<const UsernameSet> accessChatters() const;
// Emotes
2018-08-14 17:45:17 +02:00
const TwitchBadges &globalTwitchBadges() const;
const BttvEmotes &globalBttv() const;
const FfzEmotes &globalFfz() const;
2018-08-11 17:15:17 +02:00
boost::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
std::shared_ptr<const EmoteMap> bttvEmotes() const;
std::shared_ptr<const EmoteMap> ffzEmotes() const;
virtual void refreshBTTVChannelEmotes();
virtual void refreshFFZChannelEmotes();
2018-08-13 13:54:39 +02:00
// Badges
2018-10-25 21:53:03 +02:00
boost::optional<EmotePtr> ffzCustomModBadge() const;
2018-08-13 13:54:39 +02:00
boost::optional<EmotePtr> twitchBadge(const QString &set,
const QString &version) const;
2018-08-02 14:23:27 +02:00
2018-07-15 20:28:54 +02:00
// Signals
pajlada::Signals::NoArgSignal roomIdChanged;
pajlada::Signals::NoArgSignal userStateChanged;
2018-08-13 13:54:39 +02:00
pajlada::Signals::NoArgSignal liveStatusChanged;
2018-05-24 08:58:34 +02:00
pajlada::Signals::NoArgSignal roomModesChanged;
2018-08-13 13:54:39 +02:00
protected:
void addRecentChatter(const MessagePtr &message) override;
private:
2018-07-15 20:28:54 +02:00
struct NameOptions {
QString displayName;
QString localizedName;
};
2019-02-26 21:00:57 +01:00
protected:
2018-08-14 17:45:17 +02:00
explicit TwitchChannel(const QString &channelName,
TwitchBadges &globalTwitchBadges,
BttvEmotes &globalBttv, FfzEmotes &globalFfz);
2018-02-05 15:11:50 +01:00
2019-02-26 21:00:57 +01:00
private:
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();
2018-08-13 13:54:39 +02:00
void refreshChatters();
void refreshBadges();
void refreshCheerEmotes();
2018-07-14 14:24:18 +02:00
void loadRecentMessages();
2018-08-13 13:54:39 +02:00
void addJoinedUser(const QString &user);
void addPartedUser(const QString &user);
2018-07-14 14:24:18 +02:00
void setLive(bool newLiveStatus);
2018-08-13 13:54:39 +02:00
void setMod(bool value);
void setVIP(bool value);
void setStaff(bool value);
2018-08-13 13:54:39 +02:00
void setRoomId(const QString &id);
void setRoomModes(const RoomModes &roomModes_);
// Data
2018-07-15 20:28:54 +02:00
const QString subscriptionUrl_;
const QString channelUrl_;
const QString popoutPlayerUrl_;
UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<RoomModes> roomModes_;
2018-08-13 13:54:39 +02:00
UniqueAccess<UsernameSet> chatters_; // maps 2 char prefix to set of names
// Emotes
2018-08-14 17:45:17 +02:00
TwitchBadges &globalTwitchBadges_;
2019-02-26 21:00:57 +01:00
protected:
BttvEmotes &globalBttv_;
FfzEmotes &globalFfz_;
2018-08-11 17:15:17 +02:00
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
2019-02-26 21:00:57 +01:00
private:
2018-08-13 13:54:39 +02:00
// Badges
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>>
badgeSets_; // "subscribers": { "0": ... "3": ... "6": ...
UniqueAccess<std::vector<CheerEmoteSet>> cheerEmoteSets_;
2018-10-25 21:53:03 +02:00
FfzModBadge ffzCustomModBadge_;
2018-07-06 19:23:47 +02:00
bool mod_ = false;
bool vip_ = false;
bool staff_ = false;
2018-08-10 19:00:14 +02:00
UniqueAccess<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-07-15 20:28:54 +02:00
// --
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;
2018-08-13 13:54:39 +02:00
friend class TwitchMessageBuilder;
friend class IrcMessageHandler;
2018-02-05 15:11:50 +01:00
};
} // namespace chatterino