fix currentUser thing

This commit is contained in:
Rasmus Karlsson 2017-09-24 18:14:22 +02:00
parent c8c65f8f09
commit 903cf30ddf
3 changed files with 16 additions and 6 deletions

View file

@ -20,7 +20,8 @@ inline QString getEnvString(const char *target)
} // namespace
AccountManager::AccountManager()
: twitchAnonymousUser("justinfan64537", "", "")
: currentUser("/accounts/current", "")
, twitchAnonymousUser("justinfan64537", "", "")
{
}
@ -28,6 +29,8 @@ void AccountManager::load()
{
auto keys = pajlada::Settings::SettingManager::getObjectKeys("/accounts");
bool first = true;
for (const auto &uid : keys) {
if (uid == "current") {
continue;
@ -46,6 +49,11 @@ void AccountManager::load()
continue;
}
if (first) {
this->setCurrentTwitchUser(qS(username));
first = false;
}
twitch::TwitchUser user(qS(username), qS(oauthToken), qS(clientID));
this->addTwitchUser(user);
@ -67,9 +75,7 @@ twitch::TwitchUser &AccountManager::getTwitchUser()
return this->getTwitchAnon();
}
std::string currentUser = pajlada::Settings::Setting<std::string>::get("/accounts/current");
QString currentUsername = QString::fromStdString(currentUser);
QString currentUsername = QString::fromStdString(this->currentUser);
for (auto &user : this->twitchUsers) {
if (user.getUserName() == currentUsername) {
@ -82,7 +88,7 @@ twitch::TwitchUser &AccountManager::getTwitchUser()
void AccountManager::setCurrentTwitchUser(const QString &username)
{
pajlada::Settings::Setting<std::string>::set("/accounts/current", username.toStdString());
this->currentUser.setValue(username.toStdString());
}
std::vector<twitch::TwitchUser> AccountManager::getTwitchUsers()

View file

@ -2,6 +2,8 @@
#include "twitch/twitchuser.hpp"
#include <pajlada/settings/setting.hpp>
#include <mutex>
#include <vector>
@ -37,6 +39,8 @@ public:
private:
AccountManager();
pajlada::Settings::Setting<std::string> currentUser;
twitch::TwitchUser twitchAnonymousUser;
std::vector<twitch::TwitchUser> twitchUsers;
std::mutex twitchUsersMutex;

View file

@ -362,7 +362,7 @@ void TwitchMessageBuilder::parseHighlights()
{
static auto player = new QMediaPlayer;
SettingsManager &settings = SettingsManager::getInstance();
static pajlada::Settings::Setting<std::string> currentUser("/accounts/currentUser");
static pajlada::Settings::Setting<std::string> currentUser("/accounts/current");
QString currentUsername = QString::fromStdString(currentUser.getValue());