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

193 lines
5.6 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"
2019-09-17 12:10:38 +02:00
#include "common/ChannelChatters.hpp"
#include "common/ChatterSet.hpp"
#include "common/Outcome.hpp"
2018-07-15 20:28:54 +02:00
#include "common/UniqueAccess.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
2018-08-13 13:54:39 +02:00
#include "providers/twitch/TwitchEmotes.hpp"
#include "providers/twitch/api/Helix.hpp"
#include "util/QStringHash.hpp"
2018-08-13 13:54:39 +02:00
#include <QColor>
#include <QElapsedTimer>
2018-08-13 13:54:39 +02:00
#include <QRegularExpression>
#include <boost/optional.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <mutex>
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;
class TwitchIrcServer;
class TwitchChannel : public Channel, public ChannelChatters
{
public:
struct StreamStatus {
bool live = false;
bool rerun = false;
unsigned viewerCount = 0;
QString title;
QString game;
QString gameId;
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;
};
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;
2019-10-07 20:31:34 +02:00
bool isVip() const;
bool isStaff() const;
2018-07-15 20:28:54 +02:00
virtual bool isBroadcaster() const override;
virtual bool hasHighRateLimit() const override;
virtual bool canReconnect() const override;
virtual void reconnect() override;
void refreshTitle();
void createClip();
2018-07-14 14:24:18 +02:00
// Data
const QString &subscriptionUrl();
const QString &channelUrl();
const QString &popoutPlayerUrl();
2021-01-16 13:58:11 +01:00
int chatterCount();
2018-10-13 14:20:06 +02:00
virtual bool isLive() const override;
2018-08-11 17:15:17 +02:00
QString roomId() const;
SharedAccessGuard<const RoomModes> accessRoomModes() const;
SharedAccessGuard<const StreamStatus> accessStreamStatus() const;
// Emotes
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(bool manualRefresh);
virtual void refreshFFZChannelEmotes(bool manualRefresh);
2018-08-13 13:54:39 +02:00
// Badges
2018-10-25 21:53:03 +02:00
boost::optional<EmotePtr> ffzCustomModBadge() const;
boost::optional<EmotePtr> ffzCustomVipBadge() 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
// Cheers
2019-09-08 18:01:38 +02:00
boost::optional<CheerEmote> cheerEmote(const QString &string);
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;
// Channel point rewards
pajlada::Signals::SelfDisconnectingSignal<ChannelPointReward>
channelPointRewardAdded;
void addChannelPointReward(const ChannelPointReward &reward);
bool isChannelPointRewardKnown(const QString &rewardId);
boost::optional<ChannelPointReward> channelPointReward(
const QString &rewardId) const;
private:
2018-07-15 20:28:54 +02:00
struct NameOptions {
QString displayName;
QString localizedName;
} nameOptions;
2018-07-15 20:28:54 +02:00
2019-02-26 21:00:57 +01:00
protected:
explicit TwitchChannel(const QString &channelName);
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();
void parseLiveStatus(bool live, const HelixStream &stream);
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();
void fetchDisplayName();
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_);
void setDisplayName(const QString &name);
void setLocalizedName(const QString &name);
const QString &getDisplayName() const override;
const QString &getLocalizedName() const override;
// Data
2018-07-15 20:28:54 +02:00
const QString subscriptionUrl_;
const QString channelUrl_;
const QString popoutPlayerUrl_;
2021-01-16 13:58:11 +01:00
int chatterCount_;
2018-07-15 20:28:54 +02:00
UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<RoomModes> roomModes_;
2019-02-26 21:00:57 +01:00
protected:
2018-08-11 17:15:17 +02:00
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
2019-09-08 11:36:35 +02:00
Atomic<boost::optional<EmotePtr>> ffzCustomModBadge_;
Atomic<boost::optional<EmotePtr>> ffzCustomVipBadge_;
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_;
UniqueAccess<std::map<QString, ChannelPointReward>> channelPointRewards_;
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
// --
QString lastSentMessage_;
QObject lifetimeGuard_;
2018-07-14 14:24:18 +02:00
QTimer liveStatusTimer_;
QTimer chattersListTimer_;
QElapsedTimer titleRefreshedTimer_;
QElapsedTimer clipCreationTimer_;
bool isClipCreationInProgress{false};
pajlada::Signals::SignalHolder signalHolder_;
friend class TwitchIrcServer;
2018-08-13 13:54:39 +02:00
friend class TwitchMessageBuilder;
friend class IrcMessageHandler;
2018-02-05 15:11:50 +01:00
};
} // namespace chatterino