From 2746f88e491ca57c1266d1355b0d9dd45fa0ffa5 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Fri, 22 Jun 2018 20:42:53 +0000 Subject: [PATCH] Load all short codes for emojis, instead of just the first one Fix #494 --- src/providers/emoji/emojis.cpp | 26 ++++++++++++++++---------- src/providers/emoji/emojis.hpp | 2 +- src/widgets/emotepopup.cpp | 5 +++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/providers/emoji/emojis.cpp b/src/providers/emoji/emojis.cpp index b1b1892e9..4e913a467 100644 --- a/src/providers/emoji/emojis.cpp +++ b/src/providers/emoji/emojis.cpp @@ -27,10 +27,14 @@ void parseEmoji(const std::shared_ptr &emojiData, const rapidjson::Va } capabilities; if (!shortCode.isEmpty()) { - emojiData->shortCode = shortCode; - } else if (!rj::getSafe(unparsedEmoji, "short_name", emojiData->shortCode)) { - return; + emojiData->shortCodes.push_back(shortCode); + } else { + const auto &shortCodes = unparsedEmoji["short_names"]; + for (const auto &shortCode : shortCodes.GetArray()) { + emojiData->shortCodes.emplace_back(shortCode.GetString()); + } } + rj::getSafe(unparsedEmoji, "non_qualified", emojiData->nonQualifiedCode); rj::getSafe(unparsedEmoji, "unified", emojiData->unifiedCode); @@ -118,8 +122,10 @@ void Emojis::loadEmojis() auto emojiData = std::make_shared(); parseEmoji(emojiData, unparsedEmoji); - this->emojiShortCodeToEmoji.insert(emojiData->shortCode, emojiData); - this->shortCodes.emplace_back(emojiData->shortCode); + for (const auto &shortCode : emojiData->shortCodes) { + this->emojiShortCodeToEmoji.insert(shortCode, emojiData); + this->shortCodes.emplace_back(shortCode); + } this->emojiFirstByte[emojiData->value.at(0)].append(emojiData); @@ -139,11 +145,11 @@ void Emojis::loadEmojis() } parseEmoji(variationEmojiData, variation, - emojiData->shortCode + "_" + toneNameIt->second); + emojiData->shortCodes[0] + "_" + toneNameIt->second); - this->emojiShortCodeToEmoji.insert(variationEmojiData->shortCode, + this->emojiShortCodeToEmoji.insert(variationEmojiData->shortCodes[0], variationEmojiData); - this->shortCodes.push_back(variationEmojiData->shortCode); + this->shortCodes.push_back(variationEmojiData->shortCodes[0]); this->emojiFirstByte[variationEmojiData->value.at(0)].append(variationEmojiData); @@ -256,8 +262,8 @@ void Emojis::loadEmojiSet() urlPrefix = it->second; } QString url = urlPrefix + code + ".png"; - emoji->emoteData.image1x = new messages::Image(url, 0.35, emoji->value, - ":" + emoji->shortCode + ":
Emoji"); + emoji->emoteData.image1x = new messages::Image( + url, 0.35, emoji->value, ":" + emoji->shortCodes[0] + ":
Emoji"); }); }); } diff --git a/src/providers/emoji/emojis.hpp b/src/providers/emoji/emojis.hpp index b41703214..0fe8ed5f0 100644 --- a/src/providers/emoji/emojis.hpp +++ b/src/providers/emoji/emojis.hpp @@ -22,7 +22,7 @@ struct EmojiData { QString nonQualifiedCode; // i.e. thinking - QString shortCode; + std::vector shortCodes; std::set capabilities; diff --git a/src/widgets/emotepopup.cpp b/src/widgets/emotepopup.cpp index 53197be1d..3a15a67ee 100644 --- a/src/widgets/emotepopup.cpp +++ b/src/widgets/emotepopup.cpp @@ -142,8 +142,9 @@ void EmotePopup::loadEmojis() builder.getMessage()->flags |= Message::DisableCompactEmotes; emojis.each([&builder](const QString &key, const auto &value) { - builder.append((new EmoteElement(value->emoteData, MessageElement::Flags::AlwaysShow)) - ->setLink(Link(Link::Type::InsertText, ":" + value->shortCode + ":"))); + builder.append( + (new EmoteElement(value->emoteData, MessageElement::Flags::AlwaysShow)) + ->setLink(Link(Link::Type::InsertText, ":" + value->shortCodes[0] + ":"))); }); emojiChannel->addMessage(builder.getMessage());