Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
- 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: `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

Expand Down
17 changes: 11 additions & 6 deletions src/providers/emoji/Emojis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/variant.hpp>
Expand Down Expand Up @@ -62,19 +63,19 @@ void parseEmoji(const std::shared_ptr<EmojiData> &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('-');
Expand Down Expand Up @@ -244,6 +245,10 @@ void Emojis::sortEmojis()
void Emojis::loadEmojiSet()
{
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)
{
QString emojiSetToUse = emojiSet;
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 11 additions & 2 deletions src/providers/emoji/Emojis.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include "common/FlagsEnum.hpp"

#include <boost/variant.hpp>
#include <QMap>
#include <QRegularExpression>
#include <QVector>

#include <memory>
#include <set>
#include <vector>

namespace chatterino {
Expand All @@ -29,7 +30,15 @@ struct EmojiData {
// i.e. thinking
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;

Expand Down
Loading