From cc8bd538b997b0278233444814bcea0bb1e3e019 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 18 Aug 2024 12:25:01 +0200 Subject: [PATCH] refactor: Move MessageFlag(s) to its own file (#5549) --- CHANGELOG.md | 1 + src/CMakeLists.txt | 1 + src/common/Channel.hpp | 4 +- .../highlights/HighlightController.hpp | 4 +- src/messages/Message.hpp | 55 +--------------- src/messages/MessageFlag.hpp | 62 +++++++++++++++++++ .../layouts/MessageLayoutContainer.hpp | 3 +- src/widgets/helper/ChannelView.hpp | 4 +- 8 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 src/messages/MessageFlag.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 3afc6f95ac9..fc0e8a09c9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ - Dev: Refactor/unsingletonize `UserDataController`. (#5459) - Dev: Cleanup `BrowserExtension`. (#5465) - Dev: Deprecate Qt 5.12. (#5396) +- Dev: Refactored `MessageFlag` into its own file. (#5549) - Dev: The running Qt version is now shown in the about page if it differs from the compiled version. (#5501) - Dev: `FlagsEnum` is now `constexpr`. (#5510) - Dev: Documented and added tests to RTL handling. (#5473) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1998646b259..b050dec88fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -276,6 +276,7 @@ set(SOURCE_FILES messages/MessageColor.hpp messages/MessageElement.cpp messages/MessageElement.hpp + messages/MessageFlag.hpp messages/MessageThread.cpp messages/MessageThread.hpp diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index c2da9e67b75..b900abf589c 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -1,8 +1,8 @@ #pragma once -#include "common/FlagsEnum.hpp" #include "controllers/completion/TabCompletionModel.hpp" #include "messages/LimitedQueue.hpp" +#include "messages/MessageFlag.hpp" #include #include @@ -17,8 +17,6 @@ namespace chatterino { struct Message; using MessagePtr = std::shared_ptr; -enum class MessageFlag : int64_t; -using MessageFlags = FlagsEnum; enum class TimeoutStackStyle : int { StackHard = 0, diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index c217f7bb208..488f628fb31 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -1,7 +1,7 @@ #pragma once -#include "common/FlagsEnum.hpp" #include "common/UniqueAccess.hpp" +#include "messages/MessageFlag.hpp" #include "singletons/Settings.hpp" #include @@ -19,8 +19,6 @@ namespace chatterino { class Badge; struct MessageParseArgs; -enum class MessageFlag : int64_t; -using MessageFlags = FlagsEnum; class AccountController; struct HighlightResult { diff --git a/src/messages/Message.hpp b/src/messages/Message.hpp index bdbe120ddaa..898f1221789 100644 --- a/src/messages/Message.hpp +++ b/src/messages/Message.hpp @@ -1,10 +1,9 @@ #pragma once -#include "common/FlagsEnum.hpp" +#include "messages/MessageFlag.hpp" #include "providers/twitch/ChannelPointReward.hpp" #include "util/QStringHash.hpp" -#include #include #include @@ -19,53 +18,6 @@ class MessageThread; class Badge; class ScrollbarHighlight; -enum class MessageFlag : int64_t { - None = 0LL, - System = (1LL << 0), - Timeout = (1LL << 1), - Highlighted = (1LL << 2), - DoNotTriggerNotification = (1LL << 3), // disable notification sound - Centered = (1LL << 4), - Disabled = (1LL << 5), - DisableCompactEmotes = (1LL << 6), - Collapsed = (1LL << 7), - ConnectedMessage = (1LL << 8), - DisconnectedMessage = (1LL << 9), - Untimeout = (1LL << 10), - PubSub = (1LL << 11), - Subscription = (1LL << 12), - DoNotLog = (1LL << 13), - AutoMod = (1LL << 14), - RecentMessage = (1LL << 15), - Whisper = (1LL << 16), - HighlightedWhisper = (1LL << 17), - Debug = (1LL << 18), - Similar = (1LL << 19), - RedeemedHighlight = (1LL << 20), - RedeemedChannelPointReward = (1LL << 21), - ShowInMentions = (1LL << 22), - FirstMessage = (1LL << 23), - ReplyMessage = (1LL << 24), - ElevatedMessage = (1LL << 25), - SubscribedThread = (1LL << 26), - CheerMessage = (1LL << 27), - LiveUpdatesAdd = (1LL << 28), - LiveUpdatesRemove = (1LL << 29), - LiveUpdatesUpdate = (1LL << 30), - /// The header of a message caught by AutoMod containing allow/disallow - AutoModOffendingMessageHeader = (1LL << 31), - /// The message caught by AutoMod containing the user who sent the message & its contents - AutoModOffendingMessage = (1LL << 32), - LowTrustUsers = (1LL << 33), - /// The message is sent by a user marked as restricted with Twitch's "Low Trust"/"Suspicious User" feature - RestrictedMessage = (1LL << 34), - /// The message is sent by a user marked as monitor with Twitch's "Low Trust"/"Suspicious User" feature - MonitoredMessage = (1LL << 35), - /// The message is an ACTION message (/me) - Action = (1LL << 36), -}; -using MessageFlags = FlagsEnum; - struct Message; using MessagePtr = std::shared_ptr; struct Message { @@ -113,8 +65,3 @@ struct Message { }; } // namespace chatterino - -template <> -struct magic_enum::customize::enum_range { - static constexpr bool is_flags = true; -}; diff --git a/src/messages/MessageFlag.hpp b/src/messages/MessageFlag.hpp new file mode 100644 index 00000000000..7648dadc793 --- /dev/null +++ b/src/messages/MessageFlag.hpp @@ -0,0 +1,62 @@ +#pragma once + +#include "common/FlagsEnum.hpp" + +#include + +namespace chatterino { + +enum class MessageFlag : std::int64_t { + None = 0LL, + System = (1LL << 0), + Timeout = (1LL << 1), + Highlighted = (1LL << 2), + DoNotTriggerNotification = (1LL << 3), // disable notification sound + Centered = (1LL << 4), + Disabled = (1LL << 5), + DisableCompactEmotes = (1LL << 6), + Collapsed = (1LL << 7), + ConnectedMessage = (1LL << 8), + DisconnectedMessage = (1LL << 9), + Untimeout = (1LL << 10), + PubSub = (1LL << 11), + Subscription = (1LL << 12), + DoNotLog = (1LL << 13), + AutoMod = (1LL << 14), + RecentMessage = (1LL << 15), + Whisper = (1LL << 16), + HighlightedWhisper = (1LL << 17), + Debug = (1LL << 18), + Similar = (1LL << 19), + RedeemedHighlight = (1LL << 20), + RedeemedChannelPointReward = (1LL << 21), + ShowInMentions = (1LL << 22), + FirstMessage = (1LL << 23), + ReplyMessage = (1LL << 24), + ElevatedMessage = (1LL << 25), + SubscribedThread = (1LL << 26), + CheerMessage = (1LL << 27), + LiveUpdatesAdd = (1LL << 28), + LiveUpdatesRemove = (1LL << 29), + LiveUpdatesUpdate = (1LL << 30), + /// The header of a message caught by AutoMod containing allow/disallow + AutoModOffendingMessageHeader = (1LL << 31), + /// The message caught by AutoMod containing the user who sent the message & its contents + AutoModOffendingMessage = (1LL << 32), + LowTrustUsers = (1LL << 33), + /// The message is sent by a user marked as restricted with Twitch's "Low Trust"/"Suspicious User" feature + RestrictedMessage = (1LL << 34), + /// The message is sent by a user marked as monitor with Twitch's "Low Trust"/"Suspicious User" feature + MonitoredMessage = (1LL << 35), + /// The message is an ACTION message (/me) + Action = (1LL << 36), +}; +using MessageFlags = FlagsEnum; + +} // namespace chatterino + +template <> +struct magic_enum::customize::enum_range { + // NOLINTNEXTLINE(readability-identifier-naming) + static constexpr bool is_flags = true; +}; diff --git a/src/messages/layouts/MessageLayoutContainer.hpp b/src/messages/layouts/MessageLayoutContainer.hpp index 7c14faf40af..1cd7f6af2c2 100644 --- a/src/messages/layouts/MessageLayoutContainer.hpp +++ b/src/messages/layouts/MessageLayoutContainer.hpp @@ -2,6 +2,7 @@ #include "common/Common.hpp" #include "common/FlagsEnum.hpp" +#include "messages/MessageFlag.hpp" #include #include @@ -24,8 +25,6 @@ enum class TextDirection : uint8_t { LTR, }; -enum class MessageFlag : int64_t; -using MessageFlags = FlagsEnum; class MessageLayoutElement; struct Selection; struct MessagePaintContext; diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index a670d6e3074..f9f68bc2c1c 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -4,6 +4,7 @@ #include "messages/layouts/MessageLayoutContext.hpp" #include "messages/LimitedQueue.hpp" #include "messages/LimitedQueueSnapshot.hpp" +#include "messages/MessageFlag.hpp" #include "messages/Selection.hpp" #include "util/ThreadGuard.hpp" #include "widgets/BaseWidget.hpp" @@ -32,9 +33,6 @@ using ChannelPtr = std::shared_ptr; struct Message; using MessagePtr = std::shared_ptr; -enum class MessageFlag : int64_t; -using MessageFlags = FlagsEnum; - class MessageLayout; using MessageLayoutPtr = std::shared_ptr;