Skip to content

Commit

Permalink
fix: use the full url when resolving (#5345)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Apr 21, 2024
1 parent 1a04bda commit dfa929e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions src/common/LinkParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
9 changes: 4 additions & 5 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}

Expand Down
7 changes: 4 additions & 3 deletions src/messages/MessageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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})
{
Expand Down
5 changes: 4 additions & 1 deletion src/messages/MessageElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ class LinkElement : public TextElement
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;
Expand Down

0 comments on commit dfa929e

Please sign in to comment.