Skip to content

Commit

Permalink
refactor: Move MessageFlag(s) to its own file (#5549)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Aug 18, 2024
1 parent 66c3bc2 commit cc8bd53
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions src/common/Channel.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "common/FlagsEnum.hpp"
#include "controllers/completion/TabCompletionModel.hpp"
#include "messages/LimitedQueue.hpp"
#include "messages/MessageFlag.hpp"

#include <magic_enum/magic_enum.hpp>
#include <pajlada/signals/signal.hpp>
Expand All @@ -17,8 +17,6 @@ namespace chatterino {

struct Message;
using MessagePtr = std::shared_ptr<const Message>;
enum class MessageFlag : int64_t;
using MessageFlags = FlagsEnum<MessageFlag>;

enum class TimeoutStackStyle : int {
StackHard = 0,
Expand Down
4 changes: 1 addition & 3 deletions src/controllers/highlights/HighlightController.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "common/FlagsEnum.hpp"
#include "common/UniqueAccess.hpp"
#include "messages/MessageFlag.hpp"
#include "singletons/Settings.hpp"

#include <boost/signals2/connection.hpp>
Expand All @@ -19,8 +19,6 @@ namespace chatterino {

class Badge;
struct MessageParseArgs;
enum class MessageFlag : int64_t;
using MessageFlags = FlagsEnum<MessageFlag>;
class AccountController;

struct HighlightResult {
Expand Down
55 changes: 1 addition & 54 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once

#include "common/FlagsEnum.hpp"
#include "messages/MessageFlag.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "util/QStringHash.hpp"

#include <magic_enum/magic_enum.hpp>
#include <QColor>
#include <QTime>

Expand All @@ -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<MessageFlag>;

struct Message;
using MessagePtr = std::shared_ptr<const Message>;
struct Message {
Expand Down Expand Up @@ -113,8 +65,3 @@ struct Message {
};

} // namespace chatterino

template <>
struct magic_enum::customize::enum_range<chatterino::MessageFlag> {
static constexpr bool is_flags = true;
};
62 changes: 62 additions & 0 deletions src/messages/MessageFlag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include "common/FlagsEnum.hpp"

#include <magic_enum/magic_enum.hpp>

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<MessageFlag>;

} // namespace chatterino

template <>
struct magic_enum::customize::enum_range<chatterino::MessageFlag> {
// NOLINTNEXTLINE(readability-identifier-naming)
static constexpr bool is_flags = true;
};
3 changes: 1 addition & 2 deletions src/messages/layouts/MessageLayoutContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "common/Common.hpp"
#include "common/FlagsEnum.hpp"
#include "messages/MessageFlag.hpp"

#include <QPoint>
#include <QRect>
Expand All @@ -24,8 +25,6 @@ enum class TextDirection : uint8_t {
LTR,
};

enum class MessageFlag : int64_t;
using MessageFlags = FlagsEnum<MessageFlag>;
class MessageLayoutElement;
struct Selection;
struct MessagePaintContext;
Expand Down
4 changes: 1 addition & 3 deletions src/widgets/helper/ChannelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -32,9 +33,6 @@ using ChannelPtr = std::shared_ptr<Channel>;
struct Message;
using MessagePtr = std::shared_ptr<const Message>;

enum class MessageFlag : int64_t;
using MessageFlags = FlagsEnum<MessageFlag>;

class MessageLayout;
using MessageLayoutPtr = std::shared_ptr<MessageLayout>;

Expand Down

0 comments on commit cc8bd53

Please sign in to comment.