Fixed restricted users' usernames not being clickable (#5405)

This commit is contained in:
pajlada
2024-06-01 13:07:01 +02:00
committed by GitHub
parent 65bfec963b
commit 2a46ee708e
5 changed files with 55 additions and 27 deletions
+1 -1
View File
@@ -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
{
+25 -2
View File
@@ -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,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 "
"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)
+8 -3
View File
@@ -169,7 +169,7 @@ public:
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);
@@ -314,8 +314,8 @@ private:
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,9 @@ public:
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
@@ -335,6 +338,8 @@ private:
* 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 :