2017-06-07 10:09:24 +02:00
|
|
|
#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>
|
2017-04-14 14:08:57 +02:00
|
|
|
#include <vector>
|
2017-04-13 16:06:23 +02:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2017-12-16 02:21:06 +01:00
|
|
|
class AccountManager;
|
|
|
|
|
|
|
|
class TwitchAccountManager
|
|
|
|
{
|
|
|
|
public:
|
2017-12-19 16:13:02 +01:00
|
|
|
TwitchAccountManager();
|
|
|
|
|
2017-12-19 15:12:33 +01:00
|
|
|
struct UserData {
|
|
|
|
QString username;
|
|
|
|
QString userID;
|
|
|
|
QString clientID;
|
|
|
|
QString oauthToken;
|
|
|
|
};
|
|
|
|
|
2017-12-16 02:21:06 +01:00
|
|
|
// 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;
|
|
|
|
|
2017-12-19 15:12:33 +01:00
|
|
|
void reloadUsers();
|
|
|
|
|
|
|
|
bool removeUser(const QString &username);
|
|
|
|
|
2017-12-16 02:21:06 +01:00
|
|
|
pajlada::Settings::Setting<std::string> currentUsername = {"/accounts/current", ""};
|
|
|
|
pajlada::Signals::NoArgSignal userChanged;
|
2017-12-19 15:12:33 +01:00
|
|
|
pajlada::Signals::NoArgSignal userListUpdated;
|
2017-12-16 02:21:06 +01:00
|
|
|
|
|
|
|
private:
|
2017-12-19 15:12:33 +01:00
|
|
|
enum class AddUserResponse {
|
|
|
|
UserAlreadyExists,
|
|
|
|
UserValuesUpdated,
|
|
|
|
UserAdded,
|
|
|
|
};
|
|
|
|
AddUserResponse addUser(const UserData &data);
|
2017-12-16 02:21:06 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2017-04-19 15:25:05 +02:00
|
|
|
static AccountManager instance;
|
2017-04-12 17:46:44 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-07-28 19:46:53 +02:00
|
|
|
void load();
|
|
|
|
|
2017-12-16 02:21:06 +01:00
|
|
|
TwitchAccountManager Twitch;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
AccountManager();
|
|
|
|
};
|
2017-05-27 17:45:40 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace chatterino
|