// SPDX-FileCopyrightText: 2017 Contributors to Chatterino // // SPDX-License-Identifier: MIT #pragma once #include "common/ChatterinoSetting.hpp" #include "common/SignalVector.hpp" #include "util/Expected.hpp" #include "util/QStringHash.hpp" #include "util/RapidJsonSerializeQString.hpp" #include #include #include #include #include // // Warning: This class is not supposed to be created directly. // Get yourself an instance from our friends over at // AccountManager.hpp // namespace chatterino { class TwitchAccount; class AccountController; extern const std::vector AUTH_SCOPES; 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 std::shared_ptr getCurrent(); std::vector getUsernames() const; std::shared_ptr findUserByUsername( const QString &username) const; bool userExists(const QString &username) const; void reloadUsers(); void load(); bool isLoggedIn() const; pajlada::Settings::Setting currentUsername{"/accounts/current", ""}; /// This signal fires after we've figured out what the new account is, but before /// any updates to Helix have been made. /// /// Useful for scenarios where you have to call Helix using the previous account. pajlada::Signals::Signal, std::shared_ptr> currentUserAboutToChange; boost::signals2::signal currentUserChanged; pajlada::Signals::NoArgSignal userListUpdated; pajlada::Signals::NoArgSignal currentUserNameChanged; SignalVector> accounts; /// The signal is invoked with (caller, error) where caller is the argument /// passed to reloadEmotes() and error. pajlada::Signals::Signal> emotesReloaded; private: enum class AddUserResponse { UserAlreadyExists, UserValuesUpdated, UserAdded, }; AddUserResponse addUser(const UserData &data); bool removeUser(TwitchAccount *account); std::shared_ptr currentUser_; std::shared_ptr anonymousUser_; mutable std::mutex mutex_; friend class AccountController; }; } // namespace chatterino