From e434b5f1bccf80a33b5d97db4a6776477ade2372 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 19 May 2024 12:37:03 +0200 Subject: [PATCH 1/4] chore: make automod "mentions" regular text elements It's more of an "author" anyway then a regular mention --- src/providers/twitch/TwitchMessageBuilder.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 3dfd39720ec..a4f681f5757 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1938,8 +1938,8 @@ MessagePtr TwitchMessageBuilder::makeAutomodInfoMessage( builder.emplace(makeAutoModBadge(), MessageElementFlag::BadgeChannelAuthority); // AutoMod "username" - builder.emplace("AutoMod:", AUTOMOD_USER_COLOR, - AUTOMOD_USER_COLOR); + builder.emplace("AutoMod:", MessageElementFlag::Text, + AUTOMOD_USER_COLOR, FontStyle::ChatMediumBold); switch (action.type) { case AutomodInfoAction::OnHold: { @@ -1993,8 +1993,9 @@ std::pair TwitchMessageBuilder::makeAutomodMessage( builder.emplace(makeAutoModBadge(), MessageElementFlag::BadgeChannelAuthority); // AutoMod "username" - builder2.emplace("AutoMod:", AUTOMOD_USER_COLOR, - AUTOMOD_USER_COLOR); + builder2.emplace("AutoMod:", MessageElementFlag::Text, + AUTOMOD_USER_COLOR, + FontStyle::ChatMediumBold); // AutoMod header message builder.emplace( ("Held a message for reason: " + action.reason + From 79bcce84343f1d88c1b67b21ea99b0185f9040bc Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 19 May 2024 12:48:41 +0200 Subject: [PATCH 2/4] fix: auto link mention elements to UserInfo --- src/messages/MessageBuilder.cpp | 2 +- src/messages/MessageElement.cpp | 18 +++++++++-- src/messages/MessageElement.hpp | 8 +++-- src/providers/twitch/TwitchMessageBuilder.cpp | 32 +++++++++---------- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 1ffd5ba28db..cccd540d023 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -763,7 +763,7 @@ void MessageBuilder::addTextOrEmoji(const QString &string_) auto &&textColor = this->textColor_; if (string.startsWith('@')) { - this->emplace(string, textColor, textColor); + this->emplace(string, "", textColor, textColor); } else { diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 17de1270608..40ee6be8b85 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -703,11 +703,14 @@ Link LinkElement::getLink() const return {Link::Url, this->linkInfo_.url()}; } -MentionElement::MentionElement(const QString &name, MessageColor fallbackColor_, +MentionElement::MentionElement(const QString &displayName, QString loginName_, + MessageColor fallbackColor_, MessageColor userColor_) - : TextElement(name, {MessageElementFlag::Text, MessageElementFlag::Mention}) + : TextElement(displayName, + {MessageElementFlag::Text, MessageElementFlag::Mention}) , fallbackColor(fallbackColor_) , userColor(userColor_) + , userLoginName(std::move(loginName_)) { } @@ -735,6 +738,17 @@ void MentionElement::addToContainer(MessageLayoutContainer &container, TextElement::addToContainer(container, flags); } +Link MentionElement::getLink() const +{ + if (this->userLoginName.isEmpty()) + { + // Some rare mention elements don't have the knowledge of the login name + return {}; + } + + return {Link::UserInfo, this->userLoginName}; +} + // TIMESTAMP TimestampElement::TimestampElement(QTime time) : MessageElement(MessageElementFlag::Timestamp) diff --git a/src/messages/MessageElement.hpp b/src/messages/MessageElement.hpp index 2c1e98f4e89..8adbac4fdad 100644 --- a/src/messages/MessageElement.hpp +++ b/src/messages/MessageElement.hpp @@ -314,8 +314,8 @@ class LinkElement : public TextElement class MentionElement : public TextElement { public: - MentionElement(const QString &name, MessageColor fallbackColor_, - MessageColor userColor_); + MentionElement(const QString &displayName, QString loginName_, + MessageColor fallbackColor_, MessageColor userColor_); ~MentionElement() override = default; MentionElement(const MentionElement &) = delete; MentionElement(MentionElement &&) = delete; @@ -325,6 +325,8 @@ class MentionElement : public TextElement void addToContainer(MessageLayoutContainer &container, MessageElementFlags flags) override; + Link getLink() const override; + private: /** * The color of the element in case the "Colorize @usernames" is disabled @@ -335,6 +337,8 @@ class MentionElement : public TextElement * The color of the element in case the "Colorize @usernames" is enabled **/ MessageColor userColor; + + QString userLoginName; }; // contains emote data and will pick the emote based on : diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index a4f681f5757..f69264cb3b1 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -770,9 +770,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) auto prefixedUsername = '@' + username; auto remainder = string.remove(prefixedUsername); - this->emplace(prefixedUsername, originalTextColor, - textColor) - ->setLink({Link::UserInfo, username}) + this->emplace(prefixedUsername, username, + originalTextColor, textColor) ->setTrailingSpace(remainder.isEmpty()); if (!remainder.isEmpty()) @@ -802,9 +801,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) } auto remainder = string.remove(username); - this->emplace(username, originalTextColor, + this->emplace(username, username, originalTextColor, textColor) - ->setLink({Link::UserInfo, username}) ->setTrailingSpace(remainder.isEmpty()); if (!remainder.isEmpty()) @@ -1821,8 +1819,10 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(QString prefix, } } - builder->emplace(username, MessageColor::System, color) - ->setLink({Link::UserInfo, username}) + // TODO: Ensure we make use of display name / username(login name) correctly here + builder + ->emplace(username, username, MessageColor::System, + color) ->setTrailingSpace(false); } } @@ -1867,9 +1867,8 @@ void TwitchMessageBuilder::listOfUsersSystemMessage( } builder - ->emplace(user.userName, MessageColor::System, - color) - ->setLink({Link::UserInfo, user.userLogin}) + ->emplace(user.userName, user.userLogin, + MessageColor::System, color) ->setTrailingSpace(false); } @@ -2042,10 +2041,9 @@ std::pair TwitchMessageBuilder::makeAutomodMessage( builder2.message().flags.set(MessageFlag::AutoModOffendingMessage); // sender username - builder2 - .emplace(action.target.displayName + ":", - MessageColor::Text, action.target.color) - ->setLink({Link::UserInfo, action.target.login}); + builder2.emplace(action.target.displayName + ":", + action.target.login, MessageColor::Text, + action.target.color); // sender's message caught by AutoMod builder2.emplace(action.message, MessageElementFlag::Text, MessageColor::Text); @@ -2240,9 +2238,9 @@ std::pair TwitchMessageBuilder::makeLowTrustUserMessage( appendBadges(&builder2, action.senderBadges, {}, twitchChannel); // sender username - builder2.emplace(action.suspiciousUserDisplayName + ":", - MessageColor::Text, - action.suspiciousUserColor); + builder2.emplace( + action.suspiciousUserDisplayName + ":", action.suspiciousUserLogin, + MessageColor::Text, action.suspiciousUserColor); // sender's message caught by AutoMod for (const auto &fragment : action.fragments) From 3046c14b940fc19eaaafa6f793b9accacd72c9d9 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 19 May 2024 12:50:44 +0200 Subject: [PATCH 3/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cc9646e93f..37b32628dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Minor: Colored usernames now update on the fly when changing the "Color @usernames" setting. (#5300) - Minor: Added `flags.action` filter variable, allowing you to filter on `/me` messages. (#5397) - Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378) +- Bugfix: Fixed restricted users usernames not being clickable. (#5405) - Dev: Use Qt's high DPI scaling. (#4868, #5400) - Dev: Add doxygen build target. (#5377) - Dev: Make printing of strings in tests easier. (#5379) From 798131e19905bd82a9b2b73a90d98c8a727c2566 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 19 May 2024 12:55:04 +0200 Subject: [PATCH 4/4] chore: Make setLink on MentionElement's throw an assert --- src/messages/MessageElement.cpp | 9 +++++++++ src/messages/MessageElement.hpp | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 40ee6be8b85..0fb47cd0e33 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -738,6 +738,15 @@ void MentionElement::addToContainer(MessageLayoutContainer &container, TextElement::addToContainer(container, flags); } +MessageElement *MentionElement::setLink(const Link &link) +{ + assert(false && "MentionElement::setLink should not be called. Pass " + "through a valid login name in the constructor and it will " + "automatically be a UserInfo link"); + + return TextElement::setLink(link); +} + Link MentionElement::getLink() const { if (this->userLoginName.isEmpty()) diff --git a/src/messages/MessageElement.hpp b/src/messages/MessageElement.hpp index 8adbac4fdad..49ce762cb91 100644 --- a/src/messages/MessageElement.hpp +++ b/src/messages/MessageElement.hpp @@ -169,7 +169,7 @@ class MessageElement MessageElement(MessageElement &&) = delete; MessageElement &operator=(MessageElement &&) = delete; - MessageElement *setLink(const Link &link); + virtual MessageElement *setLink(const Link &link); MessageElement *setTooltip(const QString &tooltip); MessageElement *setTrailingSpace(bool value); @@ -325,6 +325,7 @@ class MentionElement : public TextElement void addToContainer(MessageLayoutContainer &container, MessageElementFlags flags) override; + MessageElement *setLink(const Link &link) override; Link getLink() const override; private: