2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
#include "Application.hpp"
|
2019-05-26 21:44:13 +02:00
|
|
|
#include "common/Env.hpp"
|
2018-06-26 15:33:51 +02:00
|
|
|
#include "common/NetworkRequest.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "common/Outcome.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2021-02-14 14:01:13 +01:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2021-03-21 15:42:45 +01:00
|
|
|
#include "providers/IvrApi.hpp"
|
2018-06-26 17:25:24 +02:00
|
|
|
#include "providers/twitch/TwitchCommon.hpp"
|
2021-02-14 14:01:13 +01:00
|
|
|
#include "providers/twitch/TwitchUser.hpp"
|
2020-03-14 12:13:57 +01:00
|
|
|
#include "providers/twitch/api/Helix.hpp"
|
2021-03-21 15:19:49 +01:00
|
|
|
#include "providers/twitch/api/Kraken.hpp"
|
2018-08-02 14:23:27 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
2018-06-26 17:20:03 +02:00
|
|
|
#include "util/RapidjsonHelpers.hpp"
|
2018-02-05 15:11:50 +01:00
|
|
|
|
|
|
|
namespace chatterino {
|
2021-03-21 15:42:45 +01:00
|
|
|
namespace {
|
|
|
|
constexpr int USERSTATE_EMOTES_REFRESH_PERIOD = 10 * 60 * 1000;
|
|
|
|
} // namespace
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
TwitchAccount::TwitchAccount(const QString &username, const QString &oauthToken,
|
|
|
|
const QString &oauthClient, const QString &userID)
|
2018-06-26 17:06:17 +02:00
|
|
|
: Account(ProviderId::Twitch)
|
2018-07-06 19:23:47 +02:00
|
|
|
, oauthClient_(oauthClient)
|
|
|
|
, oauthToken_(oauthToken)
|
|
|
|
, userName_(username)
|
|
|
|
, userId_(userID)
|
|
|
|
, isAnon_(username == ANONYMOUS_USERNAME)
|
2018-02-05 15:11:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-06 12:52:47 +02:00
|
|
|
QString TwitchAccount::toString() const
|
|
|
|
{
|
|
|
|
return this->getUserName();
|
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
const QString &TwitchAccount::getUserName() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->userName_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchAccount::getOAuthClient() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->oauthClient_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchAccount::getOAuthToken() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->oauthToken_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString &TwitchAccount::getUserId() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->userId_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
2018-08-11 17:35:46 +02:00
|
|
|
QColor TwitchAccount::color()
|
|
|
|
{
|
|
|
|
return this->color_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchAccount::setColor(QColor color)
|
|
|
|
{
|
2021-04-10 14:34:40 +02:00
|
|
|
this->color_.set(std::move(color));
|
2018-08-11 17:35:46 +02:00
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
bool TwitchAccount::setOAuthClient(const QString &newClientID)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->oauthClient_.compare(newClientID) == 0)
|
|
|
|
{
|
2018-02-05 15:11:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->oauthClient_ = newClientID;
|
2018-02-05 15:11:50 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchAccount::setOAuthToken(const QString &newOAuthToken)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (this->oauthToken_.compare(newOAuthToken) == 0)
|
|
|
|
{
|
2018-02-05 15:11:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-06 19:23:47 +02:00
|
|
|
this->oauthToken_ = newOAuthToken;
|
2018-02-05 15:11:50 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TwitchAccount::isAnon() const
|
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->isAnon_;
|
2018-02-05 15:11:50 +01:00
|
|
|
}
|
2018-03-31 13:44:15 +02:00
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
void TwitchAccount::loadBlocks()
|
2018-05-12 20:34:13 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
getHelix()->loadBlocks(
|
|
|
|
getApp()->accounts->twitch.getCurrent()->userId_,
|
|
|
|
[this](std::vector<HelixBlock> blocks) {
|
2021-05-01 13:38:58 +02:00
|
|
|
auto ignores = this->ignores_.access();
|
|
|
|
auto userIds = this->ignoresUserIds_.access();
|
|
|
|
ignores->clear();
|
|
|
|
userIds->clear();
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
for (const HelixBlock &block : blocks)
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
TwitchUser blockedUser;
|
|
|
|
blockedUser.fromHelixBlock(block);
|
2021-05-01 13:38:58 +02:00
|
|
|
ignores->insert(blockedUser);
|
|
|
|
userIds->insert(blockedUser.id);
|
2018-05-12 20:34:13 +02:00
|
|
|
}
|
2021-02-14 14:01:13 +01:00
|
|
|
},
|
|
|
|
[] {
|
|
|
|
qDebug() << "Fetching blocks failed!";
|
|
|
|
});
|
2018-05-13 17:53:24 +02:00
|
|
|
}
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
void TwitchAccount::blockUser(QString userId, std::function<void()> onSuccess,
|
|
|
|
std::function<void()> onFailure)
|
2018-05-13 17:53:24 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
getHelix()->blockUser(
|
|
|
|
userId,
|
|
|
|
[this, userId, onSuccess] {
|
|
|
|
TwitchUser blockedUser;
|
|
|
|
blockedUser.id = userId;
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
2021-05-01 13:38:58 +02:00
|
|
|
auto ignores = this->ignores_.access();
|
|
|
|
auto userIds = this->ignoresUserIds_.access();
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2021-05-01 13:38:58 +02:00
|
|
|
ignores->insert(blockedUser);
|
|
|
|
userIds->insert(blockedUser.id);
|
2019-08-20 21:50:36 +02:00
|
|
|
}
|
2021-02-14 14:01:13 +01:00
|
|
|
onSuccess();
|
|
|
|
},
|
2021-04-10 14:34:40 +02:00
|
|
|
std::move(onFailure));
|
2018-05-13 17:53:24 +02:00
|
|
|
}
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2021-02-14 14:01:13 +01:00
|
|
|
void TwitchAccount::unblockUser(QString userId, std::function<void()> onSuccess,
|
|
|
|
std::function<void()> onFailure)
|
2018-05-13 17:53:24 +02:00
|
|
|
{
|
2021-02-14 14:01:13 +01:00
|
|
|
getHelix()->unblockUser(
|
|
|
|
userId,
|
|
|
|
[this, userId, onSuccess] {
|
2019-08-20 21:50:36 +02:00
|
|
|
TwitchUser ignoredUser;
|
2021-02-14 14:01:13 +01:00
|
|
|
ignoredUser.id = userId;
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
2021-05-01 13:38:58 +02:00
|
|
|
auto ignores = this->ignores_.access();
|
|
|
|
auto userIds = this->ignoresUserIds_.access();
|
2018-05-13 17:53:24 +02:00
|
|
|
|
2021-05-01 13:38:58 +02:00
|
|
|
ignores->erase(ignoredUser);
|
|
|
|
userIds->erase(ignoredUser.id);
|
2019-08-20 21:50:36 +02:00
|
|
|
}
|
2021-02-14 14:01:13 +01:00
|
|
|
onSuccess();
|
|
|
|
},
|
2021-04-10 14:34:40 +02:00
|
|
|
std::move(onFailure));
|
2018-05-13 17:53:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TwitchAccount::checkFollow(const QString targetUserID,
|
|
|
|
std::function<void(FollowResult)> onFinished)
|
|
|
|
{
|
2020-03-14 12:13:57 +01:00
|
|
|
const auto onResponse = [onFinished](bool following, const auto &record) {
|
|
|
|
if (!following)
|
|
|
|
{
|
|
|
|
onFinished(FollowResult_NotFollowing);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
onFinished(FollowResult_Following);
|
|
|
|
};
|
2019-09-09 15:21:49 +02:00
|
|
|
|
2020-03-14 12:13:57 +01:00
|
|
|
getHelix()->getUserFollow(this->getUserId(), targetUserID, onResponse,
|
|
|
|
[] {});
|
2018-05-12 20:34:13 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const std::set<TwitchUser>> TwitchAccount::accessBlocks()
|
|
|
|
const
|
2018-05-12 20:34:13 +02:00
|
|
|
{
|
2021-05-01 13:38:58 +02:00
|
|
|
return this->ignores_.accessConst();
|
|
|
|
}
|
2018-05-12 20:34:13 +02:00
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const std::set<QString>> TwitchAccount::accessBlockedUserIds()
|
|
|
|
const
|
2021-05-01 13:38:58 +02:00
|
|
|
{
|
|
|
|
return this->ignoresUserIds_.accessConst();
|
2018-05-12 20:34:13 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void TwitchAccount::loadEmotes()
|
2018-06-27 02:16:30 +02:00
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "Loading Twitch emotes for user" << this->getUserName();
|
2018-06-27 02:16:30 +02:00
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
if (this->getOAuthClient().isEmpty() || this->getOAuthToken().isEmpty())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch) << "Missing Client ID or OAuth token";
|
2018-06-27 02:16:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
getKraken()->getUserEmotes(
|
|
|
|
this,
|
|
|
|
[this](KrakenEmoteSets data) {
|
|
|
|
// clear emote data
|
|
|
|
auto emoteData = this->emotes_.access();
|
|
|
|
emoteData->emoteSets.clear();
|
|
|
|
emoteData->allEmoteNames.clear();
|
2019-09-09 15:21:49 +02:00
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
// no emotes available
|
|
|
|
if (data.emoteSets.isEmpty())
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
2021-03-21 15:19:49 +01:00
|
|
|
qCWarning(chatterinoTwitch)
|
|
|
|
<< "\"emoticon_sets\" either empty or not present in "
|
|
|
|
"Kraken::getUserEmotes response";
|
|
|
|
return;
|
2019-08-20 21:50:36 +02:00
|
|
|
}
|
2021-03-21 15:19:49 +01:00
|
|
|
|
|
|
|
for (auto emoteSetIt = data.emoteSets.begin();
|
|
|
|
emoteSetIt != data.emoteSets.end(); ++emoteSetIt)
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
2021-03-21 15:19:49 +01:00
|
|
|
auto emoteSet = std::make_shared<EmoteSet>();
|
|
|
|
|
|
|
|
emoteSet->key = emoteSetIt.key();
|
|
|
|
this->loadEmoteSetData(emoteSet);
|
|
|
|
|
|
|
|
for (const auto emoteArrObj : emoteSetIt.value().toArray())
|
|
|
|
{
|
|
|
|
if (!emoteArrObj.isObject())
|
|
|
|
{
|
|
|
|
qCWarning(chatterinoTwitch)
|
|
|
|
<< QString("Emote value from set %1 was invalid")
|
|
|
|
.arg(emoteSet->key);
|
|
|
|
}
|
|
|
|
KrakenEmote krakenEmote(emoteArrObj.toObject());
|
|
|
|
|
|
|
|
auto id = EmoteId{krakenEmote.id};
|
|
|
|
auto code = EmoteName{krakenEmote.code};
|
|
|
|
|
|
|
|
auto cleanCode =
|
|
|
|
EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
|
|
|
|
emoteSet->emotes.emplace_back(TwitchEmote{id, cleanCode});
|
|
|
|
emoteData->allEmoteNames.push_back(cleanCode);
|
|
|
|
|
|
|
|
auto emote =
|
|
|
|
getApp()->emotes->twitch.getOrCreateEmote(id, code);
|
|
|
|
emoteData->emotes.emplace(code, emote);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(emoteSet->emotes.begin(), emoteSet->emotes.end(),
|
|
|
|
[](const TwitchEmote &l, const TwitchEmote &r) {
|
|
|
|
return l.name.string < r.name.string;
|
|
|
|
});
|
|
|
|
emoteData->emoteSets.emplace_back(emoteSet);
|
2019-08-20 21:50:36 +02:00
|
|
|
}
|
2021-03-21 15:19:49 +01:00
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// request failed
|
|
|
|
});
|
2018-08-02 14:23:27 +02:00
|
|
|
}
|
2021-03-21 15:42:45 +01:00
|
|
|
|
|
|
|
void TwitchAccount::loadUserstateEmotes(QStringList emoteSetKeys)
|
|
|
|
{
|
|
|
|
// do not attempt to load emotes too often
|
|
|
|
if (!this->userstateEmotesTimer_.isValid())
|
|
|
|
{
|
|
|
|
this->userstateEmotesTimer_.start();
|
|
|
|
}
|
|
|
|
else if (this->userstateEmotesTimer_.elapsed() <
|
|
|
|
USERSTATE_EMOTES_REFRESH_PERIOD)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->userstateEmotesTimer_.restart();
|
|
|
|
|
|
|
|
auto emoteData = this->emotes_.access();
|
|
|
|
auto userEmoteSets = emoteData->emoteSets;
|
|
|
|
|
|
|
|
QStringList newEmoteSetKeys, currentEmoteSetKeys;
|
|
|
|
// get list of already fetched emote sets
|
|
|
|
for (const auto &userEmoteSet : userEmoteSets)
|
|
|
|
{
|
|
|
|
currentEmoteSetKeys.push_back(userEmoteSet->key);
|
|
|
|
}
|
|
|
|
// filter out emote sets from userstate message, which are not in fetched emote set list
|
|
|
|
for (const auto &emoteSetKey : emoteSetKeys)
|
|
|
|
{
|
|
|
|
if (!currentEmoteSetKeys.contains(emoteSetKey))
|
|
|
|
{
|
|
|
|
newEmoteSetKeys.push_back(emoteSetKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return if there are no new emote sets
|
|
|
|
if (newEmoteSetKeys.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getIvr()->getBulkEmoteSets(
|
|
|
|
newEmoteSetKeys.join(","),
|
|
|
|
[this](QJsonArray emoteSetArray) {
|
|
|
|
auto emoteData = this->emotes_.access();
|
|
|
|
for (auto emoteSet : emoteSetArray)
|
|
|
|
{
|
|
|
|
auto newUserEmoteSet = std::make_shared<EmoteSet>();
|
|
|
|
|
|
|
|
IvrEmoteSet ivrEmoteSet(emoteSet.toObject());
|
|
|
|
|
|
|
|
newUserEmoteSet->key = ivrEmoteSet.setId;
|
|
|
|
|
|
|
|
auto name = ivrEmoteSet.login;
|
|
|
|
name.detach();
|
|
|
|
name[0] = name[0].toUpper();
|
|
|
|
|
|
|
|
newUserEmoteSet->text = name;
|
|
|
|
newUserEmoteSet->type = QString();
|
|
|
|
newUserEmoteSet->channelName = ivrEmoteSet.login;
|
|
|
|
|
|
|
|
for (const auto &emote : ivrEmoteSet.emotes)
|
|
|
|
{
|
|
|
|
IvrEmote ivrEmote(emote.toObject());
|
|
|
|
|
|
|
|
auto id = EmoteId{ivrEmote.id};
|
|
|
|
auto code = EmoteName{ivrEmote.code};
|
|
|
|
auto cleanCode =
|
|
|
|
EmoteName{TwitchEmotes::cleanUpEmoteCode(code)};
|
|
|
|
newUserEmoteSet->emotes.emplace_back(
|
|
|
|
TwitchEmote{id, cleanCode});
|
|
|
|
|
|
|
|
emoteData->allEmoteNames.push_back(cleanCode);
|
|
|
|
|
|
|
|
auto twitchEmote =
|
|
|
|
getApp()->emotes->twitch.getOrCreateEmote(id, code);
|
|
|
|
emoteData->emotes.emplace(code, twitchEmote);
|
|
|
|
}
|
|
|
|
std::sort(newUserEmoteSet->emotes.begin(),
|
|
|
|
newUserEmoteSet->emotes.end(),
|
|
|
|
[](const TwitchEmote &l, const TwitchEmote &r) {
|
|
|
|
return l.name.string < r.name.string;
|
|
|
|
});
|
|
|
|
emoteData->emoteSets.emplace_back(newUserEmoteSet);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[] {
|
|
|
|
// fetching emotes failed, ivr API might be down
|
|
|
|
});
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-05-01 17:19:41 +02:00
|
|
|
SharedAccessGuard<const TwitchAccount::TwitchAccountEmoteData>
|
2018-08-15 22:46:20 +02:00
|
|
|
TwitchAccount::accessEmotes() const
|
2018-08-02 14:23:27 +02:00
|
|
|
{
|
|
|
|
return this->emotes_.accessConst();
|
|
|
|
}
|
|
|
|
|
2019-01-20 14:45:59 +01:00
|
|
|
// AutoModActions
|
2019-01-20 16:07:31 +01:00
|
|
|
void TwitchAccount::autoModAllow(const QString msgID)
|
2019-01-20 14:47:04 +01:00
|
|
|
{
|
2019-01-20 16:07:31 +01:00
|
|
|
QString url("https://api.twitch.tv/kraken/chat/twitchbot/approve");
|
|
|
|
|
|
|
|
auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8();
|
2019-01-20 17:03:45 +01:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest(url, NetworkRequestType::Post)
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
.header("Content-Length", QByteArray::number(qba.size()))
|
|
|
|
.payload(qba)
|
2019-09-09 15:21:49 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
2019-09-19 19:03:50 +02:00
|
|
|
.onError([=](NetworkResult result) {
|
2020-11-21 16:20:10 +01:00
|
|
|
qCWarning(chatterinoTwitch)
|
|
|
|
<< "[TwitchAccounts::autoModAllow] Error" << result.status();
|
2019-08-20 21:50:36 +02:00
|
|
|
})
|
|
|
|
.execute();
|
2019-01-20 14:47:04 +01:00
|
|
|
}
|
|
|
|
|
2019-01-20 16:07:31 +01:00
|
|
|
void TwitchAccount::autoModDeny(const QString msgID)
|
2019-01-20 14:47:04 +01:00
|
|
|
{
|
2019-01-20 16:07:31 +01:00
|
|
|
QString url("https://api.twitch.tv/kraken/chat/twitchbot/deny");
|
|
|
|
|
|
|
|
auto qba = (QString("{\"msg_id\":\"") + msgID + "\"}").toUtf8();
|
2019-01-20 17:03:45 +01:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest(url, NetworkRequestType::Post)
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
.header("Content-Length", QByteArray::number(qba.size()))
|
|
|
|
.payload(qba)
|
2019-09-09 15:21:49 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
.authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken())
|
2019-09-19 19:03:50 +02:00
|
|
|
.onError([=](NetworkResult result) {
|
2020-11-21 16:20:10 +01:00
|
|
|
qCWarning(chatterinoTwitch)
|
|
|
|
<< "[TwitchAccounts::autoModDeny] Error" << result.status();
|
2019-08-20 21:50:36 +02:00
|
|
|
})
|
|
|
|
.execute();
|
2019-01-20 14:47:04 +01:00
|
|
|
}
|
2019-01-20 14:45:59 +01:00
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
void TwitchAccount::loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet)
|
|
|
|
{
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!emoteSet)
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCWarning(chatterinoTwitch) << "null emote set sent";
|
2018-08-02 14:23:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto staticSetIt = this->staticEmoteSets.find(emoteSet->key);
|
2018-10-21 13:43:02 +02:00
|
|
|
if (staticSetIt != this->staticEmoteSets.end())
|
|
|
|
{
|
2018-08-02 14:23:27 +02:00
|
|
|
const auto &staticSet = staticSetIt->second;
|
|
|
|
emoteSet->channelName = staticSet.channelName;
|
|
|
|
emoteSet->text = staticSet.text;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
NetworkRequest(Env::get().twitchEmoteSetResolverUrl.arg(emoteSet->key))
|
|
|
|
.cache()
|
2021-03-21 15:19:49 +01:00
|
|
|
.onSuccess([emoteSet](NetworkResult result) -> Outcome {
|
|
|
|
auto rootOld = result.parseRapidJson();
|
|
|
|
auto root = result.parseJson();
|
|
|
|
if (root.isEmpty())
|
2019-08-20 21:50:36 +02:00
|
|
|
{
|
|
|
|
return Failure;
|
|
|
|
}
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
TwitchEmoteSetResolverResponse response(root);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
auto name = response.channelName;
|
2019-08-20 21:50:36 +02:00
|
|
|
name.detach();
|
|
|
|
name[0] = name[0].toUpper();
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
emoteSet->text = name;
|
2021-03-21 15:19:49 +01:00
|
|
|
emoteSet->type = response.type;
|
|
|
|
emoteSet->channelName = response.channelName;
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2021-03-21 15:19:49 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< QString("Loaded twitch emote set data for %1")
|
|
|
|
.arg(emoteSet->key);
|
2018-08-02 14:23:27 +02:00
|
|
|
|
2019-08-20 21:50:36 +02:00
|
|
|
return Success;
|
|
|
|
})
|
2021-03-21 15:19:49 +01:00
|
|
|
.onError([](NetworkResult result) {
|
|
|
|
qCWarning(chatterinoTwitch)
|
|
|
|
<< QString("Error code %1 while loading emote set data")
|
|
|
|
.arg(result.status());
|
|
|
|
})
|
2019-08-20 21:50:36 +02:00
|
|
|
.execute();
|
2018-06-27 02:16:30 +02:00
|
|
|
}
|
|
|
|
|
2018-02-05 15:11:50 +01:00
|
|
|
} // namespace chatterino
|