Load all short codes for emojis, instead of just the first one

Fix #494
This commit is contained in:
Rasmus Karlsson 2018-06-22 20:42:53 +00:00
parent 077f908f4e
commit 2746f88e49
3 changed files with 20 additions and 13 deletions

View file

@ -27,10 +27,14 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData, const rapidjson::Va
} capabilities; } capabilities;
if (!shortCode.isEmpty()) { if (!shortCode.isEmpty()) {
emojiData->shortCode = shortCode; emojiData->shortCodes.push_back(shortCode);
} else if (!rj::getSafe(unparsedEmoji, "short_name", emojiData->shortCode)) { } else {
return; 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, "non_qualified", emojiData->nonQualifiedCode);
rj::getSafe(unparsedEmoji, "unified", emojiData->unifiedCode); rj::getSafe(unparsedEmoji, "unified", emojiData->unifiedCode);
@ -118,8 +122,10 @@ void Emojis::loadEmojis()
auto emojiData = std::make_shared<EmojiData>(); auto emojiData = std::make_shared<EmojiData>();
parseEmoji(emojiData, unparsedEmoji); parseEmoji(emojiData, unparsedEmoji);
this->emojiShortCodeToEmoji.insert(emojiData->shortCode, emojiData); for (const auto &shortCode : emojiData->shortCodes) {
this->shortCodes.emplace_back(emojiData->shortCode); this->emojiShortCodeToEmoji.insert(shortCode, emojiData);
this->shortCodes.emplace_back(shortCode);
}
this->emojiFirstByte[emojiData->value.at(0)].append(emojiData); this->emojiFirstByte[emojiData->value.at(0)].append(emojiData);
@ -139,11 +145,11 @@ void Emojis::loadEmojis()
} }
parseEmoji(variationEmojiData, variation, parseEmoji(variationEmojiData, variation,
emojiData->shortCode + "_" + toneNameIt->second); emojiData->shortCodes[0] + "_" + toneNameIt->second);
this->emojiShortCodeToEmoji.insert(variationEmojiData->shortCode, this->emojiShortCodeToEmoji.insert(variationEmojiData->shortCodes[0],
variationEmojiData); variationEmojiData);
this->shortCodes.push_back(variationEmojiData->shortCode); this->shortCodes.push_back(variationEmojiData->shortCodes[0]);
this->emojiFirstByte[variationEmojiData->value.at(0)].append(variationEmojiData); this->emojiFirstByte[variationEmojiData->value.at(0)].append(variationEmojiData);
@ -256,8 +262,8 @@ void Emojis::loadEmojiSet()
urlPrefix = it->second; urlPrefix = it->second;
} }
QString url = urlPrefix + code + ".png"; QString url = urlPrefix + code + ".png";
emoji->emoteData.image1x = new messages::Image(url, 0.35, emoji->value, emoji->emoteData.image1x = new messages::Image(
":" + emoji->shortCode + ":<br/>Emoji"); url, 0.35, emoji->value, ":" + emoji->shortCodes[0] + ":<br/>Emoji");
}); });
}); });
} }

View file

@ -22,7 +22,7 @@ struct EmojiData {
QString nonQualifiedCode; QString nonQualifiedCode;
// i.e. thinking // i.e. thinking
QString shortCode; std::vector<QString> shortCodes;
std::set<QString> capabilities; std::set<QString> capabilities;

View file

@ -142,8 +142,9 @@ void EmotePopup::loadEmojis()
builder.getMessage()->flags |= Message::DisableCompactEmotes; builder.getMessage()->flags |= Message::DisableCompactEmotes;
emojis.each([&builder](const QString &key, const auto &value) { emojis.each([&builder](const QString &key, const auto &value) {
builder.append((new EmoteElement(value->emoteData, MessageElement::Flags::AlwaysShow)) builder.append(
->setLink(Link(Link::Type::InsertText, ":" + value->shortCode + ":"))); (new EmoteElement(value->emoteData, MessageElement::Flags::AlwaysShow))
->setLink(Link(Link::Type::InsertText, ":" + value->shortCodes[0] + ":")));
}); });
emojiChannel->addMessage(builder.getMessage()); emojiChannel->addMessage(builder.getMessage());