From 892e16c53373f96c3b361d1db9eaa65d25ee4259 Mon Sep 17 00:00:00 2001 From: fanway <23499543+fanway@users.noreply.github.com> Date: Sun, 1 Nov 2020 16:33:01 +0300 Subject: [PATCH] Fix link preview doesn't update link info for previous messages after setting is enabled (#2108) Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com> Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/widgets/helper/ChannelView.cpp | 32 +++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a1d5254..bee34918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ - Bugfix: Fixed timestamps missing on channel point redemption messages (#1943) - Bugfix: Fixed tooltip didn't show in `EmotePopup` depending on the `Link preview` setting enabled or no (#2008) - Bugfix: Fixed Stream thumbnail not updating after using the "Change channel" feature (#2074, #2080) +- Bugfix: Fixed previous link info not updating after `Link information` setting is enabled (#2054) - Bugfix: Fix Tab key not working in the Ctrl+K Quick Switcher (#2065) - Bugfix: Fix bug preventing moderator actions when viewing a user card from the search window (#1089) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 45d28fc4..9eaf48b5 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -24,6 +24,7 @@ #include "messages/MessageElement.hpp" #include "messages/layouts/MessageLayout.hpp" #include "messages/layouts/MessageLayoutElement.hpp" +#include "providers/LinkResolver.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchIrcServer.hpp" #include "singletons/Resources.hpp" @@ -1379,13 +1380,13 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } } - const auto &tooltip = hoverLayoutElement->getCreator().getTooltip(); + auto element = &hoverLayoutElement->getCreator(); bool isLinkValid = hoverLayoutElement->getLink().isValid(); - auto emoteElement = - dynamic_cast(&hoverLayoutElement->getCreator()); + auto emoteElement = dynamic_cast(element); - if (tooltip.isEmpty() || (isLinkValid && emoteElement == nullptr && - !getSettings()->linkInfoTooltip)) + if (element->getTooltip().isEmpty() || + (isLinkValid && emoteElement == nullptr && + !getSettings()->linkInfoTooltip)) { tooltipWidget->hide(); } @@ -1393,8 +1394,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) { auto &tooltipPreviewImage = TooltipPreviewImage::instance(); tooltipPreviewImage.setImageScale(0, 0); - auto badgeElement = dynamic_cast( - &hoverLayoutElement->getCreator()); + auto badgeElement = dynamic_cast(element); if ((badgeElement || emoteElement) && getSettings()->emotesTooltipPreview.getValue()) @@ -1420,7 +1420,21 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) } else { - auto element = &hoverLayoutElement->getCreator(); + if (element->getTooltip() == "No link info loaded") + { + std::weak_ptr weakLayout = layout; + LinkResolver::getLinkInfo( + element->getLink().value, nullptr, + [weakLayout, element](QString tooltipText, + Link originalLink, + ImagePtr thumbnail) { + auto shared = weakLayout.lock(); + if (!shared) + return; + element->setTooltip(tooltipText); + element->setThumbnail(thumbnail); + }); + } auto thumbnailSize = getSettings()->thumbnailSize; if (!thumbnailSize) { @@ -1448,7 +1462,7 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event) tooltipWidget->moveTo(this, event->globalPos()); tooltipWidget->setWordWrap(isLinkValid); - tooltipWidget->setText(tooltip); + tooltipWidget->setText(element->getTooltip()); tooltipWidget->adjustSize(); tooltipWidget->show(); tooltipWidget->raise();