refactor: split some highlight structs away from HighlightController (#6613)
This commit is contained in:
@@ -197,12 +197,15 @@ set(SOURCE_FILES
|
|||||||
controllers/highlights/HighlightBadge.hpp
|
controllers/highlights/HighlightBadge.hpp
|
||||||
controllers/highlights/HighlightBlacklistModel.cpp
|
controllers/highlights/HighlightBlacklistModel.cpp
|
||||||
controllers/highlights/HighlightBlacklistModel.hpp
|
controllers/highlights/HighlightBlacklistModel.hpp
|
||||||
|
controllers/highlights/HighlightCheck.hpp
|
||||||
controllers/highlights/HighlightController.cpp
|
controllers/highlights/HighlightController.cpp
|
||||||
controllers/highlights/HighlightController.hpp
|
controllers/highlights/HighlightController.hpp
|
||||||
controllers/highlights/HighlightModel.cpp
|
controllers/highlights/HighlightModel.cpp
|
||||||
controllers/highlights/HighlightModel.hpp
|
controllers/highlights/HighlightModel.hpp
|
||||||
controllers/highlights/HighlightPhrase.cpp
|
controllers/highlights/HighlightPhrase.cpp
|
||||||
controllers/highlights/HighlightPhrase.hpp
|
controllers/highlights/HighlightPhrase.hpp
|
||||||
|
controllers/highlights/HighlightResult.cpp
|
||||||
|
controllers/highlights/HighlightResult.hpp
|
||||||
controllers/highlights/UserHighlightModel.cpp
|
controllers/highlights/UserHighlightModel.cpp
|
||||||
controllers/highlights/UserHighlightModel.hpp
|
controllers/highlights/UserHighlightModel.hpp
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/FlagsEnum.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
#include <optional>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class QString;
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
struct HighlightResult;
|
||||||
|
struct MessageParseArgs;
|
||||||
|
class Badge;
|
||||||
|
|
||||||
|
enum class MessageFlag : std::int64_t;
|
||||||
|
using MessageFlags = FlagsEnum<MessageFlag>;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
@@ -4,13 +4,14 @@
|
|||||||
#include "common/QLogging.hpp"
|
#include "common/QLogging.hpp"
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
#include "controllers/highlights/HighlightBadge.hpp"
|
#include "controllers/highlights/HighlightBadge.hpp"
|
||||||
|
#include "controllers/highlights/HighlightCheck.hpp"
|
||||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||||
|
#include "controllers/highlights/HighlightResult.hpp"
|
||||||
#include "messages/Message.hpp"
|
#include "messages/Message.hpp"
|
||||||
#include "messages/MessageBuilder.hpp"
|
#include "messages/MessageBuilder.hpp"
|
||||||
#include "providers/colors/ColorProvider.hpp"
|
#include "providers/colors/ColorProvider.hpp"
|
||||||
#include "providers/twitch/TwitchAccount.hpp"
|
#include "providers/twitch/TwitchAccount.hpp" // IWYU pragma: keep
|
||||||
#include "providers/twitch/TwitchBadge.hpp"
|
#include "providers/twitch/TwitchBadge.hpp"
|
||||||
#include "singletons/Paths.hpp"
|
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -359,89 +360,6 @@ void rebuildBadgeHighlights(Settings &settings,
|
|||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
HighlightResult::HighlightResult(bool _alert, bool _playSound,
|
|
||||||
std::optional<QUrl> _customSoundUrl,
|
|
||||||
std::shared_ptr<QColor> _color,
|
|
||||||
bool _showInMentions)
|
|
||||||
: alert(_alert)
|
|
||||||
, playSound(_playSound)
|
|
||||||
, customSoundUrl(std::move(_customSoundUrl))
|
|
||||||
, color(std::move(_color))
|
|
||||||
, showInMentions(_showInMentions)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HighlightResult HighlightResult::emptyResult()
|
|
||||||
{
|
|
||||||
return {
|
|
||||||
false, false, std::nullopt, nullptr, false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HighlightResult::operator==(const HighlightResult &other) const
|
|
||||||
{
|
|
||||||
if (this->alert != other.alert)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this->playSound != other.playSound)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this->customSoundUrl != other.customSoundUrl)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->color && other.color)
|
|
||||||
{
|
|
||||||
if (*this->color != *other.color)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->showInMentions != other.showInMentions)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HighlightResult::operator!=(const HighlightResult &other) const
|
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HighlightResult::empty() const
|
|
||||||
{
|
|
||||||
return !this->alert && !this->playSound &&
|
|
||||||
!this->customSoundUrl.has_value() && !this->color &&
|
|
||||||
!this->showInMentions;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HighlightResult::full() const
|
|
||||||
{
|
|
||||||
return this->alert && this->playSound && this->customSoundUrl.has_value() &&
|
|
||||||
this->color && this->showInMentions;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const HighlightResult &result)
|
|
||||||
{
|
|
||||||
os << "Alert: " << (result.alert ? "Yes" : "No") << ", "
|
|
||||||
<< "Play sound: " << (result.playSound ? "Yes" : "No") << " ("
|
|
||||||
<< (result.customSoundUrl
|
|
||||||
? result.customSoundUrl->toString().toStdString()
|
|
||||||
: "")
|
|
||||||
<< ")"
|
|
||||||
<< ", "
|
|
||||||
<< "Color: " << (result.color ? result.color->name().toStdString() : "")
|
|
||||||
<< ", "
|
|
||||||
<< "Show in mentions: " << (result.showInMentions ? "Yes" : "No");
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
HighlightController::HighlightController(Settings &settings,
|
HighlightController::HighlightController(Settings &settings,
|
||||||
AccountController *accounts)
|
AccountController *accounts)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/FlagsEnum.hpp"
|
||||||
#include "common/UniqueAccess.hpp"
|
#include "common/UniqueAccess.hpp"
|
||||||
#include "messages/MessageFlag.hpp"
|
#include "controllers/highlights/HighlightCheck.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
|
||||||
#include <boost/signals2/connection.hpp>
|
#include <boost/signals2/connection.hpp>
|
||||||
@@ -10,6 +11,7 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -20,68 +22,8 @@ namespace chatterino {
|
|||||||
class Badge;
|
class Badge;
|
||||||
struct MessageParseArgs;
|
struct MessageParseArgs;
|
||||||
class AccountController;
|
class AccountController;
|
||||||
|
enum class MessageFlag : std::int64_t;
|
||||||
struct HighlightResult {
|
using MessageFlags = FlagsEnum<MessageFlag>;
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
class HighlightController final
|
class HighlightController final
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
#include "controllers/highlights/HighlightResult.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
HighlightResult::HighlightResult(bool _alert, bool _playSound,
|
||||||
|
std::optional<QUrl> _customSoundUrl,
|
||||||
|
std::shared_ptr<QColor> _color,
|
||||||
|
bool _showInMentions)
|
||||||
|
: alert(_alert)
|
||||||
|
, playSound(_playSound)
|
||||||
|
, customSoundUrl(std::move(_customSoundUrl))
|
||||||
|
, color(std::move(_color))
|
||||||
|
, showInMentions(_showInMentions)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HighlightResult HighlightResult::emptyResult()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
false, false, std::nullopt, nullptr, false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlightResult::operator==(const HighlightResult &other) const
|
||||||
|
{
|
||||||
|
if (this->alert != other.alert)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this->playSound != other.playSound)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this->customSoundUrl != other.customSoundUrl)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->color && other.color)
|
||||||
|
{
|
||||||
|
if (*this->color != *other.color)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->showInMentions != other.showInMentions)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlightResult::operator!=(const HighlightResult &other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlightResult::empty() const
|
||||||
|
{
|
||||||
|
return !this->alert && !this->playSound &&
|
||||||
|
!this->customSoundUrl.has_value() && !this->color &&
|
||||||
|
!this->showInMentions;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlightResult::full() const
|
||||||
|
{
|
||||||
|
return this->alert && this->playSound && this->customSoundUrl.has_value() &&
|
||||||
|
this->color && this->showInMentions;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const HighlightResult &result)
|
||||||
|
{
|
||||||
|
os << "Alert: " << (result.alert ? "Yes" : "No") << ", "
|
||||||
|
<< "Play sound: " << (result.playSound ? "Yes" : "No") << " ("
|
||||||
|
<< (result.customSoundUrl
|
||||||
|
? result.customSoundUrl->toString().toStdString()
|
||||||
|
: "")
|
||||||
|
<< ")"
|
||||||
|
<< ", "
|
||||||
|
<< "Color: " << (result.color ? result.color->name().toStdString() : "")
|
||||||
|
<< ", "
|
||||||
|
<< "Show in mentions: " << (result.showInMentions ? "Yes" : "No");
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace chatterino
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
#include "controllers/emotes/EmoteController.hpp"
|
#include "controllers/emotes/EmoteController.hpp"
|
||||||
#include "controllers/highlights/HighlightController.hpp"
|
#include "controllers/highlights/HighlightController.hpp"
|
||||||
|
#include "controllers/highlights/HighlightResult.hpp"
|
||||||
#include "controllers/ignores/IgnoreController.hpp"
|
#include "controllers/ignores/IgnoreController.hpp"
|
||||||
#include "controllers/ignores/IgnorePhrase.hpp"
|
#include "controllers/ignores/IgnorePhrase.hpp"
|
||||||
#include "controllers/userdata/UserDataController.hpp"
|
#include "controllers/userdata/UserDataController.hpp"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "common/QLogging.hpp"
|
#include "common/QLogging.hpp"
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
#include "controllers/highlights/HighlightController.hpp"
|
#include "controllers/highlights/HighlightController.hpp"
|
||||||
|
#include "controllers/highlights/HighlightResult.hpp"
|
||||||
#include "messages/Message.hpp"
|
#include "messages/Message.hpp"
|
||||||
#include "messages/MessageBuilder.hpp"
|
#include "messages/MessageBuilder.hpp"
|
||||||
#include "providers/twitch/eventsub/Controller.hpp"
|
#include "providers/twitch/eventsub/Controller.hpp"
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ After you've built Chatterino, you can now run the tests with `ctest` or by manu
|
|||||||
We expect this to be listening to port 9050, you can launch it like this:
|
We expect this to be listening to port 9050, you can launch it like this:
|
||||||
`twitch-pubsub-server-test 127.0.0.1:9050`
|
`twitch-pubsub-server-test 127.0.0.1:9050`
|
||||||
|
|
||||||
|
Alternatively, you can run the docker-compose defined in this file: `docker compose up` before you run the tests.
|
||||||
|
|
||||||
# Modifying message building
|
# Modifying message building
|
||||||
|
|
||||||
If you make a change that has to do with message building, there's a big chance that some of the snapshot tests will fail.
|
If you make a change that has to do with message building, there's a big chance that some of the snapshot tests will fail.
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
services:
|
||||||
|
http-server:
|
||||||
|
restart: always
|
||||||
|
image: ghcr.io/kevinastone/httpbox:master
|
||||||
|
command: "--port 9051"
|
||||||
|
ports:
|
||||||
|
- "9051:9051"
|
||||||
|
pubsub-server:
|
||||||
|
restart: always
|
||||||
|
image: ghcr.io/chatterino/twitch-pubsub-server-test:latest
|
||||||
|
command: "./server 0.0.0.0:9050 0.0.0.0:9052"
|
||||||
|
ports:
|
||||||
|
- "9050:9050"
|
||||||
|
- "9052:9052"
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||||
|
#include "controllers/highlights/HighlightResult.hpp"
|
||||||
#include "messages/MessageBuilder.hpp" // for MessageParseArgs
|
#include "messages/MessageBuilder.hpp" // for MessageParseArgs
|
||||||
#include "mocks/BaseApplication.hpp"
|
#include "mocks/BaseApplication.hpp"
|
||||||
#include "mocks/Helix.hpp"
|
#include "mocks/Helix.hpp"
|
||||||
|
|||||||
Reference in New Issue
Block a user