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

80 lines
2 KiB
C++
Raw Normal View History

2017-12-31 00:50:07 +01:00
#pragma once
2018-06-26 14:09:39 +02:00
#include "providers/twitch/TwitchAccount.hpp"
#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 {
namespace controllers {
namespace accounts {
class AccountController;
}
} // namespace controllers
2018-02-05 15:11:50 +01:00
namespace providers {
2017-12-31 00:50:07 +01:00
namespace twitch {
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
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;
friend class chatterino::controllers::accounts::AccountController;
2017-12-31 00:50:07 +01:00
};
} // namespace twitch
2018-02-05 15:11:50 +01:00
} // namespace providers
} // namespace chatterino