mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add an EmojiMap which is like an EmoteMap except it contains data for Emojis
Fix emote popup not inserting the correct emoji value on click. It no inserts the shortcode (i.e. 👌) Fix #299
This commit is contained in:
parent
05335c6440
commit
13705f15ed
4 changed files with 25 additions and 24 deletions
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/emotemap.hpp"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -13,6 +15,14 @@ struct EmojiData {
|
|||
|
||||
// i.e. thinking
|
||||
QString shortCode;
|
||||
|
||||
util::EmoteData emoteData;
|
||||
};
|
||||
|
||||
namespace util {
|
||||
|
||||
using EmojiMap = ConcurrentMap<QString, EmojiData>;
|
||||
|
||||
} // namespace util
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -226,7 +226,7 @@ util::EmoteMap &EmoteManager::getBTTVChannelEmoteFromCaches()
|
|||
return _bttvChannelEmoteFromCaches;
|
||||
}
|
||||
|
||||
util::EmoteMap &EmoteManager::getEmojis()
|
||||
util::EmojiMap &EmoteManager::getEmojis()
|
||||
{
|
||||
return this->emojis;
|
||||
}
|
||||
|
@ -277,10 +277,15 @@ void EmoteManager::loadEmojis()
|
|||
unicodeBytes[numUnicodeBytes++] = QString(unicodeCharacter).toUInt(nullptr, 16);
|
||||
}
|
||||
|
||||
QString url = "https://cdnjs.cloudflare.com/ajax/libs/"
|
||||
"emojione/2.2.6/assets/png/" +
|
||||
code + ".png";
|
||||
|
||||
EmojiData emojiData{
|
||||
QString::fromUcs4(unicodeBytes, numUnicodeBytes), //
|
||||
code, //
|
||||
shortCode, //
|
||||
{new Image(url, 0.35, ":" + shortCode + ":", ":" + shortCode + ":<br/>Emoji")},
|
||||
};
|
||||
|
||||
this->emojiShortCodeToEmoji.insert(shortCode, emojiData);
|
||||
|
@ -288,12 +293,7 @@ void EmoteManager::loadEmojis()
|
|||
|
||||
this->emojiFirstByte[emojiData.value.at(0)].append(emojiData);
|
||||
|
||||
QString url = "https://cdnjs.cloudflare.com/ajax/libs/"
|
||||
"emojione/2.2.6/assets/png/" +
|
||||
code + ".png";
|
||||
|
||||
this->emojis.insert(code, util::EmoteData(new Image(url, 0.35, ":" + shortCode + ":",
|
||||
":" + shortCode + ":<br/>Emoji")));
|
||||
this->emojis.insert(code, emojiData);
|
||||
}
|
||||
|
||||
for (auto &p : this->emojiFirstByte) {
|
||||
|
@ -369,17 +369,9 @@ void EmoteManager::parseEmojis(std::vector<std::tuple<util::EmoteData, QString>>
|
|||
charactersFromLastParsedEmoji));
|
||||
}
|
||||
|
||||
QString url = "https://cdnjs.cloudflare.com/ajax/libs/"
|
||||
"emojione/2.2.6/assets/png/" +
|
||||
matchedEmoji.code + ".png";
|
||||
|
||||
// Create or fetch cached emoji image
|
||||
auto emojiImage = this->emojis.getOrAdd(matchedEmoji.code, [&url] {
|
||||
return util::EmoteData(new Image(url, 0.35, "?????????", "???????????????")); //
|
||||
});
|
||||
|
||||
// Push the emoji as a word to parsedWords
|
||||
parsedWords.push_back(std::tuple<util::EmoteData, QString>(emojiImage, QString()));
|
||||
parsedWords.push_back(
|
||||
std::tuple<util::EmoteData, QString>(matchedEmoji.emoteData, QString()));
|
||||
|
||||
lastParsedEmojiEndIndex = currentParsedEmojiEndIndex;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
util::EmoteMap &getFFZEmotes();
|
||||
util::EmoteMap &getChatterinoEmotes();
|
||||
util::EmoteMap &getBTTVChannelEmoteFromCaches();
|
||||
util::EmoteMap &getEmojis();
|
||||
util::EmojiMap &getEmojis();
|
||||
util::ConcurrentMap<int, util::EmoteData> &getFFZChannelEmoteFromCaches();
|
||||
util::ConcurrentMap<long, util::EmoteData> &getTwitchEmoteFromCache();
|
||||
|
||||
|
@ -78,8 +78,7 @@ private:
|
|||
// Maps the first character of the emoji unicode string to a vector of possible emojis
|
||||
QMap<QChar, QVector<EmojiData>> emojiFirstByte;
|
||||
|
||||
// url Emoji-one image
|
||||
util::EmoteMap emojis;
|
||||
util::EmojiMap emojis;
|
||||
|
||||
void loadEmojis();
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
|
|||
|
||||
void EmotePopup::loadEmojis()
|
||||
{
|
||||
util::EmoteMap &emojis = singletons::EmoteManager::getInstance().getEmojis();
|
||||
auto &emojis = singletons::EmoteManager::getInstance().getEmojis();
|
||||
|
||||
ChannelPtr emojiChannel(new Channel(""));
|
||||
|
||||
|
@ -105,9 +105,9 @@ void EmotePopup::loadEmojis()
|
|||
builder.getMessage()->flags &= Message::Centered;
|
||||
builder.getMessage()->flags &= Message::DisableCompactEmotes;
|
||||
|
||||
emojis.each([this, &builder](const QString &key, const util::EmoteData &value) {
|
||||
builder.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
|
||||
->setLink(Link(Link::Type::InsertText, key)));
|
||||
emojis.each([this, &builder](const QString &key, const auto &value) {
|
||||
builder.append((new EmoteElement(value.emoteData, MessageElement::Flags::AlwaysShow))
|
||||
->setLink(Link(Link::Type::InsertText, ":" + value.shortCode + ":")));
|
||||
});
|
||||
emojiChannel->addMessage(builder.getMessage());
|
||||
|
||||
|
|
Loading…
Reference in a new issue