mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
removed old NetworkRequest api
This commit is contained in:
parent
a7cd1fbf97
commit
7697ec01b4
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Resources2 : public Singleton {
|
class Resources2 : public Singleton
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Resources2();
|
Resources2();
|
||||||
|
|
||||||
|
|
|
@ -39,85 +39,9 @@ NetworkRequest::NetworkRequest(QUrl url, NetworkRequestType requestType)
|
||||||
|
|
||||||
NetworkRequest::~NetworkRequest()
|
NetworkRequest::~NetworkRequest()
|
||||||
{
|
{
|
||||||
//assert(this->executed_);
|
//assert(!this->data || this->executed_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// old
|
|
||||||
void NetworkRequest::type(NetworkRequestType newRequestType) &
|
|
||||||
{
|
|
||||||
this->data->requestType_ = newRequestType;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setCaller(const QObject *caller) &
|
|
||||||
{
|
|
||||||
this->data->caller_ = caller;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::onReplyCreated(NetworkReplyCreatedCallback cb) &
|
|
||||||
{
|
|
||||||
this->data->onReplyCreated_ = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::onError(NetworkErrorCallback cb) &
|
|
||||||
{
|
|
||||||
this->data->onError_ = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::onSuccess(NetworkSuccessCallback cb) &
|
|
||||||
{
|
|
||||||
this->data->onSuccess_ = cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setRawHeader(const char *headerName, const char *value) &
|
|
||||||
{
|
|
||||||
this->data->request_.setRawHeader(headerName, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setRawHeader(const char *headerName,
|
|
||||||
const QByteArray &value) &
|
|
||||||
{
|
|
||||||
this->data->request_.setRawHeader(headerName, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setRawHeader(const char *headerName,
|
|
||||||
const QString &value) &
|
|
||||||
{
|
|
||||||
this->data->request_.setRawHeader(headerName, value.toUtf8());
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setTimeout(int ms) &
|
|
||||||
{
|
|
||||||
this->data->hasTimeout_ = true;
|
|
||||||
this->data->timer_.setInterval(ms);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setExecuteConcurrently(bool value) &
|
|
||||||
{
|
|
||||||
this->data->executeConcurrently = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::makeAuthorizedV5(const QString &clientID,
|
|
||||||
const QString &oauthToken) &
|
|
||||||
{
|
|
||||||
this->setRawHeader("Client-ID", clientID);
|
|
||||||
this->setRawHeader("Accept", "application/vnd.twitchtv.v5+json");
|
|
||||||
if (!oauthToken.isEmpty())
|
|
||||||
{
|
|
||||||
this->setRawHeader("Authorization", "OAuth " + oauthToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setPayload(const QByteArray &payload) &
|
|
||||||
{
|
|
||||||
this->data->payload_ = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkRequest::setUseQuickLoadCache(bool value) &
|
|
||||||
{
|
|
||||||
this->data->useQuickLoadCache_ = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// new
|
|
||||||
NetworkRequest NetworkRequest::type(NetworkRequestType newRequestType) &&
|
NetworkRequest NetworkRequest::type(NetworkRequestType newRequestType) &&
|
||||||
{
|
{
|
||||||
this->data->requestType_ = newRequestType;
|
this->data->requestType_ = newRequestType;
|
||||||
|
|
|
@ -36,28 +36,6 @@ public:
|
||||||
|
|
||||||
~NetworkRequest();
|
~NetworkRequest();
|
||||||
|
|
||||||
// old
|
|
||||||
[[deprecated]] void type(NetworkRequestType newRequestType) &;
|
|
||||||
|
|
||||||
[[deprecated]] void onReplyCreated(NetworkReplyCreatedCallback cb) &;
|
|
||||||
[[deprecated]] void onError(NetworkErrorCallback cb) &;
|
|
||||||
[[deprecated]] void onSuccess(NetworkSuccessCallback cb) &;
|
|
||||||
|
|
||||||
[[deprecated]] void setPayload(const QByteArray &payload) &;
|
|
||||||
[[deprecated]] void setUseQuickLoadCache(bool value) &;
|
|
||||||
[[deprecated]] void setCaller(const QObject *caller) &;
|
|
||||||
[[deprecated]] void setRawHeader(const char *headerName,
|
|
||||||
const char *value) &;
|
|
||||||
[[deprecated]] void setRawHeader(const char *headerName,
|
|
||||||
const QByteArray &value) &;
|
|
||||||
[[deprecated]] void setRawHeader(const char *headerName,
|
|
||||||
const QString &value) &;
|
|
||||||
[[deprecated]] void setTimeout(int ms) &;
|
|
||||||
[[deprecated]] void setExecuteConcurrently(bool value) &;
|
|
||||||
[[deprecated]] void makeAuthorizedV5(
|
|
||||||
const QString &clientID, const QString &oauthToken = QString()) &;
|
|
||||||
|
|
||||||
// new
|
|
||||||
NetworkRequest type(NetworkRequestType newRequestType) &&;
|
NetworkRequest type(NetworkRequestType newRequestType) &&;
|
||||||
|
|
||||||
NetworkRequest onReplyCreated(NetworkReplyCreatedCallback cb) &&;
|
NetworkRequest onReplyCreated(NetworkReplyCreatedCallback cb) &&;
|
||||||
|
|
|
@ -106,8 +106,7 @@ public:
|
||||||
{
|
{
|
||||||
if (!this->emotesChecked_)
|
if (!this->emotesChecked_)
|
||||||
{
|
{
|
||||||
const auto &accvec =
|
const auto &accvec = getApp()->accounts->twitch.accounts;
|
||||||
getApp()->accounts->twitch.accounts;
|
|
||||||
for (const auto &acc : accvec)
|
for (const auto &acc : accvec)
|
||||||
{
|
{
|
||||||
const auto &accemotes = *acc->accessEmotes();
|
const auto &accemotes = *acc->accessEmotes();
|
||||||
|
|
|
@ -155,56 +155,56 @@ void NotificationController::getFakeTwitchChannelLiveStatus(
|
||||||
log("[TwitchChannel:{}] Refreshing live status", channelName);
|
log("[TwitchChannel:{}] Refreshing live status", channelName);
|
||||||
|
|
||||||
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
|
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
|
||||||
auto request = NetworkRequest::twitchRequest(url);
|
NetworkRequest::twitchRequest(url)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
|
.onSuccess([this, channelName](auto result) -> Outcome {
|
||||||
request.onSuccess([this, channelName](auto result) -> Outcome {
|
rapidjson::Document document = result.parseRapidJson();
|
||||||
rapidjson::Document document = result.parseRapidJson();
|
if (!document.IsObject())
|
||||||
if (!document.IsObject())
|
|
||||||
{
|
|
||||||
log("[TwitchChannel:refreshLiveStatus]root is not an object");
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!document.HasMember("stream"))
|
|
||||||
{
|
|
||||||
log("[TwitchChannel:refreshLiveStatus] Missing stream in root");
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto &stream = document["stream"];
|
|
||||||
|
|
||||||
if (!stream.IsObject())
|
|
||||||
{
|
|
||||||
// Stream is offline (stream is most likely null)
|
|
||||||
// removeFakeChannel(channelName);
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
// Stream is live
|
|
||||||
auto i = std::find(fakeTwitchChannels.begin(),
|
|
||||||
fakeTwitchChannels.end(), channelName);
|
|
||||||
|
|
||||||
if (!(i != fakeTwitchChannels.end()))
|
|
||||||
{
|
|
||||||
fakeTwitchChannels.push_back(channelName);
|
|
||||||
if (Toasts::isEnabled())
|
|
||||||
{
|
{
|
||||||
getApp()->toasts->sendChannelNotification(channelName,
|
log("[TwitchChannel:refreshLiveStatus]root is not an "
|
||||||
Platform::Twitch);
|
"object");
|
||||||
|
return Failure;
|
||||||
}
|
}
|
||||||
if (getSettings()->notificationPlaySound)
|
|
||||||
{
|
|
||||||
getApp()->notifications->playSound();
|
|
||||||
}
|
|
||||||
if (getSettings()->notificationFlashTaskbar)
|
|
||||||
{
|
|
||||||
getApp()->windows->sendAlert();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
if (!document.HasMember("stream"))
|
||||||
|
{
|
||||||
|
log("[TwitchChannel:refreshLiveStatus] Missing stream in "
|
||||||
|
"root");
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &stream = document["stream"];
|
||||||
|
|
||||||
|
if (!stream.IsObject())
|
||||||
|
{
|
||||||
|
// Stream is offline (stream is most likely null)
|
||||||
|
// removeFakeChannel(channelName);
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
// Stream is live
|
||||||
|
auto i = std::find(fakeTwitchChannels.begin(),
|
||||||
|
fakeTwitchChannels.end(), channelName);
|
||||||
|
|
||||||
|
if (!(i != fakeTwitchChannels.end()))
|
||||||
|
{
|
||||||
|
fakeTwitchChannels.push_back(channelName);
|
||||||
|
if (Toasts::isEnabled())
|
||||||
|
{
|
||||||
|
getApp()->toasts->sendChannelNotification(
|
||||||
|
channelName, Platform::Twitch);
|
||||||
|
}
|
||||||
|
if (getSettings()->notificationPlaySound)
|
||||||
|
{
|
||||||
|
getApp()->notifications->playSound();
|
||||||
|
}
|
||||||
|
if (getSettings()->notificationFlashTaskbar)
|
||||||
|
{
|
||||||
|
getApp()->windows->sendAlert();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,40 +20,38 @@ void LinkResolver::getLinkInfo(
|
||||||
}
|
}
|
||||||
// Uncomment to test crashes
|
// Uncomment to test crashes
|
||||||
// QTimer::singleShot(3000, [=]() {
|
// QTimer::singleShot(3000, [=]() {
|
||||||
NetworkRequest request(Env::get().linkResolverUrl.arg(
|
NetworkRequest(Env::get().linkResolverUrl.arg(QString::fromUtf8(
|
||||||
QString::fromUtf8(QUrl::toPercentEncoding(url, "", "/:"))));
|
QUrl::toPercentEncoding(url, "", "/:"))))
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
request.setTimeout(30000);
|
.timeout(30000)
|
||||||
request.onSuccess([successCallback, url](auto result) mutable -> Outcome {
|
.onSuccess([successCallback, url](auto result) mutable -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
auto statusCode = root.value("status").toInt();
|
auto statusCode = root.value("status").toInt();
|
||||||
QString response = QString();
|
QString response = QString();
|
||||||
QString linkString = url;
|
QString linkString = url;
|
||||||
if (statusCode == 200)
|
if (statusCode == 200)
|
||||||
{
|
|
||||||
response = root.value("tooltip").toString();
|
|
||||||
if (getSettings()->unshortLinks)
|
|
||||||
{
|
{
|
||||||
linkString = root.value("link").toString();
|
response = root.value("tooltip").toString();
|
||||||
|
if (getSettings()->unshortLinks)
|
||||||
|
{
|
||||||
|
linkString = root.value("link").toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
response = root.value("message").toString();
|
||||||
response = root.value("message").toString();
|
}
|
||||||
}
|
successCallback(QUrl::fromPercentEncoding(response.toUtf8()),
|
||||||
successCallback(QUrl::fromPercentEncoding(response.toUtf8()),
|
Link(Link::Url, linkString));
|
||||||
Link(Link::Url, linkString));
|
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.onError([successCallback, url](auto /*result*/) {
|
||||||
|
successCallback("No link info found", Link(Link::Url, url));
|
||||||
|
|
||||||
request.onError([successCallback, url](auto result) {
|
return true;
|
||||||
successCallback("No link info found", Link(Link::Url, url));
|
})
|
||||||
|
.execute();
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,42 +112,36 @@ boost::optional<EmotePtr> BttvEmotes::emote(const EmoteName &name) const
|
||||||
|
|
||||||
void BttvEmotes::loadEmotes()
|
void BttvEmotes::loadEmotes()
|
||||||
{
|
{
|
||||||
auto request = NetworkRequest(QString(globalEmoteApiUrl));
|
NetworkRequest(QString(globalEmoteApiUrl))
|
||||||
|
.caller(QThread::currentThread())
|
||||||
request.setCaller(QThread::currentThread());
|
.timeout(30000)
|
||||||
request.setTimeout(30000);
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
|
auto emotes = this->global_.get();
|
||||||
request.onSuccess([this](auto result) -> Outcome {
|
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
||||||
auto emotes = this->global_.get();
|
if (pair.first)
|
||||||
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
this->global_.set(
|
||||||
if (pair.first)
|
std::make_shared<EmoteMap>(std::move(pair.second)));
|
||||||
this->global_.set(
|
return pair.first;
|
||||||
std::make_shared<EmoteMap>(std::move(pair.second)));
|
})
|
||||||
return pair.first;
|
.execute();
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BttvEmotes::loadChannel(const QString &channelName,
|
void BttvEmotes::loadChannel(const QString &channelName,
|
||||||
std::function<void(EmoteMap &&)> callback)
|
std::function<void(EmoteMap &&)> callback)
|
||||||
{
|
{
|
||||||
auto request =
|
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName)
|
||||||
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelName);
|
.caller(QThread::currentThread())
|
||||||
|
.timeout(3000)
|
||||||
request.setCaller(QThread::currentThread());
|
.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
||||||
request.setTimeout(3000);
|
auto pair = parseChannelEmotes(result.parseJson());
|
||||||
|
if (pair.first)
|
||||||
request.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
callback(std::move(pair.second));
|
||||||
auto pair = parseChannelEmotes(result.parseJson());
|
return pair.first;
|
||||||
if (pair.first)
|
})
|
||||||
callback(std::move(pair.second));
|
.execute();
|
||||||
return pair.first;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||||
const QString &emoteScale)
|
const QString &emoteScale)
|
||||||
{
|
{
|
||||||
|
@ -156,5 +150,6 @@ static Url getEmoteLink(QString urlTemplate, const EmoteId &id,
|
||||||
return {urlTemplate.replace("{{id}}", id.string)
|
return {urlTemplate.replace("{{id}}", id.string)
|
||||||
.replace("{{image}}", emoteScale)};
|
.replace("{{image}}", emoteScale)};
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -36,32 +36,32 @@ void ChatterinoBadges::loadChatterinoBadges()
|
||||||
{
|
{
|
||||||
static QUrl url("https://fourtf.com/chatterino/badges.json");
|
static QUrl url("https://fourtf.com/chatterino/badges.json");
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
req.onSuccess([this](auto result) -> Outcome {
|
auto jsonRoot = result.parseJson();
|
||||||
auto jsonRoot = result.parseJson();
|
int index = 0;
|
||||||
int index = 0;
|
for (const auto &jsonBadge_ : jsonRoot.value("badges").toArray())
|
||||||
for (const auto &jsonBadge_ : jsonRoot.value("badges").toArray())
|
|
||||||
{
|
|
||||||
auto jsonBadge = jsonBadge_.toObject();
|
|
||||||
auto emote = Emote{
|
|
||||||
EmoteName{}, ImageSet{Url{jsonBadge.value("image").toString()}},
|
|
||||||
Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
|
|
||||||
|
|
||||||
emotes.push_back(std::make_shared<const Emote>(std::move(emote)));
|
|
||||||
|
|
||||||
for (const auto &user : jsonBadge.value("users").toArray())
|
|
||||||
{
|
{
|
||||||
badgeMap[user.toString()] = index;
|
auto jsonBadge = jsonBadge_.toObject();
|
||||||
|
auto emote = Emote{
|
||||||
|
EmoteName{},
|
||||||
|
ImageSet{Url{jsonBadge.value("image").toString()}},
|
||||||
|
Tooltip{jsonBadge.value("tooltip").toString()}, Url{}};
|
||||||
|
|
||||||
|
emotes.push_back(
|
||||||
|
std::make_shared<const Emote>(std::move(emote)));
|
||||||
|
|
||||||
|
for (const auto &user : jsonBadge.value("users").toArray())
|
||||||
|
{
|
||||||
|
badgeMap[user.toString()] = index;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -137,20 +137,18 @@ void FfzEmotes::loadEmotes()
|
||||||
{
|
{
|
||||||
QString url("https://api.frankerfacez.com/v1/set/global");
|
QString url("https://api.frankerfacez.com/v1/set/global");
|
||||||
|
|
||||||
NetworkRequest request(url);
|
NetworkRequest(url)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
request.setTimeout(30000);
|
.timeout(30000)
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
request.onSuccess([this](auto result) -> Outcome {
|
auto emotes = this->emotes();
|
||||||
auto emotes = this->emotes();
|
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
||||||
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
if (pair.first)
|
||||||
if (pair.first)
|
this->global_.set(
|
||||||
this->global_.set(
|
std::make_shared<EmoteMap>(std::move(pair.second)));
|
||||||
std::make_shared<EmoteMap>(std::move(pair.second)));
|
return pair.first;
|
||||||
return pair.first;
|
})
|
||||||
});
|
.execute();
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FfzEmotes::loadChannel(const QString &channelName,
|
void FfzEmotes::loadChannel(const QString &channelName,
|
||||||
|
@ -158,40 +156,36 @@ void FfzEmotes::loadChannel(const QString &channelName,
|
||||||
{
|
{
|
||||||
log("[FFZEmotes] Reload FFZ Channel Emotes for channel {}\n", channelName);
|
log("[FFZEmotes] Reload FFZ Channel Emotes for channel {}\n", channelName);
|
||||||
|
|
||||||
NetworkRequest request("https://api.frankerfacez.com/v1/room/" +
|
NetworkRequest("https://api.frankerfacez.com/v1/room/" + channelName)
|
||||||
channelName);
|
.caller(QThread::currentThread())
|
||||||
request.setCaller(QThread::currentThread());
|
.timeout(20000)
|
||||||
request.setTimeout(20000);
|
.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
||||||
|
auto pair = parseChannelEmotes(result.parseJson());
|
||||||
|
if (pair.first)
|
||||||
|
callback(std::move(pair.second));
|
||||||
|
return pair.first;
|
||||||
|
})
|
||||||
|
.onError([channelName](int result) {
|
||||||
|
if (result == 203)
|
||||||
|
{
|
||||||
|
// User does not have any FFZ emotes
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
request.onSuccess([callback = std::move(callback)](auto result) -> Outcome {
|
if (result == -2)
|
||||||
auto pair = parseChannelEmotes(result.parseJson());
|
{
|
||||||
if (pair.first)
|
// TODO: Auto retry in case of a timeout, with a delay
|
||||||
callback(std::move(pair.second));
|
log("Fetching FFZ emotes for channel {} failed due to timeout",
|
||||||
return pair.first;
|
channelName);
|
||||||
});
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
log("Error fetching FFZ emotes for channel {}, error {}",
|
||||||
|
channelName, result);
|
||||||
|
|
||||||
request.onError([channelName](int result) {
|
|
||||||
if (result == 203)
|
|
||||||
{
|
|
||||||
// User does not have any FFZ emotes
|
|
||||||
return true;
|
return true;
|
||||||
}
|
})
|
||||||
|
.execute();
|
||||||
if (result == -2)
|
|
||||||
{
|
|
||||||
// TODO: Auto retry in case of a timeout, with a delay
|
|
||||||
log("Fetching FFZ emotes for channel {} failed due to timeout",
|
|
||||||
channelName);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
log("Error fetching FFZ emotes for channel {}, error {}", channelName,
|
|
||||||
result);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -22,38 +22,37 @@ void FfzModBadge::loadCustomModBadge()
|
||||||
static QString partialUrl("https://cdn.frankerfacez.com/room-badge/mod/");
|
static QString partialUrl("https://cdn.frankerfacez.com/room-badge/mod/");
|
||||||
|
|
||||||
QString url = partialUrl + channelName_ + "/1";
|
QString url = partialUrl + channelName_ + "/1";
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
req.onSuccess([this, url](auto result) -> Outcome {
|
.onSuccess([this, url](auto result) -> Outcome {
|
||||||
auto data = result.getData();
|
auto data = result.getData();
|
||||||
|
|
||||||
QBuffer buffer(const_cast<QByteArray *>(&data));
|
QBuffer buffer(const_cast<QByteArray *>(&data));
|
||||||
buffer.open(QIODevice::ReadOnly);
|
buffer.open(QIODevice::ReadOnly);
|
||||||
QImageReader reader(&buffer);
|
QImageReader reader(&buffer);
|
||||||
if (reader.imageCount() == 0)
|
if (reader.imageCount() == 0)
|
||||||
return Failure;
|
return Failure;
|
||||||
|
|
||||||
QPixmap badgeOverlay = QPixmap::fromImageReader(&reader);
|
QPixmap badgeOverlay = QPixmap::fromImageReader(&reader);
|
||||||
QPixmap badgePixmap(18, 18);
|
QPixmap badgePixmap(18, 18);
|
||||||
|
|
||||||
// the default mod badge green color
|
// the default mod badge green color
|
||||||
badgePixmap.fill(QColor("#34AE0A"));
|
badgePixmap.fill(QColor("#34AE0A"));
|
||||||
QPainter painter(&badgePixmap);
|
QPainter painter(&badgePixmap);
|
||||||
QRectF rect(0, 0, 18, 18);
|
QRectF rect(0, 0, 18, 18);
|
||||||
painter.drawPixmap(rect, badgeOverlay, rect);
|
painter.drawPixmap(rect, badgeOverlay, rect);
|
||||||
|
|
||||||
auto emote = Emote{{""},
|
auto emote = Emote{{""},
|
||||||
ImageSet{Image::fromPixmap(badgePixmap)},
|
ImageSet{Image::fromPixmap(badgePixmap)},
|
||||||
Tooltip{"Twitch Channel Moderator"},
|
Tooltip{"Twitch Channel Moderator"},
|
||||||
Url{url}};
|
Url{url}};
|
||||||
|
|
||||||
this->badge_ = std::make_shared<Emote>(emote);
|
this->badge_ = std::make_shared<Emote>(emote);
|
||||||
// getBadge.execute();
|
// getBadge.execute();
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EmotePtr FfzModBadge::badge() const
|
EmotePtr FfzModBadge::badge() const
|
||||||
|
|
|
@ -36,45 +36,46 @@ void PartialTwitchUser::getId(std::function<void(QString)> successCallback,
|
||||||
caller = QThread::currentThread();
|
caller = QThread::currentThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest request("https://api.twitch.tv/kraken/users?login=" +
|
NetworkRequest("https://api.twitch.tv/kraken/users?login=" +
|
||||||
this->username_);
|
this->username_)
|
||||||
request.setCaller(caller);
|
.caller(caller)
|
||||||
request.makeAuthorizedV5(getDefaultClientID());
|
.authorizeTwitchV5(getDefaultClientID())
|
||||||
|
.onSuccess([successCallback](auto result) -> Outcome {
|
||||||
|
auto root = result.parseJson();
|
||||||
|
if (!root.value("users").isArray())
|
||||||
|
{
|
||||||
|
log("API Error while getting user id, users is not an array");
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
request.onSuccess([successCallback](auto result) -> Outcome {
|
auto users = root.value("users").toArray();
|
||||||
auto root = result.parseJson();
|
if (users.size() != 1)
|
||||||
if (!root.value("users").isArray())
|
{
|
||||||
{
|
log("API Error while getting user id, users array size is not "
|
||||||
log("API Error while getting user id, users is not an array");
|
"1");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
|
if (!users[0].isObject())
|
||||||
|
{
|
||||||
|
log("API Error while getting user id, first user is not an "
|
||||||
|
"object");
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
auto firstUser = users[0].toObject();
|
||||||
|
auto id = firstUser.value("_id");
|
||||||
|
if (!id.isString())
|
||||||
|
{
|
||||||
|
log("API Error: while getting user id, first user object `_id` "
|
||||||
|
"key "
|
||||||
|
"is not a "
|
||||||
|
"string");
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
successCallback(id.toString());
|
||||||
|
|
||||||
auto users = root.value("users").toArray();
|
return Success;
|
||||||
if (users.size() != 1)
|
})
|
||||||
{
|
.execute();
|
||||||
log("API Error while getting user id, users array size is not 1");
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
if (!users[0].isObject())
|
|
||||||
{
|
|
||||||
log("API Error while getting user id, first user is not an object");
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
auto firstUser = users[0].toObject();
|
|
||||||
auto id = firstUser.value("_id");
|
|
||||||
if (!id.isString())
|
|
||||||
{
|
|
||||||
log("API Error: while getting user id, first user object `_id` key "
|
|
||||||
"is not a "
|
|
||||||
"string");
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
successCallback(id.toString());
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -94,59 +94,58 @@ void TwitchAccount::loadIgnores()
|
||||||
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/blocks");
|
"/blocks");
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
req.onSuccess([=](auto result) -> Outcome {
|
.onSuccess([=](auto result) -> Outcome {
|
||||||
auto document = result.parseRapidJson();
|
auto document = result.parseRapidJson();
|
||||||
if (!document.IsObject())
|
if (!document.IsObject())
|
||||||
{
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto blocksIt = document.FindMember("blocks");
|
|
||||||
if (blocksIt == document.MemberEnd())
|
|
||||||
{
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
const auto &blocks = blocksIt->value;
|
|
||||||
|
|
||||||
if (!blocks.IsArray())
|
|
||||||
{
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
|
|
||||||
this->ignores_.clear();
|
|
||||||
|
|
||||||
for (const auto &block : blocks.GetArray())
|
|
||||||
{
|
{
|
||||||
if (!block.IsObject())
|
return Failure;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto userIt = block.FindMember("user");
|
|
||||||
if (userIt == block.MemberEnd())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TwitchUser ignoredUser;
|
|
||||||
if (!rj::getSafe(userIt->value, ignoredUser))
|
|
||||||
{
|
|
||||||
log("Error parsing twitch user JSON {}",
|
|
||||||
rj::stringify(userIt->value));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->ignores_.insert(ignoredUser);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Success;
|
auto blocksIt = document.FindMember("blocks");
|
||||||
});
|
if (blocksIt == document.MemberEnd())
|
||||||
|
{
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
const auto &blocks = blocksIt->value;
|
||||||
|
|
||||||
req.execute();
|
if (!blocks.IsArray())
|
||||||
|
{
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
|
||||||
|
this->ignores_.clear();
|
||||||
|
|
||||||
|
for (const auto &block : blocks.GetArray())
|
||||||
|
{
|
||||||
|
if (!block.IsObject())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto userIt = block.FindMember("user");
|
||||||
|
if (userIt == block.MemberEnd())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
TwitchUser ignoredUser;
|
||||||
|
if (!rj::getSafe(userIt->value, ignoredUser))
|
||||||
|
{
|
||||||
|
log("Error parsing twitch user JSON {}",
|
||||||
|
rj::stringify(userIt->value));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->ignores_.insert(ignoredUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::ignore(
|
void TwitchAccount::ignore(
|
||||||
|
@ -167,64 +166,63 @@ void TwitchAccount::ignoreByID(
|
||||||
{
|
{
|
||||||
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/blocks/" + targetUserID);
|
"/blocks/" + targetUserID);
|
||||||
NetworkRequest req(url, NetworkRequestType::Put);
|
|
||||||
req.setCaller(QThread::currentThread());
|
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
|
||||||
|
|
||||||
req.onError([=](int errorCode) {
|
NetworkRequest(url, NetworkRequestType::Put)
|
||||||
onFinished(IgnoreResult_Failed,
|
.caller(QThread::currentThread())
|
||||||
"An unknown error occured while trying to ignore user " +
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
targetName + " (" + QString::number(errorCode) + ")");
|
.onError([=](int errorCode) {
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.onSuccess([=](auto result) -> Outcome {
|
|
||||||
auto document = result.parseRapidJson();
|
|
||||||
if (!document.IsObject())
|
|
||||||
{
|
|
||||||
onFinished(IgnoreResult_Failed,
|
onFinished(IgnoreResult_Failed,
|
||||||
"Bad JSON data while ignoring user " + targetName);
|
"An unknown error occured while trying to ignore user " +
|
||||||
return Failure;
|
targetName + " (" + QString::number(errorCode) +
|
||||||
}
|
")");
|
||||||
|
|
||||||
auto userIt = document.FindMember("user");
|
return true;
|
||||||
if (userIt == document.MemberEnd())
|
})
|
||||||
{
|
.onSuccess([=](auto result) -> Outcome {
|
||||||
onFinished(IgnoreResult_Failed,
|
auto document = result.parseRapidJson();
|
||||||
"Bad JSON data while ignoring user (missing user) " +
|
if (!document.IsObject())
|
||||||
targetName);
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
TwitchUser ignoredUser;
|
|
||||||
if (!rj::getSafe(userIt->value, ignoredUser))
|
|
||||||
{
|
|
||||||
onFinished(IgnoreResult_Failed,
|
|
||||||
"Bad JSON data while ignoring user (invalid user) " +
|
|
||||||
targetName);
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
|
|
||||||
|
|
||||||
auto res = this->ignores_.insert(ignoredUser);
|
|
||||||
if (!res.second)
|
|
||||||
{
|
{
|
||||||
const TwitchUser &existingUser = *(res.first);
|
onFinished(IgnoreResult_Failed,
|
||||||
existingUser.update(ignoredUser);
|
"Bad JSON data while ignoring user " + targetName);
|
||||||
onFinished(IgnoreResult_AlreadyIgnored,
|
|
||||||
"User " + targetName + " is already ignored");
|
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
onFinished(IgnoreResult_Success,
|
|
||||||
"Successfully ignored user " + targetName);
|
|
||||||
|
|
||||||
return Success;
|
auto userIt = document.FindMember("user");
|
||||||
});
|
if (userIt == document.MemberEnd())
|
||||||
|
{
|
||||||
|
onFinished(IgnoreResult_Failed,
|
||||||
|
"Bad JSON data while ignoring user (missing user) " +
|
||||||
|
targetName);
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
req.execute();
|
TwitchUser ignoredUser;
|
||||||
|
if (!rj::getSafe(userIt->value, ignoredUser))
|
||||||
|
{
|
||||||
|
onFinished(IgnoreResult_Failed,
|
||||||
|
"Bad JSON data while ignoring user (invalid user) " +
|
||||||
|
targetName);
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
|
||||||
|
|
||||||
|
auto res = this->ignores_.insert(ignoredUser);
|
||||||
|
if (!res.second)
|
||||||
|
{
|
||||||
|
const TwitchUser &existingUser = *(res.first);
|
||||||
|
existingUser.update(ignoredUser);
|
||||||
|
onFinished(IgnoreResult_AlreadyIgnored,
|
||||||
|
"User " + targetName + " is already ignored");
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onFinished(IgnoreResult_Success,
|
||||||
|
"Successfully ignored user " + targetName);
|
||||||
|
|
||||||
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::unignore(
|
void TwitchAccount::unignore(
|
||||||
|
@ -246,34 +244,32 @@ void TwitchAccount::unignoreByID(
|
||||||
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/blocks/" + targetUserID);
|
"/blocks/" + targetUserID);
|
||||||
|
|
||||||
NetworkRequest req(url, NetworkRequestType::Delete);
|
NetworkRequest(url, NetworkRequestType::Delete)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
|
.onError([=](int errorCode) {
|
||||||
|
onFinished(
|
||||||
|
UnignoreResult_Failed,
|
||||||
|
"An unknown error occured while trying to unignore user " +
|
||||||
|
targetName + " (" + QString::number(errorCode) + ")");
|
||||||
|
|
||||||
req.onError([=](int errorCode) {
|
return true;
|
||||||
onFinished(UnignoreResult_Failed,
|
})
|
||||||
"An unknown error occured while trying to unignore user " +
|
.onSuccess([=](auto result) -> Outcome {
|
||||||
targetName + " (" + QString::number(errorCode) + ")");
|
auto document = result.parseRapidJson();
|
||||||
|
TwitchUser ignoredUser;
|
||||||
|
ignoredUser.id = targetUserID;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
|
||||||
|
|
||||||
return true;
|
this->ignores_.erase(ignoredUser);
|
||||||
});
|
}
|
||||||
|
onFinished(UnignoreResult_Success,
|
||||||
|
"Successfully unignored user " + targetName);
|
||||||
|
|
||||||
req.onSuccess([=](auto result) -> Outcome {
|
return Success;
|
||||||
auto document = result.parseRapidJson();
|
})
|
||||||
TwitchUser ignoredUser;
|
.execute();
|
||||||
ignoredUser.id = targetUserID;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(this->ignoresMutex_);
|
|
||||||
|
|
||||||
this->ignores_.erase(ignoredUser);
|
|
||||||
}
|
|
||||||
onFinished(UnignoreResult_Success,
|
|
||||||
"Successfully unignored user " + targetName);
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::checkFollow(const QString targetUserID,
|
void TwitchAccount::checkFollow(const QString targetUserID,
|
||||||
|
@ -282,30 +278,27 @@ void TwitchAccount::checkFollow(const QString targetUserID,
|
||||||
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/follows/channels/" + targetUserID);
|
"/follows/channels/" + targetUserID);
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
|
.onError([=](int errorCode) {
|
||||||
|
if (errorCode == 203)
|
||||||
|
{
|
||||||
|
onFinished(FollowResult_NotFollowing);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
onFinished(FollowResult_Failed);
|
||||||
|
}
|
||||||
|
|
||||||
req.onError([=](int errorCode) {
|
return true;
|
||||||
if (errorCode == 203)
|
})
|
||||||
{
|
.onSuccess([=](auto result) -> Outcome {
|
||||||
onFinished(FollowResult_NotFollowing);
|
auto document = result.parseRapidJson();
|
||||||
}
|
onFinished(FollowResult_Following);
|
||||||
else
|
return Success;
|
||||||
{
|
})
|
||||||
onFinished(FollowResult_Failed);
|
.execute();
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.onSuccess([=](auto result) -> Outcome {
|
|
||||||
auto document = result.parseRapidJson();
|
|
||||||
onFinished(FollowResult_Following);
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::followUser(const QString userID,
|
void TwitchAccount::followUser(const QString userID,
|
||||||
|
@ -314,19 +307,16 @@ void TwitchAccount::followUser(const QString userID,
|
||||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/follows/channels/" + userID);
|
"/follows/channels/" + userID);
|
||||||
|
|
||||||
NetworkRequest request(requestUrl, NetworkRequestType::Put);
|
NetworkRequest(requestUrl, NetworkRequestType::Put)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
|
.onSuccess([successCallback](auto result) -> Outcome {
|
||||||
|
// TODO: Properly check result of follow request
|
||||||
|
successCallback();
|
||||||
|
|
||||||
request.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
return Success;
|
||||||
|
})
|
||||||
// TODO: Properly check result of follow request
|
.execute();
|
||||||
request.onSuccess([successCallback](auto result) -> Outcome {
|
|
||||||
successCallback();
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::unfollowUser(const QString userID,
|
void TwitchAccount::unfollowUser(const QString userID,
|
||||||
|
@ -335,27 +325,23 @@ void TwitchAccount::unfollowUser(const QString userID,
|
||||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QUrl requestUrl("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/follows/channels/" + userID);
|
"/follows/channels/" + userID);
|
||||||
|
|
||||||
NetworkRequest request(requestUrl, NetworkRequestType::Delete);
|
NetworkRequest(requestUrl, NetworkRequestType::Delete)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
|
.onError([successCallback](int code) {
|
||||||
|
if (code >= 200 && code <= 299)
|
||||||
|
{
|
||||||
|
successCallback();
|
||||||
|
}
|
||||||
|
|
||||||
request.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
return true;
|
||||||
|
})
|
||||||
request.onError([successCallback](int code) {
|
.onSuccess([successCallback](const auto &document) -> Outcome {
|
||||||
if (code >= 200 && code <= 299)
|
|
||||||
{
|
|
||||||
successCallback();
|
successCallback();
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
request.onSuccess([successCallback](const auto &document) -> Outcome {
|
|
||||||
successCallback();
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<TwitchUser> TwitchAccount::getIgnores() const
|
std::set<TwitchUser> TwitchAccount::getIgnores() const
|
||||||
|
@ -381,31 +367,28 @@ void TwitchAccount::loadEmotes()
|
||||||
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
QString url("https://api.twitch.tv/kraken/users/" + this->getUserId() +
|
||||||
"/emotes");
|
"/emotes");
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
|
.onError([=](int errorCode) {
|
||||||
|
log("[TwitchAccount::loadEmotes] Error {}", errorCode);
|
||||||
|
if (errorCode == 203)
|
||||||
|
{
|
||||||
|
// onFinished(FollowResult_NotFollowing);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// onFinished(FollowResult_Failed);
|
||||||
|
}
|
||||||
|
|
||||||
req.onError([=](int errorCode) {
|
return true;
|
||||||
log("[TwitchAccount::loadEmotes] Error {}", errorCode);
|
})
|
||||||
if (errorCode == 203)
|
.onSuccess([=](auto result) -> Outcome {
|
||||||
{
|
this->parseEmotes(result.parseRapidJson());
|
||||||
// onFinished(FollowResult_NotFollowing);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// onFinished(FollowResult_Failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
req.onSuccess([=](auto result) -> Outcome {
|
|
||||||
this->parseEmotes(result.parseRapidJson());
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessGuard<const TwitchAccount::TwitchAccountEmoteData>
|
AccessGuard<const TwitchAccount::TwitchAccountEmoteData>
|
||||||
|
@ -419,44 +402,40 @@ void TwitchAccount::autoModAllow(const QString msgID)
|
||||||
{
|
{
|
||||||
QString url("https://api.twitch.tv/kraken/chat/twitchbot/approve");
|
QString url("https://api.twitch.tv/kraken/chat/twitchbot/approve");
|
||||||
|
|
||||||
NetworkRequest req(url, NetworkRequestType::Post);
|
|
||||||
req.setRawHeader("Content-Type", "application/json");
|
|
||||||
|
|
||||||
auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8();
|
auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8();
|
||||||
qDebug() << qba;
|
qDebug() << qba;
|
||||||
|
|
||||||
req.setRawHeader("Content-Length", QByteArray::number(qba.size()));
|
NetworkRequest(url, NetworkRequestType::Post)
|
||||||
req.setPayload(qba);
|
.header("Content-Type", "application/json")
|
||||||
req.setCaller(QThread::currentThread());
|
.header("Content-Length", QByteArray::number(qba.size()))
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
.payload(qba)
|
||||||
|
.caller(QThread::currentThread())
|
||||||
req.onError([=](int errorCode) {
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
log("[TwitchAccounts::autoModAllow] Error {}", errorCode);
|
.onError([=](int errorCode) {
|
||||||
return true;
|
log("[TwitchAccounts::autoModAllow] Error {}", errorCode);
|
||||||
});
|
return true;
|
||||||
|
})
|
||||||
req.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::autoModDeny(const QString msgID)
|
void TwitchAccount::autoModDeny(const QString msgID)
|
||||||
{
|
{
|
||||||
QString url("https://api.twitch.tv/kraken/chat/twitchbot/deny");
|
QString url("https://api.twitch.tv/kraken/chat/twitchbot/deny");
|
||||||
|
|
||||||
NetworkRequest req(url, NetworkRequestType::Post);
|
|
||||||
req.setRawHeader("Content-Type", "application/json");
|
|
||||||
auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8();
|
auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8();
|
||||||
qDebug() << qba;
|
qDebug() << qba;
|
||||||
|
|
||||||
req.setRawHeader("Content-Length", QByteArray::number(qba.size()));
|
NetworkRequest(url, NetworkRequestType::Post)
|
||||||
req.setPayload(qba);
|
.header("Content-Type", "application/json")
|
||||||
req.setCaller(QThread::currentThread());
|
.header("Content-Length", QByteArray::number(qba.size()))
|
||||||
req.makeAuthorizedV5(this->getOAuthClient(), this->getOAuthToken());
|
.payload(qba)
|
||||||
|
.caller(QThread::currentThread())
|
||||||
req.onError([=](int errorCode) {
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
||||||
log("[TwitchAccounts::autoModDeny] Error {}", errorCode);
|
.onError([=](int errorCode) {
|
||||||
return true;
|
log("[TwitchAccounts::autoModDeny] Error {}", errorCode);
|
||||||
});
|
return true;
|
||||||
req.execute();
|
})
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
||||||
|
@ -535,49 +514,46 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest req(Env::get().twitchEmoteSetResolverUrl.arg(emoteSet->key));
|
NetworkRequest(Env::get().twitchEmoteSetResolverUrl.arg(emoteSet->key))
|
||||||
req.setUseQuickLoadCache(true);
|
.cache()
|
||||||
|
.onError([](int errorCode) -> bool {
|
||||||
|
log("Error code {} while loading emote set data", errorCode);
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.onSuccess([emoteSet](auto result) -> Outcome {
|
||||||
|
auto root = result.parseRapidJson();
|
||||||
|
if (!root.IsObject())
|
||||||
|
{
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
req.onError([](int errorCode) -> bool {
|
std::string emoteSetID;
|
||||||
log("Error code {} while loading emote set data", errorCode);
|
QString channelName;
|
||||||
return true;
|
QString type;
|
||||||
});
|
if (!rj::getSafe(root, "channel_name", channelName))
|
||||||
|
{
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
req.onSuccess([emoteSet](auto result) -> Outcome {
|
if (!rj::getSafe(root, "type", type))
|
||||||
auto root = result.parseRapidJson();
|
{
|
||||||
if (!root.IsObject())
|
return Failure;
|
||||||
{
|
}
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string emoteSetID;
|
log("Loaded twitch emote set data for {}!", emoteSet->key);
|
||||||
QString channelName;
|
|
||||||
QString type;
|
|
||||||
if (!rj::getSafe(root, "channel_name", channelName))
|
|
||||||
{
|
|
||||||
return Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rj::getSafe(root, "type", type))
|
auto name = channelName;
|
||||||
{
|
name.detach();
|
||||||
return Failure;
|
name[0] = name[0].toUpper();
|
||||||
}
|
|
||||||
|
|
||||||
log("Loaded twitch emote set data for {}!", emoteSet->key);
|
emoteSet->text = name;
|
||||||
|
|
||||||
auto name = channelName;
|
emoteSet->type = type;
|
||||||
name.detach();
|
emoteSet->channelName = channelName;
|
||||||
name[0] = name[0].toUpper();
|
|
||||||
|
|
||||||
emoteSet->text = name;
|
return Success;
|
||||||
|
})
|
||||||
emoteSet->type = type;
|
.execute();
|
||||||
emoteSet->channelName = channelName;
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -15,46 +15,48 @@ void TwitchApi::findUserId(const QString user,
|
||||||
{
|
{
|
||||||
QString requestUrl("https://api.twitch.tv/kraken/users?login=" + user);
|
QString requestUrl("https://api.twitch.tv/kraken/users?login=" + user);
|
||||||
|
|
||||||
NetworkRequest request(requestUrl);
|
NetworkRequest(requestUrl)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
request.makeAuthorizedV5(getDefaultClientID());
|
.authorizeTwitchV5(getDefaultClientID())
|
||||||
request.setTimeout(30000);
|
.timeout(30000)
|
||||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
if (!root.value("users").isArray())
|
if (!root.value("users").isArray())
|
||||||
{
|
{
|
||||||
log("API Error while getting user id, users is not an array");
|
log("API Error while getting user id, users is not an array");
|
||||||
successCallback("");
|
successCallback("");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
auto users = root.value("users").toArray();
|
auto users = root.value("users").toArray();
|
||||||
if (users.size() != 1)
|
if (users.size() != 1)
|
||||||
{
|
{
|
||||||
log("API Error while getting user id, users array size is not 1");
|
log("API Error while getting user id, users array size is not "
|
||||||
successCallback("");
|
"1");
|
||||||
return Failure;
|
successCallback("");
|
||||||
}
|
return Failure;
|
||||||
if (!users[0].isObject())
|
}
|
||||||
{
|
if (!users[0].isObject())
|
||||||
log("API Error while getting user id, first user is not an object");
|
{
|
||||||
successCallback("");
|
log("API Error while getting user id, first user is not an "
|
||||||
return Failure;
|
"object");
|
||||||
}
|
successCallback("");
|
||||||
auto firstUser = users[0].toObject();
|
return Failure;
|
||||||
auto id = firstUser.value("_id");
|
}
|
||||||
if (!id.isString())
|
auto firstUser = users[0].toObject();
|
||||||
{
|
auto id = firstUser.value("_id");
|
||||||
log("API Error: while getting user id, first user object `_id` key "
|
if (!id.isString())
|
||||||
"is not a "
|
{
|
||||||
"string");
|
log("API Error: while getting user id, first user object `_id` "
|
||||||
successCallback("");
|
"key "
|
||||||
return Failure;
|
"is not a "
|
||||||
}
|
"string");
|
||||||
successCallback(id.toString());
|
successCallback("");
|
||||||
return Success;
|
return Failure;
|
||||||
});
|
}
|
||||||
|
successCallback(id.toString());
|
||||||
request.execute();
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchApi::findUserName(const QString userid,
|
void TwitchApi::findUserName(const QString userid,
|
||||||
|
@ -62,24 +64,24 @@ void TwitchApi::findUserName(const QString userid,
|
||||||
{
|
{
|
||||||
QString requestUrl("https://api.twitch.tv/kraken/users/" + userid);
|
QString requestUrl("https://api.twitch.tv/kraken/users/" + userid);
|
||||||
|
|
||||||
NetworkRequest request(requestUrl);
|
NetworkRequest(requestUrl)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
request.makeAuthorizedV5(getDefaultClientID());
|
.authorizeTwitchV5(getDefaultClientID())
|
||||||
request.setTimeout(30000);
|
.timeout(30000)
|
||||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
auto name = root.value("name");
|
auto name = root.value("name");
|
||||||
if (!name.isString())
|
if (!name.isString())
|
||||||
{
|
{
|
||||||
log("API Error: while getting user name, `name` is not a string");
|
log("API Error: while getting user name, `name` is not a "
|
||||||
successCallback("");
|
"string");
|
||||||
return Failure;
|
successCallback("");
|
||||||
}
|
return Failure;
|
||||||
successCallback(name.toString());
|
}
|
||||||
return Success;
|
successCallback(name.toString());
|
||||||
});
|
return Success;
|
||||||
|
})
|
||||||
request.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -17,45 +17,49 @@ void TwitchBadges::loadTwitchBadges()
|
||||||
static QString url(
|
static QString url(
|
||||||
"https://badges.twitch.tv/v1/badges/global/display?language=en");
|
"https://badges.twitch.tv/v1/badges/global/display?language=en");
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
req.onSuccess([this](auto result) -> Outcome {
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
auto badgeSets = this->badgeSets_.access();
|
auto badgeSets = this->badgeSets_.access();
|
||||||
|
|
||||||
auto jsonSets = root.value("badge_sets").toObject();
|
auto jsonSets = root.value("badge_sets").toObject();
|
||||||
for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt)
|
for (auto sIt = jsonSets.begin(); sIt != jsonSets.end(); ++sIt)
|
||||||
{
|
|
||||||
auto key = sIt.key();
|
|
||||||
auto versions = sIt.value().toObject().value("versions").toObject();
|
|
||||||
|
|
||||||
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt)
|
|
||||||
{
|
{
|
||||||
auto versionObj = vIt.value().toObject();
|
auto key = sIt.key();
|
||||||
|
auto versions =
|
||||||
|
sIt.value().toObject().value("versions").toObject();
|
||||||
|
|
||||||
auto emote = Emote{
|
for (auto vIt = versions.begin(); vIt != versions.end(); ++vIt)
|
||||||
{""},
|
{
|
||||||
ImageSet{
|
auto versionObj = vIt.value().toObject();
|
||||||
Image::fromUrl(
|
|
||||||
{versionObj.value("image_url_1x").toString()}, 1),
|
|
||||||
Image::fromUrl(
|
|
||||||
{versionObj.value("image_url_2x").toString()}, .5),
|
|
||||||
Image::fromUrl(
|
|
||||||
{versionObj.value("image_url_4x").toString()}, .25),
|
|
||||||
},
|
|
||||||
Tooltip{versionObj.value("description").toString()},
|
|
||||||
Url{versionObj.value("click_url").toString()}};
|
|
||||||
// "title"
|
|
||||||
// "clickAction"
|
|
||||||
|
|
||||||
(*badgeSets)[key][vIt.key()] = std::make_shared<Emote>(emote);
|
auto emote = Emote{
|
||||||
|
{""},
|
||||||
|
ImageSet{
|
||||||
|
Image::fromUrl(
|
||||||
|
{versionObj.value("image_url_1x").toString()},
|
||||||
|
1),
|
||||||
|
Image::fromUrl(
|
||||||
|
{versionObj.value("image_url_2x").toString()},
|
||||||
|
.5),
|
||||||
|
Image::fromUrl(
|
||||||
|
{versionObj.value("image_url_4x").toString()},
|
||||||
|
.25),
|
||||||
|
},
|
||||||
|
Tooltip{versionObj.value("description").toString()},
|
||||||
|
Url{versionObj.value("click_url").toString()}};
|
||||||
|
// "title"
|
||||||
|
// "clickAction"
|
||||||
|
|
||||||
|
(*badgeSets)[key][vIt.key()] =
|
||||||
|
std::make_shared<Emote>(emote);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set,
|
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set,
|
||||||
|
|
|
@ -501,19 +501,17 @@ void TwitchChannel::refreshLiveStatus()
|
||||||
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
|
QString url("https://api.twitch.tv/kraken/streams/" + roomID);
|
||||||
|
|
||||||
// auto request = makeGetStreamRequest(roomID, QThread::currentThread());
|
// auto request = makeGetStreamRequest(roomID, QThread::currentThread());
|
||||||
auto request = NetworkRequest::twitchRequest(url);
|
NetworkRequest::twitchRequest(url)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
|
.onSuccess(
|
||||||
|
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||||
|
ChannelPtr shared = weak.lock();
|
||||||
|
if (!shared)
|
||||||
|
return Failure;
|
||||||
|
|
||||||
request.onSuccess(
|
return this->parseLiveStatus(result.parseRapidJson());
|
||||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
})
|
||||||
ChannelPtr shared = weak.lock();
|
.execute();
|
||||||
if (!shared)
|
|
||||||
return Failure;
|
|
||||||
|
|
||||||
return this->parseLiveStatus(result.parseRapidJson());
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
|
||||||
|
@ -608,42 +606,38 @@ void TwitchChannel::loadRecentMessages()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest request(
|
NetworkRequest(Env::get().recentMessagesApiUrl.arg(this->getName()))
|
||||||
Env::get().recentMessagesApiUrl.arg(this->getName()));
|
.caller(QThread::currentThread())
|
||||||
request.setCaller(QThread::currentThread());
|
.concurrent()
|
||||||
// can't be concurrent right now due to SignalVector
|
.onSuccess([weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||||
request.setExecuteConcurrently(true);
|
auto shared = weak.lock();
|
||||||
|
if (!shared)
|
||||||
|
return Failure;
|
||||||
|
|
||||||
request.onSuccess([weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
auto messages = parseRecentMessages(result.parseJson(), shared);
|
||||||
auto shared = weak.lock();
|
|
||||||
if (!shared)
|
|
||||||
return Failure;
|
|
||||||
|
|
||||||
auto messages = parseRecentMessages(result.parseJson(), shared);
|
auto &handler = IrcMessageHandler::getInstance();
|
||||||
|
|
||||||
auto &handler = IrcMessageHandler::getInstance();
|
std::vector<MessagePtr> allBuiltMessages;
|
||||||
|
|
||||||
std::vector<MessagePtr> allBuiltMessages;
|
for (auto message : messages)
|
||||||
|
|
||||||
for (auto message : messages)
|
|
||||||
{
|
|
||||||
for (auto builtMessage :
|
|
||||||
handler.parseMessage(shared.get(), message))
|
|
||||||
{
|
{
|
||||||
builtMessage->flags.set(MessageFlag::RecentMessage);
|
for (auto builtMessage :
|
||||||
allBuiltMessages.emplace_back(builtMessage);
|
handler.parseMessage(shared.get(), message))
|
||||||
|
{
|
||||||
|
builtMessage->flags.set(MessageFlag::RecentMessage);
|
||||||
|
allBuiltMessages.emplace_back(builtMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
postToThread(
|
postToThread(
|
||||||
[shared, messages = std::move(allBuiltMessages)]() mutable {
|
[shared, messages = std::move(allBuiltMessages)]() mutable {
|
||||||
shared->addMessagesAtStart(messages);
|
shared->addMessagesAtStart(messages);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchChannel::refreshPubsub()
|
void TwitchChannel::refreshPubsub()
|
||||||
|
@ -675,76 +669,73 @@ void TwitchChannel::refreshChatters()
|
||||||
}
|
}
|
||||||
|
|
||||||
// get viewer list
|
// get viewer list
|
||||||
NetworkRequest request("https://tmi.twitch.tv/group/user/" +
|
NetworkRequest("https://tmi.twitch.tv/group/user/" + this->getName() +
|
||||||
this->getName() + "/chatters");
|
"/chatters")
|
||||||
|
.caller(QThread::currentThread())
|
||||||
|
.onSuccess(
|
||||||
|
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||||
|
// channel still exists?
|
||||||
|
auto shared = weak.lock();
|
||||||
|
if (!shared)
|
||||||
|
return Failure;
|
||||||
|
|
||||||
request.setCaller(QThread::currentThread());
|
auto pair = parseChatters(result.parseJson());
|
||||||
request.onSuccess(
|
if (pair.first)
|
||||||
[this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
{
|
||||||
// channel still exists?
|
*this->chatters_.access() = std::move(pair.second);
|
||||||
auto shared = weak.lock();
|
}
|
||||||
if (!shared)
|
|
||||||
return Failure;
|
|
||||||
|
|
||||||
auto pair = parseChatters(result.parseJson());
|
return pair.first;
|
||||||
if (pair.first)
|
})
|
||||||
{
|
.execute();
|
||||||
*this->chatters_.access() = std::move(pair.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pair.first;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchChannel::refreshBadges()
|
void TwitchChannel::refreshBadges()
|
||||||
{
|
{
|
||||||
auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" +
|
auto url = Url{"https://badges.twitch.tv/v1/badges/channels/" +
|
||||||
this->roomId() + "/display?language=en"};
|
this->roomId() + "/display?language=en"};
|
||||||
NetworkRequest req(url.string);
|
NetworkRequest(url.string)
|
||||||
req.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
|
.onSuccess([this,
|
||||||
|
weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
||||||
|
auto shared = weak.lock();
|
||||||
|
if (!shared)
|
||||||
|
return Failure;
|
||||||
|
|
||||||
req.onSuccess([this, weak = weakOf<Channel>(this)](auto result) -> Outcome {
|
auto badgeSets = this->badgeSets_.access();
|
||||||
auto shared = weak.lock();
|
|
||||||
if (!shared)
|
|
||||||
return Failure;
|
|
||||||
|
|
||||||
auto badgeSets = this->badgeSets_.access();
|
auto jsonRoot = result.parseJson();
|
||||||
|
|
||||||
auto jsonRoot = result.parseJson();
|
auto _ = jsonRoot["badge_sets"].toObject();
|
||||||
|
for (auto jsonBadgeSet = _.begin(); jsonBadgeSet != _.end();
|
||||||
auto _ = jsonRoot["badge_sets"].toObject();
|
jsonBadgeSet++)
|
||||||
for (auto jsonBadgeSet = _.begin(); jsonBadgeSet != _.end();
|
|
||||||
jsonBadgeSet++)
|
|
||||||
{
|
|
||||||
auto &versions = (*badgeSets)[jsonBadgeSet.key()];
|
|
||||||
|
|
||||||
auto _set = jsonBadgeSet->toObject()["versions"].toObject();
|
|
||||||
for (auto jsonVersion_ = _set.begin(); jsonVersion_ != _set.end();
|
|
||||||
jsonVersion_++)
|
|
||||||
{
|
{
|
||||||
auto jsonVersion = jsonVersion_->toObject();
|
auto &versions = (*badgeSets)[jsonBadgeSet.key()];
|
||||||
auto emote = std::make_shared<Emote>(Emote{
|
|
||||||
EmoteName{},
|
|
||||||
ImageSet{
|
|
||||||
Image::fromUrl({jsonVersion["image_url_1x"].toString()},
|
|
||||||
1),
|
|
||||||
Image::fromUrl({jsonVersion["image_url_2x"].toString()},
|
|
||||||
.5),
|
|
||||||
Image::fromUrl({jsonVersion["image_url_4x"].toString()},
|
|
||||||
.25)},
|
|
||||||
Tooltip{jsonVersion["description"].toString()},
|
|
||||||
Url{jsonVersion["clickURL"].toString()}});
|
|
||||||
|
|
||||||
versions.emplace(jsonVersion_.key(), emote);
|
auto _set = jsonBadgeSet->toObject()["versions"].toObject();
|
||||||
};
|
for (auto jsonVersion_ = _set.begin();
|
||||||
}
|
jsonVersion_ != _set.end(); jsonVersion_++)
|
||||||
|
{
|
||||||
|
auto jsonVersion = jsonVersion_->toObject();
|
||||||
|
auto emote = std::make_shared<Emote>(Emote{
|
||||||
|
EmoteName{},
|
||||||
|
ImageSet{
|
||||||
|
Image::fromUrl(
|
||||||
|
{jsonVersion["image_url_1x"].toString()}, 1),
|
||||||
|
Image::fromUrl(
|
||||||
|
{jsonVersion["image_url_2x"].toString()}, .5),
|
||||||
|
Image::fromUrl(
|
||||||
|
{jsonVersion["image_url_4x"].toString()}, .25)},
|
||||||
|
Tooltip{jsonVersion["description"].toString()},
|
||||||
|
Url{jsonVersion["clickURL"].toString()}});
|
||||||
|
|
||||||
return Success;
|
versions.emplace(jsonVersion_.key(), emote);
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
req.execute();
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchChannel::refreshCheerEmotes()
|
void TwitchChannel::refreshCheerEmotes()
|
||||||
|
|
|
@ -42,8 +42,8 @@ public:
|
||||||
BoolSetting hideModerated = {"/appearance/messages/hideModerated", false};
|
BoolSetting hideModerated = {"/appearance/messages/hideModerated", false};
|
||||||
BoolSetting hideModerationActions = {
|
BoolSetting hideModerationActions = {
|
||||||
"/appearance/messages/hideModerationActions", false};
|
"/appearance/messages/hideModerationActions", false};
|
||||||
BoolSetting colorizeNicknames = {
|
BoolSetting colorizeNicknames = {"/appearance/messages/colorizeNicknames",
|
||||||
"/appearance/messages/colorizeNicknames", false};
|
false};
|
||||||
|
|
||||||
// BoolSetting collapseLongMessages =
|
// BoolSetting collapseLongMessages =
|
||||||
// {"/appearance/messages/collapseLongMessages", false};
|
// {"/appearance/messages/collapseLongMessages", false};
|
||||||
|
@ -99,7 +99,8 @@ public:
|
||||||
"/behaviour/autocompletion/onlyFetchChattersForSmallerStreamers", true};
|
"/behaviour/autocompletion/onlyFetchChattersForSmallerStreamers", true};
|
||||||
IntSetting smallStreamerLimit = {
|
IntSetting smallStreamerLimit = {
|
||||||
"/behaviour/autocompletion/smallStreamerLimit", 1000};
|
"/behaviour/autocompletion/smallStreamerLimit", 1000};
|
||||||
BoolSetting prefixOnlyEmoteCompletion = {"/behaviour/autocompletion/prefixOnlyCompletion", true};
|
BoolSetting prefixOnlyEmoteCompletion = {
|
||||||
|
"/behaviour/autocompletion/prefixOnlyCompletion", true};
|
||||||
|
|
||||||
BoolSetting pauseChatOnHover = {"/behaviour/pauseChatHover", false};
|
BoolSetting pauseChatOnHover = {"/behaviour/pauseChatHover", false};
|
||||||
BoolSetting autorun = {"/behaviour/autorun", false};
|
BoolSetting autorun = {"/behaviour/autorun", false};
|
||||||
|
|
|
@ -213,48 +213,47 @@ void Toasts::fetchChannelAvatar(const QString channelName,
|
||||||
QString requestUrl("https://api.twitch.tv/kraken/users?login=" +
|
QString requestUrl("https://api.twitch.tv/kraken/users?login=" +
|
||||||
channelName);
|
channelName);
|
||||||
|
|
||||||
NetworkRequest request(requestUrl);
|
NetworkRequest(requestUrl)
|
||||||
request.setCaller(QThread::currentThread());
|
.caller(QThread::currentThread())
|
||||||
request.makeAuthorizedV5(getDefaultClientID());
|
.authorizeTwitchV5(getDefaultClientID())
|
||||||
request.setTimeout(30000);
|
.timeout(30000)
|
||||||
request.onSuccess([successCallback](auto result) mutable -> Outcome {
|
.onSuccess([successCallback](auto result) mutable -> Outcome {
|
||||||
auto root = result.parseJson();
|
auto root = result.parseJson();
|
||||||
if (!root.value("users").isArray())
|
if (!root.value("users").isArray())
|
||||||
{
|
{
|
||||||
// log("API Error while getting user id, users is not an array");
|
// log("API Error while getting user id, users is not an array");
|
||||||
successCallback("");
|
successCallback("");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
auto users = root.value("users").toArray();
|
auto users = root.value("users").toArray();
|
||||||
if (users.size() != 1)
|
if (users.size() != 1)
|
||||||
{
|
{
|
||||||
// log("API Error while getting user id, users array size is not
|
// log("API Error while getting user id, users array size is not
|
||||||
// 1");
|
// 1");
|
||||||
successCallback("");
|
successCallback("");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
if (!users[0].isObject())
|
if (!users[0].isObject())
|
||||||
{
|
{
|
||||||
// log("API Error while getting user id, first user is not an
|
// log("API Error while getting user id, first user is not an
|
||||||
// object");
|
// object");
|
||||||
successCallback("");
|
successCallback("");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
auto firstUser = users[0].toObject();
|
auto firstUser = users[0].toObject();
|
||||||
auto avatar = firstUser.value("logo");
|
auto avatar = firstUser.value("logo");
|
||||||
if (!avatar.isString())
|
if (!avatar.isString())
|
||||||
{
|
{
|
||||||
// log("API Error: while getting user avatar, first user object "
|
// log("API Error: while getting user avatar, first user object "
|
||||||
// "`avatar` key "
|
// "`avatar` key "
|
||||||
// "is not a "
|
// "is not a "
|
||||||
// "string");
|
// "string");
|
||||||
successCallback("");
|
successCallback("");
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
successCallback(avatar.toString());
|
successCallback(avatar.toString());
|
||||||
return Success;
|
return Success;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
request.execute();
|
|
||||||
}
|
}
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -73,47 +73,46 @@ void Updates::installUpdates()
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
box->show();
|
box->show();
|
||||||
|
|
||||||
NetworkRequest req(this->updatePortable_);
|
NetworkRequest(this->updatePortable_)
|
||||||
req.setTimeout(600000);
|
.timeout(600000)
|
||||||
req.onError([this](int) -> bool {
|
.onError([this](int) -> bool {
|
||||||
this->setStatus_(DownloadFailed);
|
this->setStatus_(DownloadFailed);
|
||||||
|
|
||||||
postToThread([] {
|
postToThread([] {
|
||||||
QMessageBox *box = new QMessageBox(
|
QMessageBox *box = new QMessageBox(
|
||||||
QMessageBox::Information, "Chatterino Update",
|
QMessageBox::Information, "Chatterino Update",
|
||||||
"Failed while trying to download the update.");
|
"Failed while trying to download the update.");
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
box->show();
|
box->show();
|
||||||
box->raise();
|
box->raise();
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
})
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
|
QByteArray object = result.getData();
|
||||||
|
auto filename =
|
||||||
|
combinePath(getPaths()->miscDirectory, "update.zip");
|
||||||
|
|
||||||
req.onSuccess([this](auto result) -> Outcome {
|
QFile file(filename);
|
||||||
QByteArray object = result.getData();
|
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||||
auto filename =
|
|
||||||
combinePath(getPaths()->miscDirectory, "update.zip");
|
|
||||||
|
|
||||||
QFile file(filename);
|
if (file.write(object) == -1)
|
||||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
{
|
||||||
|
this->setStatus_(WriteFileFailed);
|
||||||
|
return Failure;
|
||||||
|
}
|
||||||
|
|
||||||
if (file.write(object) == -1)
|
QProcess::startDetached(
|
||||||
{
|
combinePath(QCoreApplication::applicationDirPath(),
|
||||||
this->setStatus_(WriteFileFailed);
|
"updater.1/ChatterinoUpdater.exe"),
|
||||||
return Failure;
|
{filename, "restart"});
|
||||||
}
|
|
||||||
|
|
||||||
QProcess::startDetached(
|
QApplication::exit(0);
|
||||||
combinePath(QCoreApplication::applicationDirPath(),
|
return Success;
|
||||||
"updater.1/ChatterinoUpdater.exe"),
|
})
|
||||||
{filename, "restart"});
|
.execute();
|
||||||
|
|
||||||
QApplication::exit(0);
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
this->setStatus_(Downloading);
|
this->setStatus_(Downloading);
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -125,67 +124,67 @@ void Updates::installUpdates()
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
box->show();
|
box->show();
|
||||||
|
|
||||||
NetworkRequest req(this->updateExe_);
|
NetworkRequest(this->updateExe_)
|
||||||
req.setTimeout(600000);
|
.timeout(600000)
|
||||||
req.onError([this](int) -> bool {
|
.onError([this](int) -> bool {
|
||||||
this->setStatus_(DownloadFailed);
|
this->setStatus_(DownloadFailed);
|
||||||
|
|
||||||
QMessageBox *box = new QMessageBox(
|
|
||||||
QMessageBox::Information, "Chatterino Update",
|
|
||||||
"Failed to download the update. \n\nTry manually "
|
|
||||||
"downloading the update.");
|
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
box->exec();
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.onSuccess([this](auto result) -> Outcome {
|
|
||||||
QByteArray object = result.getData();
|
|
||||||
auto filename =
|
|
||||||
combinePath(getPaths()->miscDirectory, "Update.exe");
|
|
||||||
|
|
||||||
QFile file(filename);
|
|
||||||
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
|
||||||
|
|
||||||
if (file.write(object) == -1)
|
|
||||||
{
|
|
||||||
this->setStatus_(WriteFileFailed);
|
|
||||||
QMessageBox *box = new QMessageBox(
|
QMessageBox *box = new QMessageBox(
|
||||||
QMessageBox::Information, "Chatterino Update",
|
QMessageBox::Information, "Chatterino Update",
|
||||||
"Failed to save the update file. This could be due to "
|
"Failed to download the update. \n\nTry manually "
|
||||||
"window settings or antivirus software.\n\nTry manually "
|
|
||||||
"downloading the update.");
|
"downloading the update.");
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
box->exec();
|
box->exec();
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
|
QByteArray object = result.getData();
|
||||||
|
auto filename =
|
||||||
|
combinePath(getPaths()->miscDirectory, "Update.exe");
|
||||||
|
|
||||||
QDesktopServices::openUrl(this->updateExe_);
|
QFile file(filename);
|
||||||
return Failure;
|
file.open(QIODevice::Truncate | QIODevice::WriteOnly);
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
if (QProcess::startDetached(filename))
|
if (file.write(object) == -1)
|
||||||
{
|
{
|
||||||
QApplication::exit(0);
|
this->setStatus_(WriteFileFailed);
|
||||||
}
|
QMessageBox *box = new QMessageBox(
|
||||||
else
|
QMessageBox::Information, "Chatterino Update",
|
||||||
{
|
"Failed to save the update file. This could be due to "
|
||||||
QMessageBox *box = new QMessageBox(
|
"window settings or antivirus software.\n\nTry "
|
||||||
QMessageBox::Information, "Chatterino Update",
|
"manually "
|
||||||
"Failed to execute update binary. This could be due to "
|
"downloading the update.");
|
||||||
"window "
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
"settings or antivirus software.\n\nTry manually "
|
box->exec();
|
||||||
"downloading "
|
|
||||||
"the update.");
|
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
box->exec();
|
|
||||||
|
|
||||||
QDesktopServices::openUrl(this->updateExe_);
|
QDesktopServices::openUrl(this->updateExe_);
|
||||||
}
|
return Failure;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
|
||||||
return Success;
|
if (QProcess::startDetached(filename))
|
||||||
});
|
{
|
||||||
|
QApplication::exit(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox *box = new QMessageBox(
|
||||||
|
QMessageBox::Information, "Chatterino Update",
|
||||||
|
"Failed to execute update binary. This could be due to "
|
||||||
|
"window "
|
||||||
|
"settings or antivirus software.\n\nTry manually "
|
||||||
|
"downloading "
|
||||||
|
"the update.");
|
||||||
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
box->exec();
|
||||||
|
|
||||||
|
QDesktopServices::openUrl(this->updateExe_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
this->setStatus_(Downloading);
|
this->setStatus_(Downloading);
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -196,67 +195,67 @@ void Updates::checkForUpdates()
|
||||||
"https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS
|
"https://notitia.chatterino.com/version/chatterino/" CHATTERINO_OS
|
||||||
"/stable";
|
"/stable";
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setTimeout(60000);
|
.timeout(60000)
|
||||||
req.onSuccess([this](auto result) -> Outcome {
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
auto object = result.parseJson();
|
auto object = result.parseJson();
|
||||||
/// Version available on every platform
|
/// Version available on every platform
|
||||||
QJsonValue version_val = object.value("version");
|
QJsonValue version_val = object.value("version");
|
||||||
|
|
||||||
if (!version_val.isString())
|
if (!version_val.isString())
|
||||||
{
|
{
|
||||||
this->setStatus_(SearchFailed);
|
this->setStatus_(SearchFailed);
|
||||||
qDebug() << "error updating";
|
qDebug() << "error updating";
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined Q_OS_WIN || defined Q_OS_MACOS
|
#if defined Q_OS_WIN || defined Q_OS_MACOS
|
||||||
/// Windows downloads an installer for the new version
|
/// Windows downloads an installer for the new version
|
||||||
QJsonValue updateExe_val = object.value("updateexe");
|
QJsonValue updateExe_val = object.value("updateexe");
|
||||||
if (!updateExe_val.isString())
|
if (!updateExe_val.isString())
|
||||||
{
|
{
|
||||||
this->setStatus_(SearchFailed);
|
this->setStatus_(SearchFailed);
|
||||||
qDebug() << "error updating";
|
qDebug() << "error updating";
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
this->updateExe_ = updateExe_val.toString();
|
this->updateExe_ = updateExe_val.toString();
|
||||||
|
|
||||||
/// Windows portable
|
/// Windows portable
|
||||||
QJsonValue portable_val = object.value("portable_download");
|
QJsonValue portable_val = object.value("portable_download");
|
||||||
if (!portable_val.isString())
|
if (!portable_val.isString())
|
||||||
{
|
{
|
||||||
this->setStatus_(SearchFailed);
|
this->setStatus_(SearchFailed);
|
||||||
qDebug() << "error updating";
|
qDebug() << "error updating";
|
||||||
return Failure;
|
return Failure;
|
||||||
}
|
}
|
||||||
this->updatePortable_ = portable_val.toString();
|
this->updatePortable_ = portable_val.toString();
|
||||||
|
|
||||||
#elif defined Q_OS_LINUX
|
#elif defined Q_OS_LINUX
|
||||||
QJsonValue updateGuide_val = object.value("updateguide");
|
QJsonValue updateGuide_val = object.value("updateguide");
|
||||||
if (updateGuide_val.isString())
|
if (updateGuide_val.isString())
|
||||||
{
|
{
|
||||||
this->updateGuideLink_ = updateGuide_val.toString();
|
this->updateGuideLink_ = updateGuide_val.toString();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return Failure;
|
return Failure;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Current version
|
/// Current version
|
||||||
this->onlineVersion_ = version_val.toString();
|
this->onlineVersion_ = version_val.toString();
|
||||||
|
|
||||||
/// Update available :)
|
/// Update available :)
|
||||||
if (this->currentVersion_ != this->onlineVersion_)
|
if (this->currentVersion_ != this->onlineVersion_)
|
||||||
{
|
{
|
||||||
this->setStatus_(UpdateAvailable);
|
this->setStatus_(UpdateAvailable);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->setStatus_(NoUpdateAvailable);
|
this->setStatus_(NoUpdateAvailable);
|
||||||
}
|
}
|
||||||
return Failure;
|
return Failure;
|
||||||
});
|
})
|
||||||
|
.execute();
|
||||||
this->setStatus_(Searching);
|
this->setStatus_(Searching);
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Updates::Status Updates::getStatus() const
|
Updates::Status Updates::getStatus() const
|
||||||
|
|
|
@ -91,45 +91,43 @@ void LogsPopup::getLogviewerLogs(const QString &roomID)
|
||||||
auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500")
|
auto url = QString("https://cbenni.com/api/logs/%1/?nick=%2&before=500")
|
||||||
.arg(this->channelName_, this->userName_);
|
.arg(this->channelName_, this->userName_);
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(this);
|
.caller(this)
|
||||||
|
.onError([this](int errorCode) {
|
||||||
|
this->getOverrustleLogs();
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.onSuccess([this, roomID](auto result) -> Outcome {
|
||||||
|
auto data = result.parseJson();
|
||||||
|
std::vector<MessagePtr> messages;
|
||||||
|
|
||||||
req.onError([this](int errorCode) {
|
QJsonValue before = data.value("before");
|
||||||
this->getOverrustleLogs();
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.onSuccess([this, roomID](auto result) -> Outcome {
|
for (auto i : before.toArray())
|
||||||
auto data = result.parseJson();
|
{
|
||||||
std::vector<MessagePtr> messages;
|
auto messageObject = i.toObject();
|
||||||
|
QString message = messageObject.value("text").toString();
|
||||||
|
|
||||||
QJsonValue before = data.value("before");
|
// Hacky way to fix the timestamp
|
||||||
|
message.insert(1, "historical=1;");
|
||||||
|
message.insert(1, QString("tmi-sent-ts=%10000;")
|
||||||
|
.arg(messageObject["time"].toInt()));
|
||||||
|
message.insert(1, QString("room-id=%1;").arg(roomID));
|
||||||
|
|
||||||
for (auto i : before.toArray())
|
MessageParseArgs args;
|
||||||
{
|
auto ircMessage =
|
||||||
auto messageObject = i.toObject();
|
Communi::IrcMessage::fromData(message.toUtf8(), nullptr);
|
||||||
QString message = messageObject.value("text").toString();
|
auto privMsg =
|
||||||
|
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
||||||
|
TwitchMessageBuilder builder(this->channel_.get(), privMsg,
|
||||||
|
args);
|
||||||
|
messages.push_back(builder.build());
|
||||||
|
}
|
||||||
|
this->setMessages(messages);
|
||||||
|
|
||||||
// Hacky way to fix the timestamp
|
return Success;
|
||||||
message.insert(1, "historical=1;");
|
})
|
||||||
message.insert(1, QString("tmi-sent-ts=%10000;")
|
.execute();
|
||||||
.arg(messageObject["time"].toInt()));
|
|
||||||
message.insert(1, QString("room-id=%1;").arg(roomID));
|
|
||||||
|
|
||||||
MessageParseArgs args;
|
|
||||||
auto ircMessage =
|
|
||||||
Communi::IrcMessage::fromData(message.toUtf8(), nullptr);
|
|
||||||
auto privMsg =
|
|
||||||
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
|
||||||
TwitchMessageBuilder builder(this->channel_.get(), privMsg, args);
|
|
||||||
messages.push_back(builder.build());
|
|
||||||
}
|
|
||||||
this->setMessages(messages);
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsPopup::getOverrustleLogs()
|
void LogsPopup::getOverrustleLogs()
|
||||||
|
@ -138,57 +136,56 @@ void LogsPopup::getOverrustleLogs()
|
||||||
QString("https://overrustlelogs.net/api/v1/stalk/%1/%2.json?limit=500")
|
QString("https://overrustlelogs.net/api/v1/stalk/%1/%2.json?limit=500")
|
||||||
.arg(this->channelName_, this->userName_);
|
.arg(this->channelName_, this->userName_);
|
||||||
|
|
||||||
NetworkRequest req(url);
|
NetworkRequest(url)
|
||||||
req.setCaller(this);
|
.caller(this)
|
||||||
req.onError([this](int errorCode) {
|
.onError([this](int errorCode) {
|
||||||
auto box = new QMessageBox(
|
auto box = new QMessageBox(
|
||||||
QMessageBox::Information, "Error getting logs",
|
QMessageBox::Information, "Error getting logs",
|
||||||
"No logs could be found for channel " + this->channelName_);
|
"No logs could be found for channel " + this->channelName_);
|
||||||
box->setAttribute(Qt::WA_DeleteOnClose);
|
box->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
box->show();
|
box->show();
|
||||||
box->raise();
|
box->raise();
|
||||||
|
|
||||||
static QSet<int> closeButtons{
|
static QSet<int> closeButtons{
|
||||||
QMessageBox::Ok,
|
QMessageBox::Ok,
|
||||||
QMessageBox::Close,
|
QMessageBox::Close,
|
||||||
};
|
};
|
||||||
if (closeButtons.contains(box->exec()))
|
if (closeButtons.contains(box->exec()))
|
||||||
{
|
|
||||||
this->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
req.onSuccess([this](auto result) -> Outcome {
|
|
||||||
auto data = result.parseJson();
|
|
||||||
std::vector<MessagePtr> messages;
|
|
||||||
if (data.contains("lines"))
|
|
||||||
{
|
|
||||||
QJsonArray dataMessages = data.value("lines").toArray();
|
|
||||||
for (auto i : dataMessages)
|
|
||||||
{
|
{
|
||||||
QJsonObject singleMessage = i.toObject();
|
this->close();
|
||||||
QTime timeStamp = QDateTime::fromSecsSinceEpoch(
|
|
||||||
singleMessage.value("timestamp").toInt())
|
|
||||||
.time();
|
|
||||||
|
|
||||||
MessageBuilder builder;
|
|
||||||
builder.emplace<TimestampElement>(timeStamp);
|
|
||||||
builder.emplace<TextElement>(this->userName_,
|
|
||||||
MessageElementFlag::Username,
|
|
||||||
MessageColor::System);
|
|
||||||
builder.emplace<TextElement>(
|
|
||||||
singleMessage.value("text").toString(),
|
|
||||||
MessageElementFlag::Text, MessageColor::Text);
|
|
||||||
messages.push_back(builder.release());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this->setMessages(messages);
|
|
||||||
|
|
||||||
return Success;
|
return true;
|
||||||
});
|
})
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
|
auto data = result.parseJson();
|
||||||
|
std::vector<MessagePtr> messages;
|
||||||
|
if (data.contains("lines"))
|
||||||
|
{
|
||||||
|
QJsonArray dataMessages = data.value("lines").toArray();
|
||||||
|
for (auto i : dataMessages)
|
||||||
|
{
|
||||||
|
QJsonObject singleMessage = i.toObject();
|
||||||
|
QTime timeStamp =
|
||||||
|
QDateTime::fromSecsSinceEpoch(
|
||||||
|
singleMessage.value("timestamp").toInt())
|
||||||
|
.time();
|
||||||
|
|
||||||
req.execute();
|
MessageBuilder builder;
|
||||||
|
builder.emplace<TimestampElement>(timeStamp);
|
||||||
|
builder.emplace<TextElement>(this->userName_,
|
||||||
|
MessageElementFlag::Username,
|
||||||
|
MessageColor::System);
|
||||||
|
builder.emplace<TextElement>(
|
||||||
|
singleMessage.value("text").toString(),
|
||||||
|
MessageElementFlag::Text, MessageColor::Text);
|
||||||
|
messages.push_back(builder.release());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->setMessages(messages);
|
||||||
|
|
||||||
|
return Success;
|
||||||
|
})
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -350,26 +350,24 @@ void UserInfoPopup::updateUserData()
|
||||||
|
|
||||||
QString url("https://api.twitch.tv/kraken/channels/" + id);
|
QString url("https://api.twitch.tv/kraken/channels/" + id);
|
||||||
|
|
||||||
auto request = NetworkRequest::twitchRequest(url);
|
NetworkRequest::twitchRequest(url)
|
||||||
request.setCaller(this);
|
.caller(this)
|
||||||
|
.onSuccess([this](auto result) -> Outcome {
|
||||||
|
auto obj = result.parseJson();
|
||||||
|
this->ui_.followerCountLabel->setText(
|
||||||
|
TEXT_FOLLOWERS +
|
||||||
|
QString::number(obj.value("followers").toInt()));
|
||||||
|
this->ui_.viewCountLabel->setText(
|
||||||
|
TEXT_VIEWS + QString::number(obj.value("views").toInt()));
|
||||||
|
this->ui_.createdDateLabel->setText(
|
||||||
|
TEXT_CREATED +
|
||||||
|
obj.value("created_at").toString().section("T", 0, 0));
|
||||||
|
|
||||||
request.onSuccess([this](auto result) -> Outcome {
|
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
||||||
auto obj = result.parseJson();
|
|
||||||
this->ui_.followerCountLabel->setText(
|
|
||||||
TEXT_FOLLOWERS +
|
|
||||||
QString::number(obj.value("followers").toInt()));
|
|
||||||
this->ui_.viewCountLabel->setText(
|
|
||||||
TEXT_VIEWS + QString::number(obj.value("views").toInt()));
|
|
||||||
this->ui_.createdDateLabel->setText(
|
|
||||||
TEXT_CREATED +
|
|
||||||
obj.value("created_at").toString().section("T", 0, 0));
|
|
||||||
|
|
||||||
this->loadAvatar(QUrl(obj.value("logo").toString()));
|
return Success;
|
||||||
|
})
|
||||||
return Success;
|
.execute();
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
|
|
||||||
// get follow state
|
// get follow state
|
||||||
currentUser->checkFollow(id, [this, hack](auto result) {
|
currentUser->checkFollow(id, [this, hack](auto result) {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/FlagsEnum.hpp"
|
#include "common/FlagsEnum.hpp"
|
||||||
|
#include "messages/Image.hpp"
|
||||||
#include "messages/LimitedQueue.hpp"
|
#include "messages/LimitedQueue.hpp"
|
||||||
#include "messages/LimitedQueueSnapshot.hpp"
|
#include "messages/LimitedQueueSnapshot.hpp"
|
||||||
#include "messages/Selection.hpp"
|
#include "messages/Selection.hpp"
|
||||||
#include "messages/Image.hpp"
|
|
||||||
#include "widgets/BaseWidget.hpp"
|
#include "widgets/BaseWidget.hpp"
|
||||||
|
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
|
|
|
@ -218,10 +218,10 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
||||||
layout.addCheckbox("Hide moderated messages", s.hideModerated);
|
layout.addCheckbox("Hide moderated messages", s.hideModerated);
|
||||||
layout.addCheckbox("Hide moderation messages", s.hideModerationActions);
|
layout.addCheckbox("Hide moderation messages", s.hideModerationActions);
|
||||||
layout.addCheckbox("Colorize gray nicknames", s.colorizeNicknames);
|
layout.addCheckbox("Colorize gray nicknames", s.colorizeNicknames);
|
||||||
layout.addDropdown<int>(
|
layout.addDropdown<int>("Timeout stacking style",
|
||||||
"Timeout stacking style", {"Stack", "Stack sparingly"},
|
{"Stack", "Stack sparingly"}, s.timeoutStackStyle,
|
||||||
s.timeoutStackStyle, [](int index) { return index; },
|
[](int index) { return index; },
|
||||||
[](auto args) { return args.index; }, false);
|
[](auto args) { return args.index; }, false);
|
||||||
|
|
||||||
layout.addTitle("Emotes");
|
layout.addTitle("Emotes");
|
||||||
layout.addDropdown<float>(
|
layout.addDropdown<float>(
|
||||||
|
@ -278,11 +278,11 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
||||||
layout.addCheckbox("Double click links to open", s.linksDoubleClickOnly);
|
layout.addCheckbox("Double click links to open", s.linksDoubleClickOnly);
|
||||||
layout.addCheckbox("Unshorten links", s.unshortLinks);
|
layout.addCheckbox("Unshorten links", s.unshortLinks);
|
||||||
layout.addCheckbox("Show live indicator in tabs", s.showTabLive);
|
layout.addCheckbox("Show live indicator in tabs", s.showTabLive);
|
||||||
layout.addDropdown<int>(
|
layout.addDropdown<int>("Show emote preview in tooltip on hover",
|
||||||
"Show emote preview in tooltip on hover",
|
{"Don't show", "Always show", "Hold shift"},
|
||||||
{"Don't show", "Always show", "Hold shift"}, s.emotesTooltipPreview,
|
s.emotesTooltipPreview,
|
||||||
[](int index) { return index; }, [](auto args) { return args.index; },
|
[](int index) { return index; },
|
||||||
false);
|
[](auto args) { return args.index; }, false);
|
||||||
|
|
||||||
layout.addCheckbox(
|
layout.addCheckbox(
|
||||||
"Only search for emote autocompletion at the start of emote names",
|
"Only search for emote autocompletion at the start of emote names",
|
||||||
|
|
|
@ -554,34 +554,31 @@ void Split::showViewerList()
|
||||||
}
|
}
|
||||||
auto loadingLabel = new QLabel("Loading...");
|
auto loadingLabel = new QLabel("Loading...");
|
||||||
|
|
||||||
auto request = NetworkRequest::twitchRequest(
|
NetworkRequest::twitchRequest("https://tmi.twitch.tv/group/user/" +
|
||||||
"https://tmi.twitch.tv/group/user/" + this->getChannel()->getName() +
|
this->getChannel()->getName() + "/chatters")
|
||||||
"/chatters");
|
.caller(this)
|
||||||
|
.onSuccess([=](auto result) -> Outcome {
|
||||||
|
auto obj = result.parseJson();
|
||||||
|
QJsonObject chattersObj = obj.value("chatters").toObject();
|
||||||
|
|
||||||
request.setCaller(this);
|
loadingLabel->hide();
|
||||||
request.onSuccess([=](auto result) -> Outcome {
|
for (int i = 0; i < jsonLabels.size(); i++)
|
||||||
auto obj = result.parseJson();
|
{
|
||||||
QJsonObject chattersObj = obj.value("chatters").toObject();
|
auto currentCategory =
|
||||||
|
chattersObj.value(jsonLabels.at(i)).toArray();
|
||||||
|
// If current category of chatters is empty, dont show this
|
||||||
|
// category.
|
||||||
|
if (currentCategory.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
loadingLabel->hide();
|
chattersList->addItem(labelList.at(i));
|
||||||
for (int i = 0; i < jsonLabels.size(); i++)
|
foreach (const QJsonValue &v, currentCategory)
|
||||||
{
|
chattersList->addItem(v.toString());
|
||||||
auto currentCategory =
|
}
|
||||||
chattersObj.value(jsonLabels.at(i)).toArray();
|
|
||||||
// If current category of chatters is empty, dont show this
|
|
||||||
// category.
|
|
||||||
if (currentCategory.empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
chattersList->addItem(labelList.at(i));
|
return Success;
|
||||||
foreach (const QJsonValue &v, currentCategory)
|
})
|
||||||
chattersList->addItem(v.toString());
|
.execute();
|
||||||
}
|
|
||||||
|
|
||||||
return Success;
|
|
||||||
});
|
|
||||||
|
|
||||||
request.execute();
|
|
||||||
|
|
||||||
searchBar->setPlaceholderText("Search User...");
|
searchBar->setPlaceholderText("Search User...");
|
||||||
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
|
QObject::connect(searchBar, &QLineEdit::textEdited, this, [=]() {
|
||||||
|
|
Loading…
Reference in a new issue