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

chore: ensure statics are only present once in the final app #5588

Merged
merged 15 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -86,6 +86,7 @@
- Dev: Recent changes are now shown in the nightly release description. (#5553, #5554)
- Dev: The timer for `StreamerMode` is now destroyed on the correct thread. (#5571)
- Dev: Cleanup some parts of the `magic_enum` adaptation for Qt. (#5587)
- Dev: Refactored `static`s in headers to only be present once in the final app. (#5588)

## 2.5.1

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ set(SOURCE_FILES
providers/twitch/TwitchBadges.hpp
providers/twitch/TwitchChannel.cpp
providers/twitch/TwitchChannel.hpp
providers/twitch/TwitchCommon.cpp
providers/twitch/TwitchCommon.hpp
providers/twitch/TwitchEmotes.cpp
providers/twitch/TwitchEmotes.hpp
providers/twitch/TwitchHelpers.cpp
Expand Down
17 changes: 9 additions & 8 deletions src/common/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

namespace chatterino {

constexpr QStringView LINK_CHATTERINO_WIKI = u"https://wiki.chatterino.com";
constexpr QStringView LINK_CHATTERINO_DISCORD =
inline constexpr QStringView LINK_CHATTERINO_WIKI =
u"https://wiki.chatterino.com";
inline constexpr QStringView LINK_CHATTERINO_DISCORD =
u"https://discord.gg/7Y5AYhAK4z";
constexpr QStringView LINK_CHATTERINO_SOURCE =
inline constexpr QStringView LINK_CHATTERINO_SOURCE =
u"https://github.com/Chatterino/chatterino2";

constexpr QStringView TWITCH_PLAYER_URL =
inline constexpr QStringView TWITCH_PLAYER_URL =
u"https://player.twitch.tv/?channel=%1&parent=twitch.tv";

enum class HighlightState {
Expand All @@ -23,14 +24,14 @@ enum class HighlightState {
NewMessage,
};

constexpr Qt::KeyboardModifiers SHOW_SPLIT_OVERLAY_MODIFIERS =
inline constexpr Qt::KeyboardModifiers SHOW_SPLIT_OVERLAY_MODIFIERS =
Qt::ControlModifier | Qt::AltModifier;
constexpr Qt::KeyboardModifiers SHOW_ADD_SPLIT_REGIONS =
inline constexpr Qt::KeyboardModifiers SHOW_ADD_SPLIT_REGIONS =
Qt::ControlModifier | Qt::AltModifier;
constexpr Qt::KeyboardModifiers SHOW_RESIZE_HANDLES_MODIFIERS =
inline constexpr Qt::KeyboardModifiers SHOW_RESIZE_HANDLES_MODIFIERS =
Qt::ControlModifier;

constexpr const char *ANONYMOUS_USERNAME_LABEL = " - anonymous - ";
inline constexpr const char *ANONYMOUS_USERNAME_LABEL = " - anonymous - ";

template <typename T>
std::weak_ptr<T> weakOf(T *element)
Expand Down
32 changes: 32 additions & 0 deletions src/controllers/filters/lang/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@

namespace chatterino::filters {

const QMap<QString, Type> MESSAGE_TYPING_CONTEXT = {
{"author.badges", Type::StringList},
{"author.color", Type::Color},
{"author.name", Type::String},
{"author.no_color", Type::Bool},
{"author.subbed", Type::Bool},
{"author.sub_length", Type::Int},
{"channel.name", Type::String},
{"channel.watching", Type::Bool},
{"channel.live", Type::Bool},
{"flags.action", Type::Bool},
{"flags.highlighted", Type::Bool},
{"flags.points_redeemed", Type::Bool},
{"flags.sub_message", Type::Bool},
{"flags.system_message", Type::Bool},
{"flags.reward_message", Type::Bool},
{"flags.first_message", Type::Bool},
{"flags.elevated_message", Type::Bool},
{"flags.hype_chat", Type::Bool},
{"flags.cheer_message", Type::Bool},
{"flags.whisper", Type::Bool},
{"flags.reply", Type::Bool},
{"flags.automod", Type::Bool},
{"flags.restricted", Type::Bool},
{"flags.monitored", Type::Bool},
{"message.content", Type::String},
{"message.length", Type::Int},
{"reward.title", Type::String},
{"reward.cost", Type::Int},
{"reward.id", Type::String},
};

ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
{
auto watchingChannel = getApp()->getTwitch()->getWatchingChannel().get();
Expand Down
32 changes: 1 addition & 31 deletions src/controllers/filters/lang/Filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,7 @@ namespace chatterino::filters {
// For example, flags.highlighted is a boolean variable, so it is marked as Type::Bool
// below. These variable types will be used to check whether a filter "makes sense",
// i.e. if all the variables and operators being used have compatible types.
static const QMap<QString, Type> MESSAGE_TYPING_CONTEXT = {
{"author.badges", Type::StringList},
{"author.color", Type::Color},
{"author.name", Type::String},
{"author.no_color", Type::Bool},
{"author.subbed", Type::Bool},
{"author.sub_length", Type::Int},
{"channel.name", Type::String},
{"channel.watching", Type::Bool},
{"channel.live", Type::Bool},
{"flags.action", Type::Bool},
{"flags.highlighted", Type::Bool},
{"flags.points_redeemed", Type::Bool},
{"flags.sub_message", Type::Bool},
{"flags.system_message", Type::Bool},
{"flags.reward_message", Type::Bool},
{"flags.first_message", Type::Bool},
{"flags.elevated_message", Type::Bool},
{"flags.hype_chat", Type::Bool},
{"flags.cheer_message", Type::Bool},
{"flags.whisper", Type::Bool},
{"flags.reply", Type::Bool},
{"flags.automod", Type::Bool},
{"flags.restricted", Type::Bool},
{"flags.monitored", Type::Bool},
{"message.content", Type::String},
{"message.length", Type::Int},
{"reward.title", Type::String},
{"reward.cost", Type::Int},
{"reward.id", Type::String},
};
extern const QMap<QString, Type> MESSAGE_TYPING_CONTEXT;

ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel);

Expand Down
48 changes: 47 additions & 1 deletion src/controllers/filters/lang/Tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,54 @@

#include "common/QLogging.hpp"

namespace {

const QRegularExpression TOKEN_REGEX(
"((r|ri)?\\\")((\\\\\")|[^\\\"])*\\\"|" // String/Regex literal
"[\\w\\.]+|" // Identifier or reserved keyword
"(<=?|>=?|!=?|==|\\|\\||&&|\\+|-|\\*|\\/|%)+|" // Operator
"[\\(\\)]|" // Parentheses
"[{},]" // List
);

} // namespace

namespace chatterino::filters {

const QMap<QString, QString> validIdentifiersMap = {
{"author.badges", "author badges"},
{"author.color", "author color"},
{"author.name", "author name"},
{"author.no_color", "author has no color?"},
{"author.subbed", "author subscribed?"},
{"author.sub_length", "author sub length"},
{"channel.name", "channel name"},
{"channel.watching", "/watching channel?"},
{"channel.live", "channel live?"},
{"flags.action", "action/me message?"},
{"flags.highlighted", "highlighted?"},
{"flags.points_redeemed", "redeemed points?"},
{"flags.sub_message", "sub/resub message?"},
{"flags.system_message", "system message?"},
{"flags.reward_message", "channel point reward message?"},
{"flags.first_message", "first message?"},
{"flags.elevated_message", "hype chat message?"},
// Ideally these values are unique, because ChannelFilterEditorDialog::ValueSpecifier::expressionText depends on
// std::map layout in Qt 6 and internal implementation in Qt 5.
{"flags.hype_chat", "hype chat message?"},
{"flags.cheer_message", "cheer message?"},
{"flags.whisper", "whisper message?"},
{"flags.reply", "reply message?"},
{"flags.automod", "automod message?"},
{"flags.restricted", "restricted message?"},
{"flags.monitored", "monitored message?"},
{"message.content", "message text"},
{"message.length", "message length"},
{"reward.title", "point reward title"},
{"reward.cost", "point reward cost"},
{"reward.id", "point reward id"},
};

QString tokenTypeToInfoString(TokenType type)
{
switch (type)
Expand Down Expand Up @@ -77,7 +123,7 @@ QString tokenTypeToInfoString(TokenType type)

Tokenizer::Tokenizer(const QString &text)
{
QRegularExpressionMatchIterator i = tokenRegex.globalMatch(text);
QRegularExpressionMatchIterator i = TOKEN_REGEX.globalMatch(text);
while (i.hasNext())
{
auto capturedText = i.next().captured();
Expand Down
44 changes: 1 addition & 43 deletions src/controllers/filters/lang/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,7 @@

namespace chatterino::filters {

static const QMap<QString, QString> validIdentifiersMap = {
{"author.badges", "author badges"},
{"author.color", "author color"},
{"author.name", "author name"},
{"author.no_color", "author has no color?"},
{"author.subbed", "author subscribed?"},
{"author.sub_length", "author sub length"},
{"channel.name", "channel name"},
{"channel.watching", "/watching channel?"},
{"channel.live", "channel live?"},
{"flags.action", "action/me message?"},
{"flags.highlighted", "highlighted?"},
{"flags.points_redeemed", "redeemed points?"},
{"flags.sub_message", "sub/resub message?"},
{"flags.system_message", "system message?"},
{"flags.reward_message", "channel point reward message?"},
{"flags.first_message", "first message?"},
{"flags.elevated_message", "hype chat message?"},
// Ideally these values are unique, because ChannelFilterEditorDialog::ValueSpecifier::expressionText depends on
// std::map layout in Qt 6 and internal implementation in Qt 5.
{"flags.hype_chat", "hype chat message?"},
{"flags.cheer_message", "cheer message?"},
{"flags.whisper", "whisper message?"},
{"flags.reply", "reply message?"},
{"flags.automod", "automod message?"},
{"flags.restricted", "restricted message?"},
{"flags.monitored", "monitored message?"},
{"message.content", "message text"},
{"message.length", "message length"},
{"reward.title", "point reward title"},
{"reward.cost", "point reward cost"},
{"reward.id", "point reward id"},
};

// clang-format off
static const QRegularExpression tokenRegex(
QString("((r|ri)?\\\")((\\\\\")|[^\\\"])*\\\"|") + // String/Regex literal
QString("[\\w\\.]+|") + // Identifier or reserved keyword
QString("(<=?|>=?|!=?|==|\\|\\||&&|\\+|-|\\*|\\/|%)+|") + // Operator
QString("[\\(\\)]|") + // Parentheses
QString("[{},]") // List
);
// clang-format on
extern const QMap<QString, QString> validIdentifiersMap;
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved
Nerixyz marked this conversation as resolved.
Show resolved Hide resolved

enum TokenType {
// control
Expand Down
2 changes: 1 addition & 1 deletion src/messages/Emote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EmoteMap : public std::unordered_map<EmoteName, EmotePtr>
const QString &emoteID) const;
};

static const std::shared_ptr<const EmoteMap> EMPTY_EMOTE_MAP = std::make_shared<
const std::shared_ptr<const EmoteMap> EMPTY_EMOTE_MAP = std::make_shared<
const EmoteMap>(); // NOLINT(cert-err58-cpp) -- assume this doesn't throw an exception

EmotePtr cachedOrMakeEmotePtr(Emote &&emote, const EmoteMap &cache);
Expand Down
14 changes: 4 additions & 10 deletions src/providers/twitch/TwitchChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ namespace chatterino {
// instead.
// See https://github.com/Chatterino/chatterino2/issues/3384 and
// https://mm2pl.github.io/emoji_rfc.pdf for more details
const QString ZERO_WIDTH_JOINER = QString(QChar(0x200D));
const QString ZERO_WIDTH_JOINER = QStringLiteral("\u200D");

// Here be MSVC: Do NOT replace with "\U" literal, it will fail silently.
namespace {
const QChar ESCAPE_TAG_CHARS[2] = {QChar::highSurrogate(0xE0002),
QChar::lowSurrogate(0xE0002)};
}
const QString ESCAPE_TAG = QString(ESCAPE_TAG_CHARS, 2);

const static QRegularExpression COMBINED_FIXER(
QString("(?<!%1)%1").arg(ESCAPE_TAG),
// Note: \U requires /utf-8 for MSVC
const QRegularExpression COMBINED_FIXER(
QStringLiteral("(?<!\U000E0002)\U000E0002"),
QRegularExpression::UseUnicodePropertiesOption);

enum class HighlightState;
Expand Down
63 changes: 63 additions & 0 deletions src/providers/twitch/TwitchCommon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "providers/twitch/TwitchCommon.hpp"

namespace chatterino {

const std::vector<QColor> TWITCH_USERNAME_COLORS = {
{255, 0, 0}, // Red
{0, 0, 255}, // Blue
{0, 255, 0}, // Green
{178, 34, 34}, // FireBrick
{255, 127, 80}, // Coral
{154, 205, 50}, // YellowGreen
{255, 69, 0}, // OrangeRed
{46, 139, 87}, // SeaGreen
{218, 165, 32}, // GoldenRod
{210, 105, 30}, // Chocolate
{95, 158, 160}, // CadetBlue
{30, 144, 255}, // DodgerBlue
{255, 105, 180}, // HotPink
{138, 43, 226}, // BlueViolet
{0, 255, 127}, // SpringGreen
};

const QStringList TWITCH_DEFAULT_COMMANDS{
"help",
"w",
"me",
"disconnect",
"mods",
"vips",
"color",
"commercial",
"mod",
"unmod",
"vip",
"unvip",
"ban",
"unban",
"timeout",
"untimeout",
"slow",
"slowoff",
"r9kbeta",
"r9kbetaoff",
"emoteonly",
"emoteonlyoff",
"clear",
"subscribers",
"subscribersoff",
"followers",
"followersoff",
"host",
"unhost",
"raid",
"unraid",
"delete",
"announce",
"requests",
"warn",
};

const QStringList TWITCH_WHISPER_COMMANDS{"/w", ".w"};

} // namespace chatterino
Loading
Loading