From f5a8ea4cbf8bccb95a14f8c8be344f4af8a7c606 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 5 Oct 2024 15:18:54 +0200 Subject: [PATCH] fix(emoji): use flags over strings for capabilities (#5616) --- CHANGELOG.md | 1 + src/providers/emoji/Emojis.cpp | 17 +++++++++++------ src/providers/emoji/Emojis.hpp | 13 +++++++++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d35bfb744..a6514d6dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ - Dev: The JSON output when copying a message (SHIFT + 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: `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 diff --git a/src/providers/emoji/Emojis.cpp b/src/providers/emoji/Emojis.cpp index eefdd827e..562c74026 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -4,6 +4,7 @@ #include "messages/Emote.hpp" #include "messages/Image.hpp" #include "singletons/Settings.hpp" +#include "util/QMagicEnum.hpp" #include "util/RapidjsonHelpers.hpp" #include @@ -62,19 +63,19 @@ void parseEmoji(const std::shared_ptr &emojiData, if (capabilities.apple) { - emojiData->capabilities.insert("Apple"); + emojiData->capabilities.set(EmojiData::Capability::Apple); } if (capabilities.google) { - emojiData->capabilities.insert("Google"); + emojiData->capabilities.set(EmojiData::Capability::Google); } if (capabilities.twitter) { - emojiData->capabilities.insert("Twitter"); + emojiData->capabilities.set(EmojiData::Capability::Twitter); } if (capabilities.facebook) { - emojiData->capabilities.insert("Facebook"); + emojiData->capabilities.set(EmojiData::Capability::Facebook); } QStringList unicodeCharacters = emojiData->unifiedCode.toLower().split('-'); @@ -244,6 +245,10 @@ void Emojis::sortEmojis() void Emojis::loadEmojiSet() { getSettings()->emojiSet.connect([this](const auto &emojiSet) { + EmojiData::Capability setCapability = + qmagicenum::enumCast(emojiSet).value_or( + EmojiData::Capability::Google); + for (const auto &emoji : this->emojis) { QString emojiSetToUse = emojiSet; @@ -271,9 +276,9 @@ void Emojis::loadEmojiSet() // clang-format on // 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(); diff --git a/src/providers/emoji/Emojis.hpp b/src/providers/emoji/Emojis.hpp index d6d783fc5..bbc5b747f 100644 --- a/src/providers/emoji/Emojis.hpp +++ b/src/providers/emoji/Emojis.hpp @@ -1,12 +1,13 @@ #pragma once +#include "common/FlagsEnum.hpp" + #include #include #include #include #include -#include #include namespace chatterino { @@ -29,7 +30,15 @@ struct EmojiData { // i.e. thinking std::vector shortCodes; - std::set capabilities; + enum class Capability : uint8_t { + Apple = 1 << 0, + Google = 1 << 1, + Twitter = 1 << 2, + Facebook = 1 << 3, + }; + using Capabilities = FlagsEnum; + + Capabilities capabilities; std::vector variations;