refactor: split some highlight structs away from HighlightController (#6613)

This commit is contained in:
pajlada
2025-11-30 14:31:50 +01:00
committed by GitHub
parent 292f0dffca
commit d3287a615b
11 changed files with 213 additions and 148 deletions
@@ -1,7 +1,8 @@
#pragma once
#include "common/FlagsEnum.hpp"
#include "common/UniqueAccess.hpp"
#include "messages/MessageFlag.hpp"
#include "controllers/highlights/HighlightCheck.hpp"
#include "singletons/Settings.hpp"
#include <boost/signals2/connection.hpp>
@@ -10,6 +11,7 @@
#include <QColor>
#include <QUrl>
#include <cstdint>
#include <functional>
#include <memory>
#include <optional>
@@ -20,68 +22,8 @@ namespace chatterino {
class Badge;
struct MessageParseArgs;
class AccountController;
struct HighlightResult {
HighlightResult(bool _alert, bool _playSound,
std::optional<QUrl> _customSoundUrl,
std::shared_ptr<QColor> _color, bool _showInMentions);
/**
* @brief Construct an empty HighlightResult with all side-effects disabled
**/
static HighlightResult emptyResult();
/**
* @brief true if highlight should trigger the taskbar to flash
**/
bool alert{false};
/**
* @brief true if highlight should play a notification sound
**/
bool playSound{false};
/**
* @brief Can be set to a different sound that should play when this highlight is activated
*
* May only be set if playSound is true
**/
std::optional<QUrl> customSoundUrl{};
/**
* @brief set if highlight should set a background color
**/
std::shared_ptr<QColor> color{};
/**
* @brief true if highlight should show message in the /mentions split
**/
bool showInMentions{false};
bool operator==(const HighlightResult &other) const;
bool operator!=(const HighlightResult &other) const;
/**
* @brief Returns true if no side-effect has been enabled
**/
[[nodiscard]] bool empty() const;
/**
* @brief Returns true if all side-effects have been enabled
**/
[[nodiscard]] bool full() const;
friend std::ostream &operator<<(std::ostream &os,
const HighlightResult &result);
};
struct HighlightCheck {
using Checker = std::function<std::optional<HighlightResult>(
const MessageParseArgs &args, const std::vector<Badge> &badges,
const QString &senderName, const QString &originalMessage,
const MessageFlags &messageFlags, bool self)>;
Checker cb;
};
enum class MessageFlag : std::int64_t;
using MessageFlags = FlagsEnum<MessageFlag>;
class HighlightController final
{