mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Clean up FFZEmotes class
This commit is contained in:
parent
09963700ae
commit
d739fb0df4
2 changed files with 53 additions and 69 deletions
|
@ -44,68 +44,6 @@ void fillInEmoteData(const QJsonObject &urls, const QString &code, const QString
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void FFZEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<util::EmoteMap> _map)
|
|
||||||
{
|
|
||||||
printf("[FFZEmotes] Reload FFZ Channel Emotes for channel %s\n", qPrintable(channelName));
|
|
||||||
|
|
||||||
QString url("https://api.frankerfacez.com/v1/room/" + channelName);
|
|
||||||
|
|
||||||
util::NetworkRequest req(url);
|
|
||||||
req.setCaller(QThread::currentThread());
|
|
||||||
req.setTimeout(3000);
|
|
||||||
req.getJSON([this, channelName, _map](QJsonObject &rootNode) {
|
|
||||||
auto map = _map.lock();
|
|
||||||
|
|
||||||
if (_map.expired()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
map->clear();
|
|
||||||
|
|
||||||
auto setsNode = rootNode.value("sets").toObject();
|
|
||||||
|
|
||||||
std::vector<std::string> codes;
|
|
||||||
for (const QJsonValue &setNode : setsNode) {
|
|
||||||
auto emotesNode = setNode.toObject().value("emoticons").toArray();
|
|
||||||
|
|
||||||
for (const QJsonValue &emoteNode : emotesNode) {
|
|
||||||
QJsonObject emoteObject = emoteNode.toObject();
|
|
||||||
|
|
||||||
// margins
|
|
||||||
int id = emoteObject.value("id").toInt();
|
|
||||||
QString code = emoteObject.value("name").toString();
|
|
||||||
|
|
||||||
QJsonObject urls = emoteObject.value("urls").toObject();
|
|
||||||
|
|
||||||
auto emote = this->getChannelEmoteFromCaches().getOrAdd(id, [id, &code, &urls] {
|
|
||||||
util::EmoteData emoteData;
|
|
||||||
fillInEmoteData(urls, code, code + "<br/>Channel FFZ Emote", emoteData);
|
|
||||||
emoteData.pageLink =
|
|
||||||
QString("https://www.frankerfacez.com/emoticon/%1-%2").arg(id).arg(code);
|
|
||||||
|
|
||||||
return emoteData;
|
|
||||||
});
|
|
||||||
|
|
||||||
this->channelEmotes.insert(code, emote);
|
|
||||||
map->insert(code, emote);
|
|
||||||
codes.push_back(code.toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
this->channelEmoteCodes[channelName.toStdString()] = codes;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
util::EmoteMap &FFZEmotes::getEmotes()
|
|
||||||
{
|
|
||||||
return this->globalEmotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
util::ConcurrentMap<int, util::EmoteData> &FFZEmotes::getChannelEmoteFromCaches()
|
|
||||||
{
|
|
||||||
return this->_channelEmoteFromCaches;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FFZEmotes::loadGlobalEmotes()
|
void FFZEmotes::loadGlobalEmotes()
|
||||||
{
|
{
|
||||||
QString url("https://api.frankerfacez.com/v1/set/global");
|
QString url("https://api.frankerfacez.com/v1/set/global");
|
||||||
|
@ -141,6 +79,58 @@ void FFZEmotes::loadGlobalEmotes()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FFZEmotes::loadChannelEmotes(const QString &channelName, std::weak_ptr<util::EmoteMap> _map)
|
||||||
|
{
|
||||||
|
printf("[FFZEmotes] Reload FFZ Channel Emotes for channel %s\n", qPrintable(channelName));
|
||||||
|
|
||||||
|
QString url("https://api.frankerfacez.com/v1/room/" + channelName);
|
||||||
|
|
||||||
|
util::NetworkRequest req(url);
|
||||||
|
req.setCaller(QThread::currentThread());
|
||||||
|
req.setTimeout(3000);
|
||||||
|
req.getJSON([this, channelName, _map](QJsonObject &rootNode) {
|
||||||
|
auto map = _map.lock();
|
||||||
|
|
||||||
|
if (_map.expired()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
map->clear();
|
||||||
|
|
||||||
|
auto setsNode = rootNode.value("sets").toObject();
|
||||||
|
|
||||||
|
std::vector<std::string> codes;
|
||||||
|
for (const QJsonValue &setNode : setsNode) {
|
||||||
|
auto emotesNode = setNode.toObject().value("emoticons").toArray();
|
||||||
|
|
||||||
|
for (const QJsonValue &emoteNode : emotesNode) {
|
||||||
|
QJsonObject emoteObject = emoteNode.toObject();
|
||||||
|
|
||||||
|
// margins
|
||||||
|
int id = emoteObject.value("id").toInt();
|
||||||
|
QString code = emoteObject.value("name").toString();
|
||||||
|
|
||||||
|
QJsonObject urls = emoteObject.value("urls").toObject();
|
||||||
|
|
||||||
|
auto emote = this->channelEmoteCache.getOrAdd(id, [id, &code, &urls] {
|
||||||
|
util::EmoteData emoteData;
|
||||||
|
fillInEmoteData(urls, code, code + "<br/>Channel FFZ Emote", emoteData);
|
||||||
|
emoteData.pageLink =
|
||||||
|
QString("https://www.frankerfacez.com/emoticon/%1-%2").arg(id).arg(code);
|
||||||
|
|
||||||
|
return emoteData;
|
||||||
|
});
|
||||||
|
|
||||||
|
this->channelEmotes.insert(code, emote);
|
||||||
|
map->insert(code, emote);
|
||||||
|
codes.push_back(code.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
this->channelEmoteCodes[channelName.toStdString()] = codes;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ffz
|
} // namespace ffz
|
||||||
} // namespace providers
|
} // namespace providers
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -20,17 +20,11 @@ public:
|
||||||
std::map<std::string, SignalVector<std::string>> channelEmoteCodes;
|
std::map<std::string, SignalVector<std::string>> channelEmoteCodes;
|
||||||
|
|
||||||
void loadGlobalEmotes();
|
void loadGlobalEmotes();
|
||||||
|
|
||||||
void loadChannelEmotes(const QString &channelName,
|
void loadChannelEmotes(const QString &channelName,
|
||||||
std::weak_ptr<util::EmoteMap> channelEmoteMap);
|
std::weak_ptr<util::EmoteMap> channelEmoteMap);
|
||||||
|
|
||||||
util::EmoteMap &getEmotes();
|
|
||||||
util::ConcurrentMap<int, util::EmoteData> &getChannelEmoteFromCaches();
|
|
||||||
|
|
||||||
util::ConcurrentMap<QString, util::EmoteMap> channels;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
util::ConcurrentMap<int, util::EmoteData> _channelEmoteFromCaches;
|
util::ConcurrentMap<int, util::EmoteData> channelEmoteCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ffz
|
} // namespace ffz
|
||||||
|
|
Loading…
Reference in a new issue