Fix highlight mentions not updating when username changes (#6723)
Reported-by: James Upjohn <jupjohn@jammeh.co.nz> Reviewed-by: pajlada <rasmus.karlsson@pajlada.com> Reviewed-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "common/Literals.hpp"
|
||||
#include "common/network/NetworkResult.hpp"
|
||||
#include "common/QLogging.hpp"
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/api/Helix.hpp"
|
||||
#include "providers/twitch/TwitchAccount.hpp"
|
||||
@@ -50,13 +51,13 @@ QString missingScopes(const QJsonArray &scopesArray)
|
||||
return missingList;
|
||||
}
|
||||
|
||||
void checkMissingScopes(const QString &token)
|
||||
void checkMissingScopes(const std::shared_ptr<TwitchAccount> &account)
|
||||
{
|
||||
NetworkRequest(u"https://id.twitch.tv/oauth2/validate"_s,
|
||||
NetworkRequestType::Get)
|
||||
.header("Authorization", u"OAuth " % token)
|
||||
.header("Authorization", u"OAuth " % account->getOAuthToken())
|
||||
.timeout(20000)
|
||||
.onSuccess([](const auto &res) {
|
||||
.onSuccess([account](const auto &res) {
|
||||
auto *app = tryGetApp();
|
||||
if (!app)
|
||||
{
|
||||
@@ -64,6 +65,15 @@ void checkMissingScopes(const QString &token)
|
||||
}
|
||||
|
||||
const auto json = res.parseJson();
|
||||
|
||||
const auto login = json["login"_L1].toString();
|
||||
if (!login.isEmpty() &&
|
||||
login.compare(account->getUserName(), Qt::CaseInsensitive) != 0)
|
||||
{
|
||||
account->setUserName(login);
|
||||
app->getAccounts()->twitch.currentUserNameChanged.invoke();
|
||||
}
|
||||
|
||||
auto missing = missingScopes(json["scopes"_L1].toArray());
|
||||
if (missing.isEmpty())
|
||||
{
|
||||
@@ -209,7 +219,7 @@ TwitchAccountManager::TwitchAccountManager()
|
||||
currentUser->loadSeventvUserID();
|
||||
if (!currentUser->isAnon())
|
||||
{
|
||||
checkMissingScopes(currentUser->getOAuthToken());
|
||||
checkMissingScopes(currentUser);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user