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

View file

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

View file

@ -71,6 +71,7 @@
- Dev: Updated minimum required Qt framework version to 5.12. (#2210)
- 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 `Kraken::getChannel` to Helix. (#2381)
- Dev: Build in CI with multiple Qt versions (#2349)
## 2.2.2

View file

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

View file

@ -413,6 +413,35 @@ void Helix::createClip(QString channelId,
.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)
{
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 {
Unknown,
ClipsDisabled,
@ -218,6 +237,11 @@ public:
std::function<void(HelixClipError)> failureCallback,
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);
static void initialize();

View file

@ -8,27 +8,6 @@ namespace chatterino {
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)
{
assert(!url.startsWith("/"));

View file

@ -26,11 +26,6 @@ struct KrakenChannel {
class Kraken final : boost::noncopyable
{
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);
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 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
URL: https://dev.twitch.tv/docs/v5/reference/bits#get-cheermotes
@ -115,6 +106,13 @@ Requires `clips:edit` scope
Used in:
* `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
The TMI api is undocumented.