2017-09-16 00:05:06 +02:00
|
|
|
#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-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/ConcurrentMap.hpp"
|
2017-09-16 00:05:06 +02:00
|
|
|
|
2018-04-15 15:09:31 +02:00
|
|
|
#include <pajlada/signals/signalholder.hpp>
|
|
|
|
|
2018-03-30 15:05:33 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
namespace chatterino {
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
class TwitchServer;
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2018-04-15 15:09:31 +02:00
|
|
|
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
|
2017-09-16 00:05:06 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-03-30 15:05:33 +02:00
|
|
|
struct StreamStatus {
|
|
|
|
bool live = false;
|
2018-04-08 15:14:14 +02:00
|
|
|
bool rerun = false;
|
2018-03-30 15:05:33 +02:00
|
|
|
unsigned viewerCount = 0;
|
|
|
|
QString title;
|
|
|
|
QString game;
|
|
|
|
QString uptime;
|
2018-05-26 16:31:43 +02:00
|
|
|
QString streamType;
|
2018-03-30 15:05:33 +02:00
|
|
|
};
|
|
|
|
|
2018-04-15 15:09:31 +02:00
|
|
|
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
|
2018-06-28 19:38:57 +02:00
|
|
|
void addRecentChatter(const std::shared_ptr<Message> &message) final;
|
2018-05-26 18:06:55 +02:00
|
|
|
void addJoinedUser(const QString &user);
|
|
|
|
void addPartedUser(const QString &user);
|
2018-03-30 12:16:12 +02:00
|
|
|
|
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;
|
2017-12-23 23:24:35 +01:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
const EmoteMap &getFfzEmotes() const;
|
|
|
|
const EmoteMap &getBttvEmotes() const;
|
|
|
|
const QString &getSubscriptionUrl();
|
|
|
|
const QString &getChannelUrl();
|
|
|
|
const QString &getPopoutPlayerUrl();
|
2017-09-16 00:05:06 +02:00
|
|
|
|
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;
|
2018-04-03 02:55:32 +02:00
|
|
|
pajlada::Signals::NoArgSignal userStateChanged;
|
2018-05-24 08:58:34 +02:00
|
|
|
pajlada::Signals::NoArgSignal roomModesChanged;
|
2017-12-28 00:03:52 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
private:
|
2018-07-15 20:28:54 +02:00
|
|
|
struct NameOptions {
|
|
|
|
QString displayName;
|
|
|
|
QString localizedName;
|
|
|
|
};
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
explicit TwitchChannel(const QString &channelName, Communi::IrcConnection *readConnection);
|
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
// Methods
|
2017-11-04 14:57:29 +01:00
|
|
|
void refreshLiveStatus();
|
2018-07-15 20:28:54 +02:00
|
|
|
bool parseLiveStatus(const rapidjson::Document &document);
|
2018-07-14 14:24:18 +02:00
|
|
|
void refreshPubsub();
|
|
|
|
void refreshViewerList();
|
|
|
|
bool parseViewerList(const QJsonObject &jsonRoot);
|
|
|
|
void loadRecentMessages();
|
|
|
|
bool parseRecentMessages(const QJsonObject &jsonRoot);
|
|
|
|
|
|
|
|
void setLive(bool newLiveStatus);
|
2017-11-04 14:57:29 +01:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
// Twitch data
|
|
|
|
UniqueAccess<StreamStatus> streamStatus_;
|
|
|
|
UniqueAccess<UserState> userState_;
|
|
|
|
UniqueAccess<RoomModes> roomModes_;
|
2018-03-30 15:05:33 +02:00
|
|
|
|
2018-07-15 20:28:54 +02:00
|
|
|
const std::shared_ptr<EmoteMap> bttvEmotes_;
|
|
|
|
const std::shared_ptr<EmoteMap> ffzEmotes_;
|
|
|
|
const QString subscriptionUrl_;
|
|
|
|
const QString channelUrl_;
|
|
|
|
const QString popoutPlayerUrl_;
|
2018-04-15 15:09:31 +02:00
|
|
|
|
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;
|
2017-11-04 14:57:29 +01:00
|
|
|
|
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-07-15 20:28:54 +02:00
|
|
|
Communi::IrcConnection *readConnection_ = nullptr;
|
2018-07-14 14:24:18 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
friend class TwitchServer;
|
|
|
|
};
|
2018-03-24 12:02:07 +01:00
|
|
|
|
2017-11-04 14:57:29 +01:00
|
|
|
} // namespace chatterino
|