2017-12-31 00:50:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
#include "providers/twitch/twitchaccount.hpp"
|
2018-05-06 12:52:47 +02:00
|
|
|
#include "util/sharedptrelementless.hpp"
|
|
|
|
#include "util/signalvector2.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 {
|
2018-05-26 20:25:00 +02:00
|
|
|
namespace controllers {
|
|
|
|
namespace accounts {
|
|
|
|
class AccountController;
|
|
|
|
}
|
|
|
|
} // namespace controllers
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
namespace providers {
|
2017-12-31 00:50:07 +01:00
|
|
|
namespace twitch {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
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();
|
2018-04-22 14:38:10 +02:00
|
|
|
void load();
|
2017-12-31 00:50:07 +01:00
|
|
|
|
2018-06-24 15:09:56 +02:00
|
|
|
bool isLoggedIn() const;
|
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
pajlada::Settings::Setting<std::string> currentUsername = {"/accounts/current", ""};
|
2018-05-06 12:52:47 +02:00
|
|
|
pajlada::Signals::NoArgSignal currentUserChanged;
|
2017-12-31 00:50:07 +01:00
|
|
|
pajlada::Signals::NoArgSignal userListUpdated;
|
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
util::SortedSignalVector<std::shared_ptr<TwitchAccount>,
|
|
|
|
util::SharedPtrElementLess<TwitchAccount>>
|
|
|
|
accounts;
|
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
private:
|
|
|
|
enum class AddUserResponse {
|
|
|
|
UserAlreadyExists,
|
|
|
|
UserValuesUpdated,
|
|
|
|
UserAdded,
|
|
|
|
};
|
|
|
|
AddUserResponse addUser(const UserData &data);
|
2018-05-28 08:51:39 +02:00
|
|
|
bool removeUser(TwitchAccount *account);
|
2017-12-31 00:50:07 +01:00
|
|
|
|
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;
|
2017-12-31 00:50:07 +01:00
|
|
|
mutable std::mutex mutex;
|
|
|
|
|
2018-05-26 20:25:00 +02:00
|
|
|
friend class chatterino::controllers::accounts::AccountController;
|
2017-12-31 00:50:07 +01:00
|
|
|
};
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-18 18:20:40 +01:00
|
|
|
} // namespace twitch
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace providers
|
2018-01-18 18:20:40 +01:00
|
|
|
} // namespace chatterino
|