fix: use the full url when resolving (#5345)

This commit is contained in:
nerix 2024-04-21 21:24:11 +02:00 committed by GitHub
parent 1a04bda56b
commit dfa929e207
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 9 deletions

View file

@ -2,6 +2,8 @@
## Unversioned ## Unversioned
- Bugfix: Fixed links without a protocol not being clickable. (#5345)
## 2.5.0 ## 2.5.0
- Major: Twitch follower emotes can now be correctly tabbed in other channels when you are subscribed to the channel the emote is from. (#4922) - Major: Twitch follower emotes can now be correctly tabbed in other channels when you are subscribed to the channel the emote is from. (#4922)

View file

@ -12,9 +12,28 @@ struct ParsedLink {
#else #else
using StringView = QStringRef; using StringView = QStringRef;
#endif #endif
/// The parsed protocol of the link. Can be empty.
///
/// https://www.forsen.tv/commands
/// ^------^
StringView protocol; StringView protocol;
/// The parsed host of the link. Can not be empty.
///
/// https://www.forsen.tv/commands
/// ^-----------^
StringView host; StringView host;
/// The remainder of the link. Can be empty.
///
/// https://www.forsen.tv/commands
/// ^-------^
StringView rest; StringView rest;
/// The original unparsed link.
///
/// https://www.forsen.tv/commands
/// ^----------------------------^
QString source; QString source;
}; };

View file

@ -617,16 +617,16 @@ void MessageBuilder::addLink(const ParsedLink &parsedLink)
{ {
QString lowercaseLinkString; QString lowercaseLinkString;
QString origLink = parsedLink.source; QString origLink = parsedLink.source;
QString matchedLink; QString fullUrl;
if (parsedLink.protocol.isNull()) if (parsedLink.protocol.isNull())
{ {
matchedLink = QStringLiteral("http://") + parsedLink.source; fullUrl = QStringLiteral("http://") + parsedLink.source;
} }
else else
{ {
lowercaseLinkString += parsedLink.protocol; lowercaseLinkString += parsedLink.protocol;
matchedLink = parsedLink.source; fullUrl = parsedLink.source;
} }
lowercaseLinkString += parsedLink.host.toString().toLower(); lowercaseLinkString += parsedLink.host.toString().toLower();
@ -636,8 +636,7 @@ void MessageBuilder::addLink(const ParsedLink &parsedLink)
auto *el = this->emplace<LinkElement>( auto *el = this->emplace<LinkElement>(
LinkElement::Parsed{.lowercase = lowercaseLinkString, LinkElement::Parsed{.lowercase = lowercaseLinkString,
.original = origLink}, .original = origLink},
MessageElementFlag::Text, textColor); fullUrl, MessageElementFlag::Text, textColor);
el->setLink({Link::Url, matchedLink});
getIApp()->getLinkResolver()->resolve(el->linkInfo()); getIApp()->getLinkResolver()->resolve(el->linkInfo());
} }

View file

@ -679,10 +679,11 @@ void SingleLineTextElement::addToContainer(MessageLayoutContainer &container,
} }
} }
LinkElement::LinkElement(const Parsed &parsed, MessageElementFlags flags, LinkElement::LinkElement(const Parsed &parsed, const QString &fullUrl,
const MessageColor &color, FontStyle style) MessageElementFlags flags, const MessageColor &color,
FontStyle style)
: TextElement({}, flags, color, style) : TextElement({}, flags, color, style)
, linkInfo_(parsed.original) , linkInfo_(fullUrl)
, lowercase_({parsed.lowercase}) , lowercase_({parsed.lowercase})
, original_({parsed.original}) , original_({parsed.original})
{ {

View file

@ -272,7 +272,10 @@ public:
QString original; QString original;
}; };
LinkElement(const Parsed &parsed, MessageElementFlags flags, /// @param parsed The link as it appeared in the message
/// @param fullUrl A full URL (notably with a protocol)
LinkElement(const Parsed &parsed, const QString &fullUrl,
MessageElementFlags flags,
const MessageColor &color = MessageColor::Text, const MessageColor &color = MessageColor::Text,
FontStyle style = FontStyle::ChatMedium); FontStyle style = FontStyle::ChatMedium);
~LinkElement() override = default; ~LinkElement() override = default;