Fix emotes not loading properly

This commit is contained in:
Rasmus Karlsson 2018-04-22 14:38:10 +02:00
parent 0718277271
commit 3dad7e778a
3 changed files with 23 additions and 28 deletions

View file

@ -11,22 +11,6 @@ namespace twitch {
TwitchAccountManager::TwitchAccountManager() TwitchAccountManager::TwitchAccountManager()
{ {
this->anonymousUser.reset(new TwitchAccount(ANONYMOUS_USERNAME, "", "", "")); this->anonymousUser.reset(new TwitchAccount(ANONYMOUS_USERNAME, "", "", ""));
this->currentUsername.connect([this](const auto &newValue, auto) {
QString newUsername(QString::fromStdString(newValue));
auto user = this->findUserByUsername(newUsername);
if (user) {
debug::Log("[AccountManager:currentUsernameChanged] User successfully updated to {}",
newUsername);
this->currentUser = user;
} else {
debug::Log(
"[AccountManager:currentUsernameChanged] User successfully updated to anonymous");
this->currentUser = this->anonymousUser;
}
this->userChanged.invoke();
});
} }
std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent() std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent()
@ -125,6 +109,27 @@ void TwitchAccountManager::reloadUsers()
} }
} }
void TwitchAccountManager::load()
{
this->reloadUsers();
this->currentUsername.connect([this](const auto &newValue, auto) {
QString newUsername(QString::fromStdString(newValue));
auto user = this->findUserByUsername(newUsername);
if (user) {
debug::Log("[AccountManager:currentUsernameChanged] User successfully updated to {}",
newUsername);
this->currentUser = user;
} else {
debug::Log(
"[AccountManager:currentUsernameChanged] User successfully updated to anonymous");
this->currentUser = this->anonymousUser;
}
this->userChanged.invoke();
});
}
bool TwitchAccountManager::removeUser(const QString &username) bool TwitchAccountManager::removeUser(const QString &username)
{ {
if (!this->userExists(username)) { if (!this->userExists(username)) {

View file

@ -42,6 +42,7 @@ public:
bool userExists(const QString &username) const; bool userExists(const QString &username) const;
void reloadUsers(); void reloadUsers();
void load();
bool removeUser(const QString &username); bool removeUser(const QString &username);

View file

@ -25,18 +25,7 @@ AccountManager &AccountManager::getInstance()
void AccountManager::load() void AccountManager::load()
{ {
this->Twitch.reloadUsers(); this->Twitch.load();
auto currentUser = this->Twitch.findUserByUsername(
QString::fromStdString(this->Twitch.currentUsername.getValue()));
if (currentUser) {
this->Twitch.currentUser = currentUser;
} else {
this->Twitch.currentUser = this->Twitch.anonymousUser;
}
// this->Twitch.userChanged.invoke();
} }
} // namespace singletons } // namespace singletons