mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
twitch emotes are now refreshed properly (sub and global emotes)
this only works if you're logged in I think
This commit is contained in:
parent
afd4549c3f
commit
51fe00dfec
|
@ -24,11 +24,12 @@ namespace chatterino {
|
||||||
EmoteManager::EmoteManager()
|
EmoteManager::EmoteManager()
|
||||||
: findShortCodesRegex(":([-+\\w]+):")
|
: findShortCodesRegex(":([-+\\w]+):")
|
||||||
{
|
{
|
||||||
pajlada::Settings::Setting<std::string> roomID(
|
auto &accountManager = AccountManager::getInstance();
|
||||||
"/accounts/current/roomID", "", pajlada::Settings::SettingOption::DoNotWriteToJSON);
|
|
||||||
|
|
||||||
roomID.getValueChangedSignal().connect([this](const std::string &roomID, auto) {
|
accountManager.Twitch.userChanged.connect([this] {
|
||||||
this->refreshTwitchEmotes(roomID); //
|
auto currentUser = AccountManager::getInstance().Twitch.getCurrent();
|
||||||
|
assert(currentUser);
|
||||||
|
this->refreshTwitchEmotes(currentUser);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,38 +355,31 @@ QString EmoteManager::replaceShortCodes(const QString &text)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteManager::refreshTwitchEmotes(const std::string &roomID)
|
void EmoteManager::refreshTwitchEmotes(const std::shared_ptr<twitch::TwitchUser> &user)
|
||||||
{
|
{
|
||||||
std::string oauthClient =
|
debug::Log("Loading Twitch emotes for user {}", user->getNickName());
|
||||||
pajlada::Settings::Setting<std::string>::get("/accounts/" + roomID + "/oauthClient");
|
|
||||||
std::string oauthToken =
|
|
||||||
pajlada::Settings::Setting<std::string>::get("/accounts/" + roomID + "/oauthToken");
|
|
||||||
|
|
||||||
TwitchAccountEmoteData &emoteData = this->twitchAccountEmotes[roomID];
|
const auto &roomID = user->getUserId();
|
||||||
|
const auto &clientID = user->getOAuthClient();
|
||||||
|
const auto &oauthToken = user->getOAuthToken();
|
||||||
|
|
||||||
|
if (clientID.isEmpty() || oauthToken.isEmpty()) {
|
||||||
|
debug::Log("Missing Client ID or OAuth token");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TwitchAccountEmoteData &emoteData = this->twitchAccountEmotes[roomID.toStdString()];
|
||||||
|
|
||||||
if (emoteData.filled) {
|
if (emoteData.filled) {
|
||||||
qDebug() << "Already loaded for room id " << qS(roomID);
|
qDebug() << "Already loaded for room id " << roomID;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Loading emotes for room id " << qS(roomID);
|
QString url("https://api.twitch.tv/kraken/users/" + roomID + "/emotes");
|
||||||
|
|
||||||
if (oauthClient.empty() || oauthToken.empty()) {
|
util::twitch::getAuthorized(
|
||||||
qDebug() << "Missing oauth client/token";
|
url, clientID, oauthToken, QThread::currentThread(),
|
||||||
return;
|
[=, &emoteData](QJsonObject &root) {
|
||||||
}
|
|
||||||
|
|
||||||
// api:v5
|
|
||||||
QString url("https://api.twitch.tv/kraken/users/" + qS(roomID) +
|
|
||||||
"/emotes?api_version=5&oauth_token=" + qS(oauthToken) +
|
|
||||||
"&client_id=" + qS(oauthClient));
|
|
||||||
|
|
||||||
qDebug() << url;
|
|
||||||
|
|
||||||
util::NetworkRequest req(url);
|
|
||||||
req.setCaller(QThread::currentThread());
|
|
||||||
req.setTimeout(3000);
|
|
||||||
req.getJSON([=, &emoteData](QJsonObject &root) {
|
|
||||||
emoteData.emoteSets.clear();
|
emoteData.emoteSets.clear();
|
||||||
emoteData.emoteCodes.clear();
|
emoteData.emoteCodes.clear();
|
||||||
auto emoticonSets = root.value("emoticon_sets").toObject();
|
auto emoticonSets = root.value("emoticon_sets").toObject();
|
||||||
|
@ -403,7 +397,9 @@ void EmoteManager::refreshTwitchEmotes(const std::string &roomID)
|
||||||
}
|
}
|
||||||
|
|
||||||
emoteData.filled = true;
|
emoteData.filled = true;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmoteManager::loadBTTVEmotes()
|
void EmoteManager::loadBTTVEmotes()
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "messages/lazyloadedimage.hpp"
|
#include "messages/lazyloadedimage.hpp"
|
||||||
#include "signalvector.hpp"
|
#include "signalvector.hpp"
|
||||||
#include "twitch/emotevalue.hpp"
|
#include "twitch/emotevalue.hpp"
|
||||||
|
#include "twitch/twitchuser.hpp"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
@ -100,7 +101,7 @@ public:
|
||||||
std::vector<std::string> emojiShortCodes;
|
std::vector<std::string> emojiShortCodes;
|
||||||
|
|
||||||
/// Twitch emotes
|
/// Twitch emotes
|
||||||
void refreshTwitchEmotes(const std::string &roomID);
|
void refreshTwitchEmotes(const std::shared_ptr<twitch::TwitchUser> &user);
|
||||||
|
|
||||||
struct TwitchAccountEmoteData {
|
struct TwitchAccountEmoteData {
|
||||||
struct TwitchEmote {
|
struct TwitchEmote {
|
||||||
|
|
Loading…
Reference in a new issue