Migrated getChannel to Helix (#2381)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
Paweł 2021-01-21 13:48:48 +01:00 committed by GitHub
parent a9b1af60de
commit 857705668e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 54 deletions

View file

@ -43,7 +43,7 @@ jobs:
uses: jurplel/install-qt-action@v2 uses: jurplel/install-qt-action@v2
if: ${{ matrix.qt-version == 'default' }} if: ${{ matrix.qt-version == 'default' }}
with: with:
# mirror: 'http://mirrors.ocf.berkeley.edu/qt/' mirror: 'http://mirrors.ocf.berkeley.edu/qt/'
cached: ${{ steps.cache-qt.outputs.cache-hit }} cached: ${{ steps.cache-qt.outputs.cache-hit }}
extra: --external 7z extra: --external 7z
@ -51,7 +51,7 @@ jobs:
uses: jurplel/install-qt-action@v2 uses: jurplel/install-qt-action@v2
if: ${{ matrix.qt-version != 'default' }} if: ${{ matrix.qt-version != 'default' }}
with: with:
# mirror: 'http://mirrors.ocf.berkeley.edu/qt/' mirror: 'http://mirrors.ocf.berkeley.edu/qt/'
cached: ${{ steps.cache-qt.outputs.cache-hit }} cached: ${{ steps.cache-qt.outputs.cache-hit }}
extra: --external 7z extra: --external 7z
version: ${{ matrix.qt-version }} version: ${{ matrix.qt-version }}

View file

@ -35,7 +35,7 @@ jobs:
- name: Install Qt - name: Install Qt
uses: jurplel/install-qt-action@v2 uses: jurplel/install-qt-action@v2
with: with:
# mirror: 'http://mirrors.ocf.berkeley.edu/qt/' mirror: 'http://mirrors.ocf.berkeley.edu/qt/'
cached: ${{ steps.cache-qt.outputs.cache-hit }} cached: ${{ steps.cache-qt.outputs.cache-hit }}
extra: --external 7z extra: --external 7z

View file

@ -71,6 +71,7 @@
- Dev: Updated minimum required Qt framework version to 5.12. (#2210) - Dev: Updated minimum required Qt framework version to 5.12. (#2210)
- Dev: Migrated `Kraken::getUser` to Helix (#2260) - Dev: Migrated `Kraken::getUser` to Helix (#2260)
- Dev: Migrated `TwitchAccount::(un)followUser` from Kraken to Helix and moved it to `Helix::(un)followUser`. (#2306) - Dev: Migrated `TwitchAccount::(un)followUser` from Kraken to Helix and moved it to `Helix::(un)followUser`. (#2306)
- Dev: Migrated `Kraken::getChannel` to Helix. (#2381)
- Dev: Build in CI with multiple Qt versions (#2349) - Dev: Build in CI with multiple Qt versions (#2349)
## 2.2.2 ## 2.2.2

View file

@ -599,25 +599,26 @@ void TwitchChannel::refreshTitle()
} }
this->titleRefreshedTime_ = QTime::currentTime(); this->titleRefreshedTime_ = QTime::currentTime();
const auto onSuccess = [this, getHelix()->getChannel(
weak = weakOf<Channel>(this)](const auto &channel) { roomID,
ChannelPtr shared = weak.lock(); [this, weak = weakOf<Channel>(this)](HelixChannel channel) {
if (!shared) ChannelPtr shared = weak.lock();
{
return;
}
{ if (!shared)
auto status = this->streamStatus_.access(); {
status->title = channel.status; return;
} }
this->liveStatusChanged.invoke(); {
}; auto status = this->streamStatus_.access();
status->title = channel.title;
}
const auto onFailure = [] {}; this->liveStatusChanged.invoke();
},
getKraken()->getChannel(roomID, onSuccess, onFailure); [] {
// failure
});
} }
void TwitchChannel::refreshLiveStatus() void TwitchChannel::refreshLiveStatus()

View file

@ -413,6 +413,35 @@ void Helix::createClip(QString channelId,
.execute(); .execute();
} }
void Helix::getChannel(QString broadcasterId,
ResultCallback<HelixChannel> successCallback,
HelixFailureCallback failureCallback)
{
QUrlQuery urlQuery;
urlQuery.addQueryItem("broadcaster_id", broadcasterId);
this->makeRequest("channels", urlQuery)
.onSuccess([successCallback, failureCallback](auto result) -> Outcome {
auto root = result.parseJson();
auto data = root.value("data");
if (!data.isArray())
{
failureCallback();
return Failure;
}
HelixChannel channel(data.toArray()[0].toObject());
successCallback(channel);
return Success;
})
.onError([failureCallback](auto /*result*/) {
failureCallback();
})
.execute();
}
NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery) NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery)
{ {
assert(!url.startsWith("/")); assert(!url.startsWith("/"));

View file

@ -146,6 +146,25 @@ struct HelixClip {
} }
}; };
struct HelixChannel {
QString userId;
QString name;
QString language;
QString gameId;
QString gameName;
QString title;
explicit HelixChannel(QJsonObject jsonObject)
: userId(jsonObject.value("broadcaster_id").toString())
, name(jsonObject.value("broadcaster_name").toString())
, language(jsonObject.value("broadcaster_language").toString())
, gameId(jsonObject.value("game_id").toString())
, gameName(jsonObject.value("game_name").toString())
, title(jsonObject.value("title").toString())
{
}
};
enum class HelixClipError { enum class HelixClipError {
Unknown, Unknown,
ClipsDisabled, ClipsDisabled,
@ -218,6 +237,11 @@ public:
std::function<void(HelixClipError)> failureCallback, std::function<void(HelixClipError)> failureCallback,
std::function<void()> finallyCallback); std::function<void()> finallyCallback);
// https://dev.twitch.tv/docs/api/reference#get-channel-information
void getChannel(QString broadcasterId,
ResultCallback<HelixChannel> successCallback,
HelixFailureCallback failureCallback);
void update(QString clientId, QString oauthToken); void update(QString clientId, QString oauthToken);
static void initialize(); static void initialize();

View file

@ -8,27 +8,6 @@ namespace chatterino {
static Kraken *instance = nullptr; static Kraken *instance = nullptr;
void Kraken::getChannel(QString userId,
ResultCallback<KrakenChannel> successCallback,
KrakenFailureCallback failureCallback)
{
assert(!userId.isEmpty());
this->makeRequest("channels/" + 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) NetworkRequest Kraken::makeRequest(QString url, QUrlQuery urlQuery)
{ {
assert(!url.startsWith("/")); assert(!url.startsWith("/"));

View file

@ -26,11 +26,6 @@ struct KrakenChannel {
class Kraken final : boost::noncopyable class Kraken final : boost::noncopyable
{ {
public: public:
// https://dev.twitch.tv/docs/v5/reference/users#follow-channel
void getChannel(QString userId,
ResultCallback<KrakenChannel> resultCallback,
KrakenFailureCallback failureCallback);
void update(QString clientId, QString oauthToken); void update(QString clientId, QString oauthToken);
static void initialize(); 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) ## Kraken (V5)
We use a bunch of Kraken (V5) in Chatterino2. We use a bunch of Kraken (V5) in Chatterino2.
### Get Channel
URL: https://dev.twitch.tv/docs/v5/reference/channels#get-channel
Migration path: **Unknown**
* We implement this in `providers/twitch/api/Kraken.cpp getChannel`
Used in:
* `TwitchChannel::refreshTitle` to check the current stream title/game of offline channels
### Get Cheermotes ### Get Cheermotes
URL: https://dev.twitch.tv/docs/v5/reference/bits#get-cheermotes URL: https://dev.twitch.tv/docs/v5/reference/bits#get-cheermotes
@ -115,6 +106,13 @@ Requires `clips:edit` scope
Used in: Used in:
* `TwitchChannel` to create a clip of a live broadcast * `TwitchChannel` to create a clip of a live broadcast
### Get Channel
URL: https://dev.twitch.tv/docs/api/reference#get-channel-information
* We implement this in `providers/twitch/api/Helix.cpp getChannel`
Used in:
* `TwitchChannel` to refresh stream title
## TMI ## TMI
The TMI api is undocumented. The TMI api is undocumented.