Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed restricted users' usernames not being clickable #5405

Merged
merged 5 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ void MessageBuilder::addTextOrEmoji(const QString &string_)
auto &&textColor = this->textColor_;
if (string.startsWith('@'))
{
this->emplace<MentionElement>(string, textColor, textColor);
this->emplace<MentionElement>(string, "", textColor, textColor);
}
else
{
Expand Down
27 changes: 25 additions & 2 deletions src/messages/MessageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_))
{
}

Expand Down Expand Up @@ -735,6 +738,26 @@ void MentionElement::addToContainer(MessageLayoutContainer &container,
TextElement::addToContainer(container, flags);
}

MessageElement *MentionElement::setLink(const Link &link)
{
assert(false && "MentionElement::setLink should not be called. Pass "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "assert" is directly included [misc-include-cleaner]

src/messages/MessageElement.cpp:15:

+ #include <cassert>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "assert" is directly included [misc-include-cleaner]

src/messages/MessageElement.cpp:15:

+ #include <cassert>

"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())
{
// 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)
Expand Down
11 changes: 8 additions & 3 deletions src/messages/MessageElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -325,6 +325,9 @@ class MentionElement : public TextElement
void addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags) override;

MessageElement *setLink(const Link &link) override;
Link getLink() const override;

private:
/**
* The color of the element in case the "Colorize @usernames" is disabled
Expand All @@ -335,6 +338,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 :
Expand Down
41 changes: 20 additions & 21 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)

auto prefixedUsername = '@' + username;
auto remainder = string.remove(prefixedUsername);
this->emplace<MentionElement>(prefixedUsername, originalTextColor,
textColor)
->setLink({Link::UserInfo, username})
this->emplace<MentionElement>(prefixedUsername, username,
originalTextColor, textColor)
->setTrailingSpace(remainder.isEmpty());

if (!remainder.isEmpty())
Expand Down Expand Up @@ -802,9 +801,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
}

auto remainder = string.remove(username);
this->emplace<MentionElement>(username, originalTextColor,
this->emplace<MentionElement>(username, username, originalTextColor,
textColor)
->setLink({Link::UserInfo, username})
->setTrailingSpace(remainder.isEmpty());

if (!remainder.isEmpty())
Expand Down Expand Up @@ -1821,8 +1819,10 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(QString prefix,
}
}

builder->emplace<MentionElement>(username, MessageColor::System, color)
->setLink({Link::UserInfo, username})
// TODO: Ensure we make use of display name / username(login name) correctly here
builder
->emplace<MentionElement>(username, username, MessageColor::System,
color)
->setTrailingSpace(false);
}
}
Expand Down Expand Up @@ -1867,9 +1867,8 @@ void TwitchMessageBuilder::listOfUsersSystemMessage(
}

builder
->emplace<MentionElement>(user.userName, MessageColor::System,
color)
->setLink({Link::UserInfo, user.userLogin})
->emplace<MentionElement>(user.userName, user.userLogin,
MessageColor::System, color)
->setTrailingSpace(false);
}

Expand Down Expand Up @@ -1938,8 +1937,8 @@ MessagePtr TwitchMessageBuilder::makeAutomodInfoMessage(
builder.emplace<BadgeElement>(makeAutoModBadge(),
MessageElementFlag::BadgeChannelAuthority);
// AutoMod "username"
builder.emplace<MentionElement>("AutoMod:", AUTOMOD_USER_COLOR,
AUTOMOD_USER_COLOR);
builder.emplace<TextElement>("AutoMod:", MessageElementFlag::Text,
AUTOMOD_USER_COLOR, FontStyle::ChatMediumBold);
switch (action.type)
{
case AutomodInfoAction::OnHold: {
Expand Down Expand Up @@ -1993,8 +1992,9 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeAutomodMessage(
builder.emplace<BadgeElement>(makeAutoModBadge(),
MessageElementFlag::BadgeChannelAuthority);
// AutoMod "username"
builder2.emplace<MentionElement>("AutoMod:", AUTOMOD_USER_COLOR,
AUTOMOD_USER_COLOR);
builder2.emplace<TextElement>("AutoMod:", MessageElementFlag::Text,
AUTOMOD_USER_COLOR,
FontStyle::ChatMediumBold);
// AutoMod header message
builder.emplace<TextElement>(
("Held a message for reason: " + action.reason +
Expand Down Expand Up @@ -2041,10 +2041,9 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeAutomodMessage(
builder2.message().flags.set(MessageFlag::AutoModOffendingMessage);

// sender username
builder2
.emplace<MentionElement>(action.target.displayName + ":",
MessageColor::Text, action.target.color)
->setLink({Link::UserInfo, action.target.login});
builder2.emplace<MentionElement>(action.target.displayName + ":",
action.target.login, MessageColor::Text,
action.target.color);
// sender's message caught by AutoMod
builder2.emplace<TextElement>(action.message, MessageElementFlag::Text,
MessageColor::Text);
Expand Down Expand Up @@ -2239,9 +2238,9 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeLowTrustUserMessage(
appendBadges(&builder2, action.senderBadges, {}, twitchChannel);

// sender username
builder2.emplace<MentionElement>(action.suspiciousUserDisplayName + ":",
MessageColor::Text,
action.suspiciousUserColor);
builder2.emplace<MentionElement>(
action.suspiciousUserDisplayName + ":", action.suspiciousUserLogin,
MessageColor::Text, action.suspiciousUserColor);

// sender's message caught by AutoMod
for (const auto &fragment : action.fragments)
Expand Down
Loading