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
- Bugfix: Fixed links without a protocol not being clickable. (#5345)
## 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)

View file

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

View file

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

View file

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

View file

@ -272,7 +272,10 @@ public:
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,
FontStyle style = FontStyle::ChatMedium);
~LinkElement() override = default;