Migrated Kraken's getUser to Helix (#2260)

This commit is contained in:
Paweł 2020-12-06 19:41:52 +01:00 committed by GitHub
parent 277ef4b2e3
commit cfa9e5903e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 61 deletions

View file

@ -55,6 +55,7 @@
- Bugfix: Fix a freeze caused by ignored & replaced phrases followed by Twitch Emotes (#2231)
- Bugfix: Fix a crash bug that occurred when moving splits across windows and closing the "parent tab" (#2249, #2259)
- Dev: Updated minimum required Qt framework version to 5.12. (#2210)
- Dev: Migrated `Kraken::getUser` to Helix (#2260)
## 2.2.2

View file

@ -22,6 +22,7 @@ struct HelixUser {
QString id;
QString login;
QString displayName;
QString createdAt;
QString description;
QString profileImageUrl;
int viewCount;
@ -30,6 +31,7 @@ struct HelixUser {
: id(jsonObject.value("id").toString())
, login(jsonObject.value("login").toString())
, displayName(jsonObject.value("display_name").toString())
, createdAt(jsonObject.value("created_at").toString())
, description(jsonObject.value("description").toString())
, profileImageUrl(jsonObject.value("profile_image_url").toString())
, viewCount(jsonObject.value("view_count").toInt())

View file

@ -29,26 +29,6 @@ void Kraken::getChannel(QString userId,
.execute();
}
void Kraken::getUser(QString userId, ResultCallback<KrakenUser> successCallback,
KrakenFailureCallback failureCallback)
{
assert(!userId.isEmpty());
this->makeRequest("users/" + userId, {})
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
auto root = result.parseJson();
successCallback(root);
return Success;
})
.onError([failureCallback](auto result) {
// TODO: make better xd
failureCallback();
})
.execute();
}
NetworkRequest Kraken::makeRequest(QString url, QUrlQuery urlQuery)
{
assert(!url.startsWith("/"));

View file

@ -23,17 +23,6 @@ struct KrakenChannel {
}
};
struct KrakenUser {
const QString createdAt;
const QString displayName;
KrakenUser(QJsonObject jsonObject)
: createdAt(jsonObject.value("created_at").toString())
, displayName(jsonObject.value("display_name").toString())
{
}
};
class Kraken final : boost::noncopyable
{
public:
@ -42,10 +31,6 @@ public:
ResultCallback<KrakenChannel> resultCallback,
KrakenFailureCallback failureCallback);
// https://dev.twitch.tv/docs/v5/reference/users#get-user-by-id
void getUser(QString userId, ResultCallback<KrakenUser> resultCallback,
KrakenFailureCallback failureCallback);
void update(QString clientId, QString oauthToken);
static void initialize();

View file

@ -4,15 +4,6 @@ this folder describes what sort of API requests we do, what permissions are requ
## Kraken (V5)
We use a bunch of Kraken (V5) in Chatterino2.
### Get User
URL: https://dev.twitch.tv/docs/v5/reference/users#get-user-by-id
Migration path: **Unknown**
* We implement this in `providers/twitch/api/Kraken.cpp getUser`
Used in:
* `UserInfoPopup` to get the "created at" date of a user
### Get Channel
URL: https://dev.twitch.tv/docs/v5/reference/channels#get-channel
@ -95,7 +86,7 @@ URL: https://dev.twitch.tv/docs/api/reference#get-users
* We implement this in `providers/twitch/api/Helix.cpp fetchUsers`.
Used in:
* `UserInfoPopup` to get ID and viewcount of username we clicked
* `UserInfoPopup` to get ID, viewCount, displayName, createdAt of username we clicked
* `CommandController` to power any commands that need to get a user ID
* `Toasts` to get the profile picture of a streamer who just went live
* `TwitchAccount` ignore and unignore features to translate user name to user ID

View file

@ -580,25 +580,14 @@ void UserInfoPopup::updateUserData()
this->userId_ = user.id;
this->ui_.nameLabel->setText(user.displayName);
this->setWindowTitle(TEXT_TITLE.arg(user.displayName));
this->ui_.viewCountLabel->setText(TEXT_VIEWS.arg(user.viewCount));
this->ui_.createdDateLabel->setText(
TEXT_CREATED.arg(user.createdAt.section("T", 0, 0)));
this->ui_.userIDLabel->setText(TEXT_USER_ID + user.id);
this->ui_.userIDLabel->setProperty("copy-text", user.id);
this->ui_.viewCountLabel->setText(TEXT_VIEWS.arg(user.viewCount));
getKraken()->getUser(
user.id,
[this, hack](const auto &user) {
if (!hack.lock())
{
return;
}
this->ui_.nameLabel->setText(user.displayName);
this->setWindowTitle(TEXT_TITLE.arg(user.displayName));
this->ui_.createdDateLabel->setText(
TEXT_CREATED.arg(user.createdAt.section("T", 0, 0)));
},
[] {
// failure
});
if (isInStreamerMode() &&
getSettings()->streamerModeHideUsercardAvatars)
{