From 9219647b6ab1ef70f01d395f51d92fa02346f2ac Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 6 Jun 2022 15:36:53 +0200 Subject: [PATCH] Fix highlights not showing in mentions (#3801) --- CHANGELOG.md | 2 +- benchmarks/src/Highlights.cpp | 49 ++++++++++++++++++- .../highlights/HighlightController.cpp | 16 ++++-- .../highlights/HighlightController.hpp | 16 ++++++ tests/src/HighlightController.cpp | 41 ++++++++++++++++ 5 files changed, 116 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31f8c4eb..ea8863dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ - Bugfix: Fixed automod queue pubsub topic persisting after user change. (#3718) - Bugfix: Fixed viewer list not closing after pressing escape key. (#3734) - Bugfix: Fixed links with no thumbnail having previous link's thumbnail. (#3720) -- Dev: Overhaul highlight system by moving all checks into a Controller allowing for easier tests. (#3399) +- Dev: Overhaul highlight system by moving all checks into a Controller allowing for easier tests. (#3399, #3801) - Dev: Use Game Name returned by Get Streams instead of querying it from the Get Games API. (#3662) - Dev: Batch checking live status for all channels after startup. (#3757, #3762, #3767) diff --git a/benchmarks/src/Highlights.cpp b/benchmarks/src/Highlights.cpp index 80061b46..82234f5c 100644 --- a/benchmarks/src/Highlights.cpp +++ b/benchmarks/src/Highlights.cpp @@ -44,12 +44,57 @@ public: } }; -class MockApplication : BaseApplication +class MockApplication : IApplication { - AccountController *const getAccounts() override +public: + Theme *getThemes() override + { + return nullptr; + } + Fonts *getFonts() override + { + return nullptr; + } + Emotes *getEmotes() override + { + return nullptr; + } + AccountController *getAccounts() override { return &this->accounts; } + HotkeyController *getHotkeys() override + { + return nullptr; + } + WindowManager *getWindows() override + { + return nullptr; + } + Toasts *getToasts() override + { + return nullptr; + } + CommandController *getCommands() override + { + return nullptr; + } + NotificationController *getNotifications() override + { + return nullptr; + } + TwitchIrcServer *getTwitch() override + { + return nullptr; + } + ChatterinoBadges *getChatterinoBadges() override + { + return nullptr; + } + FfzBadges *getFfzBadges() override + { + return nullptr; + } AccountController accounts; // TODO: Figure this out diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 379a2b60..aa122d9a 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -170,11 +170,9 @@ void rebuildUserHighlights(Settings &settings, } return HighlightResult{ - highlight.hasAlert(), - highlight.hasSound(), - highlightSoundUrl, - highlight.getColor(), - false, // showInMentions + highlight.hasAlert(), highlight.hasSound(), + highlightSoundUrl, highlight.getColor(), + highlight.showInMentions(), }; }}); } @@ -344,6 +342,14 @@ std::pair HighlightController::check( } } + if (checkResult->showInMentions) + { + if (!result.showInMentions) + { + result.showInMentions = checkResult->showInMentions; + } + } + if (result.full()) { // The final highlight result does not have room to add any more parameters, early out diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index 7d761ce1..eb20716f 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -121,6 +121,22 @@ struct HighlightResult { this->customSoundUrl.has_value() && this->color && this->showInMentions; } + + friend 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.get().toString().toStdString() + : "") + << ")" + << ", " + << "Color: " + << (result.color ? result.color->name().toStdString() : "") << ", " + << "Show in mentions: " << (result.showInMentions ? "Yes" : "No"); + return os; + } }; struct HighlightCheck { diff --git a/tests/src/HighlightController.cpp b/tests/src/HighlightController.cpp index 61ac2388..c2a60dc5 100644 --- a/tests/src/HighlightController.cpp +++ b/tests/src/HighlightController.cpp @@ -451,6 +451,47 @@ TEST_F(HighlightControllerTest, A) }, }, }, + { + // User mention with showInMentions + { + // input + MessageParseArgs{}, // no special args + {}, // no badges + "gempir", // sender name + "a", // original message + }, + { + // expected + true, // state + { + true, // alert + false, // playsound + boost::none, // custom sound url + std::make_shared("#7ff19900"), // color + true, // showInMentions + }, + }, + }, + { + { + // input + MessageParseArgs{}, // no special args + {}, // no badges + "a", // sender name + "!testmanxd", // original message + }, + { + // expected + true, // state + { + true, // alert + true, // playsound + boost::none, // custom sound url + std::make_shared("#7f7f3f49"), // color + true, // showInMentions + }, + }, + }, }; for (const auto &[input, expected] : tests)