diff --git a/CHANGELOG.md b/CHANGELOG.md index c8067f797..0e174a74c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/providers/twitch/api/Helix.hpp b/src/providers/twitch/api/Helix.hpp index bfe54b699..1da8c1c70 100644 --- a/src/providers/twitch/api/Helix.hpp +++ b/src/providers/twitch/api/Helix.hpp @@ -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()) diff --git a/src/providers/twitch/api/Kraken.cpp b/src/providers/twitch/api/Kraken.cpp index aed7c8c6d..edd8682dc 100644 --- a/src/providers/twitch/api/Kraken.cpp +++ b/src/providers/twitch/api/Kraken.cpp @@ -29,26 +29,6 @@ void Kraken::getChannel(QString userId, .execute(); } -void Kraken::getUser(QString userId, ResultCallback 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("/")); diff --git a/src/providers/twitch/api/Kraken.hpp b/src/providers/twitch/api/Kraken.hpp index c2996347d..0f6c7e2f9 100644 --- a/src/providers/twitch/api/Kraken.hpp +++ b/src/providers/twitch/api/Kraken.hpp @@ -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 resultCallback, KrakenFailureCallback failureCallback); - // https://dev.twitch.tv/docs/v5/reference/users#get-user-by-id - void getUser(QString userId, ResultCallback resultCallback, - KrakenFailureCallback failureCallback); - void update(QString clientId, QString oauthToken); static void initialize(); diff --git a/src/providers/twitch/api/README.md b/src/providers/twitch/api/README.md index a95ac6bcc..3ae218fe9 100644 --- a/src/providers/twitch/api/README.md +++ b/src/providers/twitch/api/README.md @@ -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 diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 4b39bdd68..0d3560daa 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -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) {