diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index b9271d2ed..49b2cadbc 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -61,6 +61,12 @@ MessageElementFlags MessageElement::getFlags() const return this->flags_; } +MessageElement *MessageElement::updateLink() +{ + this->linkChanged.invoke(); + return this; +} + // IMAGE ImageElement::ImageElement(ImagePtr image, MessageElementFlags flags) : MessageElement(flags) @@ -152,6 +158,15 @@ void TextElement::addToContainer(MessageLayoutContainer &container, color, this->style_, container.getScale())) ->setLink(this->getLink()); e->setTrailingSpace(trailingSpace); + + // If URL link was changed, + // Should update it in MessageLayoutElement too! + if (this->getLink().type == Link::Url) { + this->linkChanged.connect( + [this, e]() { + e->setLink(this->getLink()); + }); + } return e; }; diff --git a/src/messages/MessageElement.hpp b/src/messages/MessageElement.hpp index 8d96d1135..e82bee5e0 100644 --- a/src/messages/MessageElement.hpp +++ b/src/messages/MessageElement.hpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace chatterino { class Channel; @@ -128,6 +129,7 @@ public: const Link &getLink() const; bool hasTrailingSpace() const; MessageElementFlags getFlags() const; + MessageElement *updateLink(); virtual void addToContainer(MessageLayoutContainer &container, MessageElementFlags flags) = 0; @@ -135,6 +137,7 @@ public: protected: MessageElement(MessageElementFlags flags); bool trailingSpace = true; + pajlada::Signals::NoArgSignal linkChanged; private: Link link_; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index ac2194f4c..62a005601 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -280,13 +280,16 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_) ->setLink(link); LinkResolver::getLinkInfo( - linkString, [linkMELowercase, linkMEOriginal](QString tooltipText, - Link originalLink) { + linkString, [linkMELowercase, linkMEOriginal, linkString] + (QString tooltipText, Link originalLink) { if (!tooltipText.isEmpty()) { - linkMELowercase->setTooltip(tooltipText) - ->setLink(originalLink); - linkMEOriginal->setTooltip(tooltipText) - ->setLink(originalLink); + linkMELowercase->setTooltip(tooltipText); + linkMEOriginal->setTooltip(tooltipText); + } + if (originalLink.value != linkString && + !originalLink.value.isEmpty()) { + linkMELowercase->setLink(originalLink)->updateLink(); + linkMEOriginal->setLink(originalLink)->updateLink(); } }); }