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

76 lines
1.8 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#pragma once
#include "common/SignalVector.hpp"
2018-06-26 14:09:39 +02:00
#include "providers/twitch/TwitchAccount.hpp"
#include "util/SharedPtrElementLess.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.
2018-08-06 21:17:03 +02:00
// Get yourself an instance from our friends over at
// AccountManager.hpp
2017-12-31 00:50:07 +01:00
//
namespace chatterino {
2018-06-26 17:06:17 +02:00
class AccountController;
2017-12-31 00:50:07 +01:00
class TwitchAccountManager
{
TwitchAccountManager();
public:
struct UserData {
QString username;
QString userID;
QString clientID;
QString oauthToken;
};
2018-08-06 21:17:03 +02:00
// 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-08-06 21:17:03 +02: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
bool isLoggedIn() const;
2018-08-06 21:17:03 +02: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-08-06 21:17:03 +02:00
SortedSignalVector<std::shared_ptr<TwitchAccount>,
SharedPtrElementLess<TwitchAccount>>
2018-05-06 12:52:47 +02:00
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-07-06 19:23:47 +02:00
std::shared_ptr<TwitchAccount> currentUser_;
2017-12-31 00:50:07 +01:00
2018-07-06 19:23:47 +02:00
std::shared_ptr<TwitchAccount> anonymousUser_;
mutable std::mutex mutex_;
2017-12-31 00:50:07 +01:00
friend class AccountController;
2017-12-31 00:50:07 +01:00
};
} // namespace chatterino