#pragma once #include #include "common/Channel.hpp" #include "common/Common.hpp" #include "common/MutexValue.hpp" #include "common/UniqueAccess.hpp" #include "singletons/Emotes.hpp" #include "util/ConcurrentMap.hpp" #include #include namespace chatterino { 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 std::shared_ptr &message) final; void addJoinedUser(const QString &user); void addPartedUser(const QString &user); // Twitch data bool isLive() const; virtual bool isMod() const override; void setMod(bool value); virtual bool isBroadcaster() const override; QString getRoomId() const; void setRoomId(const QString &id); const AccessGuard accessRoomModes() const; void setRoomModes(const RoomModes &roomModes_); const AccessGuard accessStreamStatus() const; const EmoteMap &getFfzEmotes() const; const EmoteMap &getBttvEmotes() const; const QString &getSubscriptionUrl(); const QString &getChannelUrl(); const QString &getPopoutPlayerUrl(); // Signals pajlada::Signals::NoArgSignal roomIdChanged; pajlada::Signals::NoArgSignal liveStatusChanged; pajlada::Signals::NoArgSignal userStateChanged; pajlada::Signals::NoArgSignal roomModesChanged; private: struct NameOptions { QString displayName; QString localizedName; }; explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection); // Methods void refreshLiveStatus(); bool parseLiveStatus(const rapidjson::Document &document); void refreshPubsub(); void refreshViewerList(); bool parseViewerList(const QJsonObject &jsonRoot); void loadRecentMessages(); bool parseRecentMessages(const QJsonObject &jsonRoot); void setLive(bool newLiveStatus); // Twitch data UniqueAccess streamStatus_; UniqueAccess userState_; UniqueAccess roomModes_; const std::shared_ptr bttvEmotes_; const std::shared_ptr ffzEmotes_; const QString subscriptionUrl_; const QString channelUrl_; const QString popoutPlayerUrl_; bool mod_ = false; MutexValue roomID_; UniqueAccess joinedUsers_; bool joinedUsersMergeQueued_ = false; UniqueAccess partedUsers_; bool partedUsersMergeQueued_ = false; // -- QByteArray messageSuffix_; QString lastSentMessage_; QObject lifetimeGuard_; QTimer liveStatusTimer_; QTimer chattersListTimer_; Communi::IrcConnection *readConnection_ = nullptr; friend class TwitchServer; }; } // namespace chatterino