mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Display authors name on hover for supported emotes (FFZ only for now) (#1721)
Co-authored-by: Paweł <44851575+zneix@users.noreply.github.com>
This commit is contained in:
parent
f3f8b2d024
commit
1eeb09a78e
|
@ -34,3 +34,4 @@ QStringAlias(Url);
|
|||
QStringAlias(Tooltip);
|
||||
QStringAlias(EmoteId);
|
||||
QStringAlias(EmoteName);
|
||||
QStringAlias(EmoteAuthor);
|
||||
|
|
|
@ -65,11 +65,12 @@ namespace {
|
|||
|
||||
return {Success, std::move(emotes)};
|
||||
}
|
||||
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot)
|
||||
std::pair<Outcome, EmoteMap> parseChannelEmotes(const QJsonObject &jsonRoot,
|
||||
const QString &userName)
|
||||
{
|
||||
auto emotes = EmoteMap();
|
||||
|
||||
auto innerParse = [&jsonRoot, &emotes](const char *key) {
|
||||
auto innerParse = [&jsonRoot, &emotes, &userName](const char *key) {
|
||||
auto jsonEmotes = jsonRoot.value(key).toArray();
|
||||
for (auto jsonEmote_ : jsonEmotes)
|
||||
{
|
||||
|
@ -77,6 +78,10 @@ namespace {
|
|||
|
||||
auto id = EmoteId{jsonEmote.value("id").toString()};
|
||||
auto name = EmoteName{jsonEmote.value("code").toString()};
|
||||
auto author = EmoteAuthor{jsonEmote.value("user")
|
||||
.toObject()
|
||||
.value("name")
|
||||
.toString()};
|
||||
// emoteObject.value("imageType").toString();
|
||||
|
||||
auto emote = Emote({
|
||||
|
@ -86,7 +91,10 @@ namespace {
|
|||
Image::fromUrl(getEmoteLinkV3(id, "2x"), 0.5),
|
||||
Image::fromUrl(getEmoteLinkV3(id, "3x"), 0.25),
|
||||
},
|
||||
Tooltip{name.string + "<br />Channel BetterTTV Emote"},
|
||||
Tooltip{name.string + "<br>Channel BetterTTV Emote" +
|
||||
((author.string.isEmpty())
|
||||
? "<br>By: " + userName.toUtf8()
|
||||
: "<br>By: " + author.string)},
|
||||
Url{emoteLinkFormat.arg(id.string)},
|
||||
});
|
||||
|
||||
|
@ -140,15 +148,15 @@ void BttvEmotes::loadEmotes()
|
|||
}
|
||||
|
||||
void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
|
||||
const QString &channelId,
|
||||
const QString &channelId, const QString &userName,
|
||||
std::function<void(EmoteMap &&)> callback,
|
||||
bool manualRefresh)
|
||||
{
|
||||
NetworkRequest(QString(bttvChannelEmoteApiUrl) + channelId)
|
||||
.timeout(3000)
|
||||
.onSuccess([callback = std::move(callback), channel,
|
||||
.onSuccess([callback = std::move(callback), channel, &userName,
|
||||
manualRefresh](auto result) -> Outcome {
|
||||
auto pair = parseChannelEmotes(result.parseJson());
|
||||
auto pair = parseChannelEmotes(result.parseJson(), userName);
|
||||
if (pair.first)
|
||||
callback(std::move(pair.second));
|
||||
if (auto shared = channel.lock(); manualRefresh)
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
static void loadChannel(std::weak_ptr<Channel> channel,
|
||||
const QString &channelId,
|
||||
const QString &channelId, const QString &userName,
|
||||
std::function<void(EmoteMap &&)> callback,
|
||||
bool manualRefresh);
|
||||
|
||||
|
|
|
@ -128,11 +128,17 @@ namespace {
|
|||
auto id =
|
||||
EmoteId{QString::number(jsonEmote.value("id").toInt())};
|
||||
auto name = EmoteName{jsonEmote.value("name").toString()};
|
||||
auto author = EmoteAuthor{jsonEmote.value("owner")
|
||||
.toObject()
|
||||
.value("display_name")
|
||||
.toString()};
|
||||
auto urls = jsonEmote.value("urls").toObject();
|
||||
|
||||
Emote emote;
|
||||
fillInEmoteData(urls, name,
|
||||
name.string + "<br/>Channel FFZ Emote", emote);
|
||||
name.string + "<br/>Channel FFZ Emote" +
|
||||
"<br />By: " + author.string,
|
||||
emote);
|
||||
emote.homePage =
|
||||
Url{QString("https://www.frankerfacez.com/emoticon/%1-%2")
|
||||
.arg(id.string)
|
||||
|
|
|
@ -159,7 +159,7 @@ bool TwitchChannel::canSendMessage() const
|
|||
void TwitchChannel::refreshBTTVChannelEmotes(bool manualRefresh)
|
||||
{
|
||||
BttvEmotes::loadChannel(
|
||||
weakOf<Channel>(this), this->roomId(),
|
||||
weakOf<Channel>(this), this->roomId(), this->getName(),
|
||||
[this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
|
||||
if (auto shared = weak.lock())
|
||||
this->bttvEmotes_.set(
|
||||
|
|
Loading…
Reference in a new issue