mirror-chatterino2/src/accountmanager.hpp

77 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
2017-04-12 17:46:44 +02:00
2017-06-11 09:31:45 +02:00
#include "twitch/twitchuser.hpp"
2017-04-12 17:46:44 +02:00
2017-09-24 18:14:22 +02:00
#include <pajlada/settings/setting.hpp>
2017-04-13 16:06:23 +02:00
#include <mutex>
#include <vector>
2017-04-13 16:06:23 +02:00
2017-04-12 17:46:44 +02:00
namespace chatterino {
class AccountManager;
class TwitchAccountManager
{
public:
TwitchAccountManager();
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
std::shared_ptr<twitch::TwitchUser> getCurrent();
std::vector<QString> getUsernames() const;
std::shared_ptr<twitch::TwitchUser> findUserByUsername(const QString &username) const;
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);
std::shared_ptr<twitch::TwitchUser> currentUser;
std::shared_ptr<twitch::TwitchUser> anonymousUser;
std::vector<std::shared_ptr<twitch::TwitchUser>> users;
mutable std::mutex mutex;
friend class AccountManager;
};
2017-04-12 17:46:44 +02:00
class AccountManager
{
public:
static AccountManager &getInstance()
{
static AccountManager instance;
2017-04-12 17:46:44 +02:00
return instance;
}
void load();
TwitchAccountManager Twitch;
2017-04-12 17:46:44 +02:00
private:
AccountManager();
};
2017-04-14 17:52:22 +02:00
} // namespace chatterino