mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +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
56f0e5e76a
commit
3dae83e749
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "util/emotemap.hpp"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
@ -13,6 +15,14 @@ struct EmojiData {
|
||||||
|
|
||||||
// i.e. thinking
|
// i.e. thinking
|
||||||
QString shortCode;
|
QString shortCode;
|
||||||
|
|
||||||
|
util::EmoteData emoteData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
|
||||||
|
using EmojiMap = ConcurrentMap<QString, EmojiData>;
|
||||||
|
|
||||||
|
} // namespace util
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -226,7 +226,7 @@ util::EmoteMap &EmoteManager::getBTTVChannelEmoteFromCaches()
|
||||||
return _bttvChannelEmoteFromCaches;
|
return _bttvChannelEmoteFromCaches;
|
||||||
}
|
}
|
||||||
|
|
||||||
util::EmoteMap &EmoteManager::getEmojis()
|
util::EmojiMap &EmoteManager::getEmojis()
|
||||||
{
|
{
|
||||||
return this->emojis;
|
return this->emojis;
|
||||||
}
|
}
|
||||||
|
@ -277,10 +277,15 @@ void EmoteManager::loadEmojis()
|
||||||
unicodeBytes[numUnicodeBytes++] = QString(unicodeCharacter).toUInt(nullptr, 16);
|
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{
|
EmojiData emojiData{
|
||||||
QString::fromUcs4(unicodeBytes, numUnicodeBytes), //
|
QString::fromUcs4(unicodeBytes, numUnicodeBytes), //
|
||||||
code, //
|
code, //
|
||||||
shortCode, //
|
shortCode, //
|
||||||
|
{new Image(url, 0.35, ":" + shortCode + ":", ":" + shortCode + ":<br/>Emoji")},
|
||||||
};
|
};
|
||||||
|
|
||||||
this->emojiShortCodeToEmoji.insert(shortCode, emojiData);
|
this->emojiShortCodeToEmoji.insert(shortCode, emojiData);
|
||||||
|
@ -288,12 +293,7 @@ void EmoteManager::loadEmojis()
|
||||||
|
|
||||||
this->emojiFirstByte[emojiData.value.at(0)].append(emojiData);
|
this->emojiFirstByte[emojiData.value.at(0)].append(emojiData);
|
||||||
|
|
||||||
QString url = "https://cdnjs.cloudflare.com/ajax/libs/"
|
this->emojis.insert(code, emojiData);
|
||||||
"emojione/2.2.6/assets/png/" +
|
|
||||||
code + ".png";
|
|
||||||
|
|
||||||
this->emojis.insert(code, util::EmoteData(new Image(url, 0.35, ":" + shortCode + ":",
|
|
||||||
":" + shortCode + ":<br/>Emoji")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &p : this->emojiFirstByte) {
|
for (auto &p : this->emojiFirstByte) {
|
||||||
|
@ -369,17 +369,9 @@ void EmoteManager::parseEmojis(std::vector<std::tuple<util::EmoteData, QString>>
|
||||||
charactersFromLastParsedEmoji));
|
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
|
// 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;
|
lastParsedEmojiEndIndex = currentParsedEmojiEndIndex;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
util::EmoteMap &getFFZEmotes();
|
util::EmoteMap &getFFZEmotes();
|
||||||
util::EmoteMap &getChatterinoEmotes();
|
util::EmoteMap &getChatterinoEmotes();
|
||||||
util::EmoteMap &getBTTVChannelEmoteFromCaches();
|
util::EmoteMap &getBTTVChannelEmoteFromCaches();
|
||||||
util::EmoteMap &getEmojis();
|
util::EmojiMap &getEmojis();
|
||||||
util::ConcurrentMap<int, util::EmoteData> &getFFZChannelEmoteFromCaches();
|
util::ConcurrentMap<int, util::EmoteData> &getFFZChannelEmoteFromCaches();
|
||||||
util::ConcurrentMap<long, util::EmoteData> &getTwitchEmoteFromCache();
|
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
|
// Maps the first character of the emoji unicode string to a vector of possible emojis
|
||||||
QMap<QChar, QVector<EmojiData>> emojiFirstByte;
|
QMap<QChar, QVector<EmojiData>> emojiFirstByte;
|
||||||
|
|
||||||
// url Emoji-one image
|
util::EmojiMap emojis;
|
||||||
util::EmoteMap emojis;
|
|
||||||
|
|
||||||
void loadEmojis();
|
void loadEmojis();
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
|
||||||
|
|
||||||
void EmotePopup::loadEmojis()
|
void EmotePopup::loadEmojis()
|
||||||
{
|
{
|
||||||
util::EmoteMap &emojis = singletons::EmoteManager::getInstance().getEmojis();
|
auto &emojis = singletons::EmoteManager::getInstance().getEmojis();
|
||||||
|
|
||||||
ChannelPtr emojiChannel(new Channel(""));
|
ChannelPtr emojiChannel(new Channel(""));
|
||||||
|
|
||||||
|
@ -105,9 +105,9 @@ void EmotePopup::loadEmojis()
|
||||||
builder.getMessage()->flags &= Message::Centered;
|
builder.getMessage()->flags &= Message::Centered;
|
||||||
builder.getMessage()->flags &= Message::DisableCompactEmotes;
|
builder.getMessage()->flags &= Message::DisableCompactEmotes;
|
||||||
|
|
||||||
emojis.each([this, &builder](const QString &key, const util::EmoteData &value) {
|
emojis.each([this, &builder](const QString &key, const auto &value) {
|
||||||
builder.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
|
builder.append((new EmoteElement(value.emoteData, MessageElement::Flags::AlwaysShow))
|
||||||
->setLink(Link(Link::Type::InsertText, key)));
|
->setLink(Link(Link::Type::InsertText, ":" + value.shortCode + ":")));
|
||||||
});
|
});
|
||||||
emojiChannel->addMessage(builder.getMessage());
|
emojiChannel->addMessage(builder.getMessage());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue