fix(emoji): use flags over strings for capabilities (#5616)

This commit is contained in:
nerix 2024-10-05 15:18:54 +02:00 committed by GitHub
parent 2d7f515e5a
commit f5a8ea4cbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 8 deletions

View file

@ -99,6 +99,7 @@
- Dev: The JSON output when copying a message (<kbd>SHIFT</kbd> + right-click) is now more extensive. (#5600) - Dev: The JSON output when copying a message (<kbd>SHIFT</kbd> + right-click) is now more extensive. (#5600)
- Dev: Twitch messages are now sent using Twitch's Helix API instead of IRC by default. (#5607) - Dev: Twitch messages are now sent using Twitch's Helix API instead of IRC by default. (#5607)
- Dev: `GIFTimer` is no longer initialized in tests. (#5608) - Dev: `GIFTimer` is no longer initialized in tests. (#5608)
- Dev: Emojis now use flags instead of a set of strings for capabilities. (#5616)
## 2.5.1 ## 2.5.1

View file

@ -4,6 +4,7 @@
#include "messages/Emote.hpp" #include "messages/Emote.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "util/QMagicEnum.hpp"
#include "util/RapidjsonHelpers.hpp" #include "util/RapidjsonHelpers.hpp"
#include <boost/variant.hpp> #include <boost/variant.hpp>
@ -62,19 +63,19 @@ void parseEmoji(const std::shared_ptr<EmojiData> &emojiData,
if (capabilities.apple) if (capabilities.apple)
{ {
emojiData->capabilities.insert("Apple"); emojiData->capabilities.set(EmojiData::Capability::Apple);
} }
if (capabilities.google) if (capabilities.google)
{ {
emojiData->capabilities.insert("Google"); emojiData->capabilities.set(EmojiData::Capability::Google);
} }
if (capabilities.twitter) if (capabilities.twitter)
{ {
emojiData->capabilities.insert("Twitter"); emojiData->capabilities.set(EmojiData::Capability::Twitter);
} }
if (capabilities.facebook) if (capabilities.facebook)
{ {
emojiData->capabilities.insert("Facebook"); emojiData->capabilities.set(EmojiData::Capability::Facebook);
} }
QStringList unicodeCharacters = emojiData->unifiedCode.toLower().split('-'); QStringList unicodeCharacters = emojiData->unifiedCode.toLower().split('-');
@ -244,6 +245,10 @@ void Emojis::sortEmojis()
void Emojis::loadEmojiSet() void Emojis::loadEmojiSet()
{ {
getSettings()->emojiSet.connect([this](const auto &emojiSet) { getSettings()->emojiSet.connect([this](const auto &emojiSet) {
EmojiData::Capability setCapability =
qmagicenum::enumCast<EmojiData::Capability>(emojiSet).value_or(
EmojiData::Capability::Google);
for (const auto &emoji : this->emojis) for (const auto &emoji : this->emojis)
{ {
QString emojiSetToUse = emojiSet; QString emojiSetToUse = emojiSet;
@ -271,9 +276,9 @@ void Emojis::loadEmojiSet()
// clang-format on // clang-format on
// As of emoji-data v15.1.1, google is the only source missing no images. // As of emoji-data v15.1.1, google is the only source missing no images.
if (!emoji->capabilities.contains(emojiSetToUse)) if (!emoji->capabilities.has(setCapability))
{ {
emojiSetToUse = "Google"; emojiSetToUse = QStringLiteral("Google");
} }
QString code = emoji->unifiedCode.toLower(); QString code = emoji->unifiedCode.toLower();

View file

@ -1,12 +1,13 @@
#pragma once #pragma once
#include "common/FlagsEnum.hpp"
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <QMap> #include <QMap>
#include <QRegularExpression> #include <QRegularExpression>
#include <QVector> #include <QVector>
#include <memory> #include <memory>
#include <set>
#include <vector> #include <vector>
namespace chatterino { namespace chatterino {
@ -29,7 +30,15 @@ struct EmojiData {
// i.e. thinking // i.e. thinking
std::vector<QString> shortCodes; std::vector<QString> shortCodes;
std::set<QString> capabilities; enum class Capability : uint8_t {
Apple = 1 << 0,
Google = 1 << 1,
Twitter = 1 << 2,
Facebook = 1 << 3,
};
using Capabilities = FlagsEnum<Capability>;
Capabilities capabilities;
std::vector<EmojiData> variations; std::vector<EmojiData> variations;