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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

132 lines
4.2 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
#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"
#include "providers/twitch/TwitchEmotes.hpp"
#include "providers/twitch/TwitchUser.hpp"
#include "util/CancellationToken.hpp"
#include "util/QStringHash.hpp"
#include <boost/unordered/unordered_flat_map_fwd.hpp>
#include <pajlada/signals.hpp>
#include <QColor>
#include <QElapsedTimer>
#include <QObject>
2017-04-12 17:46:44 +02:00
#include <QString>
#include <rapidjson/document.h>
2017-04-12 17:46:44 +02:00
#include <functional>
#include <mutex>
#include <unordered_set>
2018-05-06 12:52:47 +02:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
2018-06-26 17:06:17 +02:00
class TwitchAccount : public Account
2017-04-12 17:46:44 +02:00
{
public:
2018-07-06 19:23:47 +02:00
TwitchAccount(const QString &username, const QString &oauthToken_,
const QString &oauthClient_, const QString &_userID);
~TwitchAccount() override;
TwitchAccount(const TwitchAccount &) = delete;
TwitchAccount(TwitchAccount &&) = delete;
TwitchAccount &operator=(const TwitchAccount &) = delete;
TwitchAccount &operator=(TwitchAccount &&) = delete;
2017-04-12 17:46:44 +02:00
QString toString() const override;
2018-05-06 12:52:47 +02:00
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
/**
* The Seventv user-id of the current user.
* Empty if there's no associated Seventv user with this twitch user.
*/
const QString &getSeventvUserID() const;
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 loadBlocks();
void blockUser(const QString &userId, const QObject *caller,
std::function<void()> onSuccess,
std::function<void()> onFailure);
void unblockUser(const QString &userId, const QObject *caller,
std::function<void()> onSuccess,
std::function<void()> onFailure);
2018-08-06 21:17:03 +02:00
void blockUserLocally(const QString &userID);
[[nodiscard]] const std::unordered_set<TwitchUser> &blocks() const;
[[nodiscard]] const std::unordered_set<QString> &blockedUserIds() const;
// Automod actions
void autoModAllow(const QString msgID, ChannelPtr channel);
void autoModDeny(const QString msgID, ChannelPtr channel);
void loadSeventvUserID();
/// Returns true if the account has access to the given emote set
bool hasEmoteSet(const EmoteSetId &id) const;
/// Returns a map of emote sets the account has access to
///
/// Key being the emote set ID, and contents being information about the emote set
/// and the emotes contained in the emote set
SharedAccessGuard<std::shared_ptr<const TwitchEmoteSetMap>>
accessEmoteSets() const;
/// Returns a map of emotes the account has access to
SharedAccessGuard<std::shared_ptr<const EmoteMap>> accessEmotes() const;
/// Sets the emotes this account has access to
///
/// This should only be used in tests.
void setEmotes(std::shared_ptr<const EmoteMap> emotes);
/// Return the emote by emote name if the account has access to the emote
std::optional<EmotePtr> twitchEmote(const EmoteName &name) const;
/// Once emotes are reloaded, TwitchAccountManager::emotesReloaded is
/// invoked with @a caller and an optional error.
void reloadEmotes(void *caller = nullptr);
2017-04-12 17:46:44 +02:00
private:
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
QStringList userstateEmoteSets_;
ScopedCancellationToken blockToken_;
std::unordered_set<TwitchUser> ignores_;
std::unordered_set<QString> ignoresUserIds_;
2018-08-02 14:23:27 +02:00
ScopedCancellationToken emoteToken_;
UniqueAccess<std::shared_ptr<const TwitchEmoteSetMap>> emoteSets_;
UniqueAccess<std::shared_ptr<const EmoteMap>> emotes_;
QString seventvUserID_;
2017-04-12 17:46:44 +02:00
};
} // namespace chatterino