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

130 lines
3.4 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#include "common/Aliases.hpp"
#include "common/Atomic.hpp"
2018-08-02 14:23:27 +02:00
#include "common/UniqueAccess.hpp"
2018-06-26 14:09:39 +02:00
#include "controllers/accounts/Account.hpp"
2018-08-02 14:23:27 +02:00
#include "messages/Emote.hpp"
2018-06-26 14:09:39 +02:00
#include "providers/twitch/TwitchUser.hpp"
#include <rapidjson/document.h>
#include <QColor>
2017-04-12 17:46:44 +02:00
#include <QString>
#include <functional>
#include <mutex>
#include <set>
2018-05-06 12:52:47 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
enum IgnoreResult {
IgnoreResult_Success,
IgnoreResult_AlreadyIgnored,
IgnoreResult_Failed,
};
enum UnignoreResult {
UnignoreResult_Success,
UnignoreResult_Failed,
};
enum FollowResult {
FollowResult_Following,
FollowResult_NotFollowing,
FollowResult_Failed,
};
2018-06-26 17:06:17 +02:00
class TwitchAccount : public Account
2017-04-12 17:46:44 +02:00
{
public:
2018-08-02 14:23:27 +02:00
struct TwitchEmote {
EmoteId id;
EmoteName name;
};
struct EmoteSet {
QString key;
QString channelName;
QString text;
2018-08-11 14:20:53 +02:00
QString type;
2018-08-02 14:23:27 +02:00
std::vector<TwitchEmote> emotes;
};
std::map<QString, EmoteSet> staticEmoteSets;
struct TwitchAccountEmoteData {
std::vector<std::shared_ptr<EmoteSet>> emoteSets;
std::vector<EmoteName> allEmoteNames;
EmoteMap emotes;
};
2018-08-06 21:17:03 +02:00
TwitchAccount(const QString &username, const QString &oauthToken_,
const QString &oauthClient_, const QString &_userID);
2017-04-12 17:46:44 +02:00
2018-05-06 12:52:47 +02:00
virtual QString toString() const override;
2018-02-05 15:11:50 +01:00
const QString &getUserName() const;
2017-04-12 17:46:44 +02:00
const QString &getOAuthToken() const;
const QString &getOAuthClient() const;
const QString &getUserId() const;
2017-04-12 17:46:44 +02:00
QColor color();
void setColor(QColor color);
// Attempts to update the users OAuth Client ID
// Returns true if the value has changed, otherwise false
bool setOAuthClient(const QString &newClientID);
// Attempts to update the users OAuth Token
// Returns true if the value has changed, otherwise false
bool setOAuthToken(const QString &newOAuthToken);
2017-04-12 17:46:44 +02:00
bool isAnon() const;
void loadIgnores();
void ignore(const QString &targetName,
std::function<void(IgnoreResult, const QString &)> onFinished);
2018-08-06 21:17:03 +02:00
void ignoreByID(
const QString &targetUserID, const QString &targetName,
std::function<void(IgnoreResult, const QString &)> onFinished);
void unignore(
const QString &targetName,
std::function<void(UnignoreResult, const QString &)> onFinished);
void unignoreByID(
const QString &targetUserID, const QString &targetName,
std::function<void(UnignoreResult, const QString &message)> onFinished);
void checkFollow(const QString targetUserID,
std::function<void(FollowResult)> onFinished);
void followUser(const QString userID,
std::function<void()> successCallback);
void unfollowUser(const QString userID,
std::function<void()> successCallback);
std::set<TwitchUser> getIgnores() const;
2018-08-02 14:23:27 +02:00
void loadEmotes();
AccessGuard<const TwitchAccountEmoteData> accessEmotes() const;
2017-04-12 17:46:44 +02:00
private:
2018-08-02 14:23:27 +02:00
void parseEmotes(const rapidjson::Document &document);
void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet);
2018-07-06 19:23:47 +02:00
QString oauthClient_;
QString oauthToken_;
QString userName_;
QString userId_;
const bool isAnon_;
Atomic<QColor> color_;
2018-07-06 19:23:47 +02:00
mutable std::mutex ignoresMutex_;
std::set<TwitchUser> ignores_;
2018-08-02 14:23:27 +02:00
// std::map<UserId, TwitchAccountEmoteData> emotes;
UniqueAccess<TwitchAccountEmoteData> emotes_;
2017-04-12 17:46:44 +02:00
};
} // namespace chatterino