From dfa929e20736e3da93a97e12de288974dcc69871 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 21 Apr 2024 21:24:11 +0200 Subject: [PATCH] fix: use the full url when resolving (#5345) --- CHANGELOG.md | 2 ++ src/common/LinkParser.hpp | 19 +++++++++++++++++++ src/messages/MessageBuilder.cpp | 9 ++++----- src/messages/MessageElement.cpp | 7 ++++--- src/messages/MessageElement.hpp | 5 ++++- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fed1f751..d335d8274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/common/LinkParser.hpp b/src/common/LinkParser.hpp index 16bfe235e..9d5e10cfb 100644 --- a/src/common/LinkParser.hpp +++ b/src/common/LinkParser.hpp @@ -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; }; diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 45b8cafda..e17194549 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -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::Parsed{.lowercase = lowercaseLinkString, .original = origLink}, - MessageElementFlag::Text, textColor); - el->setLink({Link::Url, matchedLink}); + fullUrl, MessageElementFlag::Text, textColor); getIApp()->getLinkResolver()->resolve(el->linkInfo()); } diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 56d1e2ed3..b11e82be1 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -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}) { diff --git a/src/messages/MessageElement.hpp b/src/messages/MessageElement.hpp index 68f90e9b5..b57bab752 100644 --- a/src/messages/MessageElement.hpp +++ b/src/messages/MessageElement.hpp @@ -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;