Skip to content

Commit

Permalink
Fix highlights not showing in mentions (Chatterino#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Jun 6, 2022
1 parent d29243a commit 9219647
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
49 changes: 47 additions & 2 deletions benchmarks/src/Highlights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,57 @@ class BenchmarkMessageBuilder : public SharedMessageBuilder
}
};

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
Expand Down
16 changes: 11 additions & 5 deletions src/controllers/highlights/HighlightController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}});
}
Expand Down Expand Up @@ -344,6 +342,14 @@ std::pair<bool, HighlightResult> 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
Expand Down
16 changes: 16 additions & 0 deletions src/controllers/highlights/HighlightController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
41 changes: 41 additions & 0 deletions tests/src/HighlightController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QColor>("#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<QColor>("#7f7f3f49"), // color
true, // showInMentions
},
},
},
};

for (const auto &[input, expected] : tests)
Expand Down

0 comments on commit 9219647

Please sign in to comment.