mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Migrated getChannel to Helix (#2381)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
a9b1af60de
commit
857705668e
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
|
@ -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 }}
|
||||
|
|
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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("/"));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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("/"));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue