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

68 lines
1.7 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#pragma once
2018-02-05 15:11:50 +01:00
#include "providers/twitch/twitchaccount.hpp"
2017-12-31 00:50:07 +01:00
#include <pajlada/settings/setting.hpp>
#include <mutex>
#include <vector>
//
// Warning: This class is not supposed to be created directly.
// Get yourself an instance from our friends over at AccountManager.hpp
//
namespace chatterino {
2017-12-31 22:58:35 +01:00
namespace singletons {
2017-12-31 00:50:07 +01:00
class AccountManager;
2017-12-31 22:58:35 +01:00
}
2018-02-05 15:11:50 +01:00
namespace providers {
2017-12-31 00:50:07 +01:00
namespace twitch {
class TwitchAccountManager
{
TwitchAccountManager();
public:
struct UserData {
QString username;
QString userID;
QString clientID;
QString oauthToken;
};
// Returns the current twitchUsers, or the anonymous user if we're not currently logged in
2018-02-05 15:11:50 +01:00
std::shared_ptr<TwitchAccount> getCurrent();
2017-12-31 00:50:07 +01:00
std::vector<QString> getUsernames() const;
2018-02-05 15:11:50 +01:00
std::shared_ptr<TwitchAccount> findUserByUsername(const QString &username) const;
2017-12-31 00:50:07 +01:00
bool userExists(const QString &username) const;
void reloadUsers();
bool removeUser(const QString &username);
pajlada::Settings::Setting<std::string> currentUsername = {"/accounts/current", ""};
pajlada::Signals::NoArgSignal userChanged;
pajlada::Signals::NoArgSignal userListUpdated;
private:
enum class AddUserResponse {
UserAlreadyExists,
UserValuesUpdated,
UserAdded,
};
AddUserResponse addUser(const UserData &data);
2018-02-05 15:11:50 +01:00
std::shared_ptr<TwitchAccount> currentUser;
2017-12-31 00:50:07 +01:00
2018-02-05 15:11:50 +01:00
std::shared_ptr<TwitchAccount> anonymousUser;
std::vector<std::shared_ptr<TwitchAccount>> users;
2017-12-31 00:50:07 +01:00
mutable std::mutex mutex;
2017-12-31 22:58:35 +01:00
friend class chatterino::singletons::AccountManager;
2017-12-31 00:50:07 +01:00
};
} // namespace twitch
2018-02-05 15:11:50 +01:00
} // namespace providers
} // namespace chatterino