added brace wrapping after if and for
This commit is contained in:
@@ -21,7 +21,8 @@ TwitchAccountManager::TwitchAccountManager()
|
||||
|
||||
std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent()
|
||||
{
|
||||
if (!this->currentUser_) {
|
||||
if (!this->currentUser_)
|
||||
{
|
||||
return this->anonymousUser_;
|
||||
}
|
||||
|
||||
@@ -34,7 +35,8 @@ std::vector<QString> TwitchAccountManager::getUsernames() const
|
||||
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
for (const auto &user : this->accounts.getVector()) {
|
||||
for (const auto &user : this->accounts.getVector())
|
||||
{
|
||||
userNames.push_back(user->getUserName());
|
||||
}
|
||||
|
||||
@@ -46,8 +48,10 @@ std::shared_ptr<TwitchAccount> TwitchAccountManager::findUserByUsername(
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex_);
|
||||
|
||||
for (const auto &user : this->accounts.getVector()) {
|
||||
if (username.compare(user->getUserName(), Qt::CaseInsensitive) == 0) {
|
||||
for (const auto &user : this->accounts.getVector())
|
||||
{
|
||||
if (username.compare(user->getUserName(), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -68,8 +72,10 @@ void TwitchAccountManager::reloadUsers()
|
||||
|
||||
bool listUpdated = false;
|
||||
|
||||
for (const auto &uid : keys) {
|
||||
if (uid == "current") {
|
||||
for (const auto &uid : keys)
|
||||
{
|
||||
if (uid == "current")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -83,7 +89,8 @@ void TwitchAccountManager::reloadUsers()
|
||||
"/accounts/" + uid + "/oauthToken");
|
||||
|
||||
if (username.empty() || userID.empty() || clientID.empty() ||
|
||||
oauthToken.empty()) {
|
||||
oauthToken.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -92,28 +99,37 @@ void TwitchAccountManager::reloadUsers()
|
||||
userData.clientID = qS(clientID).trimmed();
|
||||
userData.oauthToken = qS(oauthToken).trimmed();
|
||||
|
||||
switch (this->addUser(userData)) {
|
||||
case AddUserResponse::UserAlreadyExists: {
|
||||
switch (this->addUser(userData))
|
||||
{
|
||||
case AddUserResponse::UserAlreadyExists:
|
||||
{
|
||||
log("User {} already exists", userData.username);
|
||||
// Do nothing
|
||||
} break;
|
||||
case AddUserResponse::UserValuesUpdated: {
|
||||
}
|
||||
break;
|
||||
case AddUserResponse::UserValuesUpdated:
|
||||
{
|
||||
log("User {} already exists, and values updated!",
|
||||
userData.username);
|
||||
if (userData.username == this->getCurrent()->getUserName()) {
|
||||
if (userData.username == this->getCurrent()->getUserName())
|
||||
{
|
||||
log("It was the current user, so we need to reconnect "
|
||||
"stuff!");
|
||||
this->currentUserChanged.invoke();
|
||||
}
|
||||
} break;
|
||||
case AddUserResponse::UserAdded: {
|
||||
}
|
||||
break;
|
||||
case AddUserResponse::UserAdded:
|
||||
{
|
||||
log("Added user {}", userData.username);
|
||||
listUpdated = true;
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (listUpdated) {
|
||||
if (listUpdated)
|
||||
{
|
||||
this->userListUpdated.invoke();
|
||||
}
|
||||
}
|
||||
@@ -125,12 +141,15 @@ void TwitchAccountManager::load()
|
||||
this->currentUsername.connect([this](const auto &newValue, auto) {
|
||||
QString newUsername(QString::fromStdString(newValue));
|
||||
auto user = this->findUserByUsername(newUsername);
|
||||
if (user) {
|
||||
if (user)
|
||||
{
|
||||
log("[AccountManager:currentUsernameChanged] User successfully "
|
||||
"updated to {}",
|
||||
newUsername);
|
||||
this->currentUser_ = user;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
log("[AccountManager:currentUsernameChanged] User successfully "
|
||||
"updated to anonymous");
|
||||
this->currentUser_ = this->anonymousUser_;
|
||||
@@ -142,7 +161,8 @@ void TwitchAccountManager::load()
|
||||
|
||||
bool TwitchAccountManager::isLoggedIn() const
|
||||
{
|
||||
if (!this->currentUser_) {
|
||||
if (!this->currentUser_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -156,12 +176,14 @@ bool TwitchAccountManager::removeUser(TwitchAccount *account)
|
||||
const auto &accs = this->accounts.getVector();
|
||||
|
||||
std::string userID(account->getUserId().toStdString());
|
||||
if (!userID.empty()) {
|
||||
if (!userID.empty())
|
||||
{
|
||||
pajlada::Settings::SettingManager::removeSetting("/accounts/uid" +
|
||||
userID);
|
||||
}
|
||||
|
||||
if (account->getUserName() == qS(this->currentUsername.getValue())) {
|
||||
if (account->getUserName() == qS(this->currentUsername.getValue()))
|
||||
{
|
||||
// The user that was removed is the current user, log into the anonymous
|
||||
// user
|
||||
this->currentUsername = "";
|
||||
@@ -176,20 +198,26 @@ TwitchAccountManager::AddUserResponse TwitchAccountManager::addUser(
|
||||
const TwitchAccountManager::UserData &userData)
|
||||
{
|
||||
auto previousUser = this->findUserByUsername(userData.username);
|
||||
if (previousUser) {
|
||||
if (previousUser)
|
||||
{
|
||||
bool userUpdated = false;
|
||||
|
||||
if (previousUser->setOAuthClient(userData.clientID)) {
|
||||
if (previousUser->setOAuthClient(userData.clientID))
|
||||
{
|
||||
userUpdated = true;
|
||||
}
|
||||
|
||||
if (previousUser->setOAuthToken(userData.oauthToken)) {
|
||||
if (previousUser->setOAuthToken(userData.oauthToken))
|
||||
{
|
||||
userUpdated = true;
|
||||
}
|
||||
|
||||
if (userUpdated) {
|
||||
if (userUpdated)
|
||||
{
|
||||
return AddUserResponse::UserValuesUpdated;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return AddUserResponse::UserAlreadyExists;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user