2017-12-31 00:50:07 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-11-03 13:00:07 +01:00
|
|
|
#include "common/ChatterinoSetting.hpp"
|
2018-06-28 20:25:37 +02:00
|
|
|
#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 <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
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
class TwitchAccount;
|
2018-05-26 20:25:00 +02:00
|
|
|
class AccountController;
|
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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2018-06-24 15:09:56 +02:00
|
|
|
bool isLoggedIn() const;
|
|
|
|
|
2018-11-03 13:22:47 +01:00
|
|
|
pajlada::Settings::Setting<QString> 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
|
|
|
|
2018-06-28 19:38:57 +02:00
|
|
|
friend class 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 chatterino
|