#pragma once #include #include "common/Aliases.hpp" #include "common/Atomic.hpp" #include "common/Channel.hpp" #include "common/Outcome.hpp" #include "common/UniqueAccess.hpp" #include #include #include #include namespace chatterino { struct Emote; using EmotePtr = std::shared_ptr; class EmoteMap; class FfzEmotes; class BttvEmotes; 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; }; struct RoomModes { bool submode = false; bool r9k = false; bool emoteOnly = false; // int folowerOnly = 0; int slowMode = 0; QString broadcasterLang; }; void refreshChannelEmotes(); // Channel methods virtual bool isEmpty() const override; virtual bool canSendMessage() const override; virtual void sendMessage(const QString &message) override; // Auto completion void addRecentChatter(const MessagePtr &message) final; void addJoinedUser(const QString &user); void addPartedUser(const QString &user); bool isLive() const; virtual bool isMod() const override; void setMod(bool value); virtual bool isBroadcaster() const override; // Data const QString &subscriptionUrl(); const QString &channelUrl(); const QString &popoutPlayerUrl(); QString roomId() const; void setRoomId(const QString &id); AccessGuard accessRoomModes() const; void setRoomModes(const RoomModes &roomModes_); AccessGuard accessStreamStatus() const; // Emotes const BttvEmotes &globalBttv() const; const FfzEmotes &globalFfz() const; boost::optional bttvEmote(const EmoteName &name) const; boost::optional ffzEmote(const EmoteName &name) const; std::shared_ptr bttvEmotes() const; std::shared_ptr ffzEmotes() const; boost::optional getTwitchBadge(const QString &set, const QString &version) const; // Signals pajlada::Signals::NoArgSignal roomIdChanged; pajlada::Signals::NoArgSignal liveStatusChanged; pajlada::Signals::NoArgSignal userStateChanged; pajlada::Signals::NoArgSignal roomModesChanged; private: struct NameOptions { QString displayName; QString localizedName; }; struct CheerEmote { // a Cheermote indicates one tier QColor color; int minBits; EmotePtr animatedEmote; EmotePtr staticEmote; }; struct CheerEmoteSet { QRegularExpression regex; std::vector cheerEmotes; }; explicit TwitchChannel(const QString &channelName, BttvEmotes &bttv, FfzEmotes &ffz); // Methods void refreshLiveStatus(); Outcome parseLiveStatus(const rapidjson::Document &document); void refreshPubsub(); void refreshViewerList(); Outcome parseViewerList(const QJsonObject &jsonRoot); void loadRecentMessages(); void setLive(bool newLiveStatus); void loadBadges(); void loadCheerEmotes(); // Data const QString subscriptionUrl_; const QString channelUrl_; const QString popoutPlayerUrl_; UniqueAccess streamStatus_; UniqueAccess userState_; UniqueAccess roomModes_; // Emotes BttvEmotes &globalBttv_; FfzEmotes &globalFfz_; Atomic> bttvEmotes_; Atomic> ffzEmotes_; bool mod_ = false; UniqueAccess roomID_; UniqueAccess joinedUsers_; bool joinedUsersMergeQueued_ = false; UniqueAccess partedUsers_; bool partedUsersMergeQueued_ = false; // "subscribers": { "0": ... "3": ... "6": ... UniqueAccess>> badgeSets_; UniqueAccess> cheerEmoteSets_; // -- QByteArray messageSuffix_; QString lastSentMessage_; QObject lifetimeGuard_; QTimer liveStatusTimer_; QTimer chattersListTimer_; friend class TwitchServer; }; } // namespace chatterino