From d81b6ca51805bec782a9ce3175f0a15a560cec65 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 31 Aug 2022 09:32:08 +0100 Subject: [PATCH] fix(Chat): improve gif confirmation popup and fix preview whitelisting Enable preview for gifs after enabling the gif functionality Disable gif functionality if the preview was disabled Addition fixes - The gifs weren't checked if all images weren't enabled - The subdomain wasn't checked for whitelisting if the main domain wasn't enabled - Image clicking - Dismiss asking for unfurling was not updating the state Considerations - Looked into having the "gif enabled" - "tenor unfurling" relation embedded in the controller but it would require extensive refactoring by implementing a data-model for unfurling whitelisted domains Closes: #6829 --- .../Profile/views/MessagingView.qml | 24 +++---- .../StatusGifPopup/ConfirmationPopup.qml | 5 +- .../StatusGifPopup/EmptyPlaceholder.qml | 2 - ui/imports/shared/stores/RootStore.qml | 16 +++++ .../shared/views/chat/LinksMessageView.qml | 68 ++++++++++--------- ui/imports/shared/views/chat/MessageView.qml | 3 + vendor/status-go | 2 +- 7 files changed, 69 insertions(+), 51 deletions(-) diff --git a/ui/app/AppLayouts/Profile/views/MessagingView.qml b/ui/app/AppLayouts/Profile/views/MessagingView.qml index 76fc132d73..3d17bb99cf 100644 --- a/ui/app/AppLayouts/Profile/views/MessagingView.qml +++ b/ui/app/AppLayouts/Profile/views/MessagingView.qml @@ -9,6 +9,7 @@ import shared.panels 1.0 import shared.popups 1.0 import shared.status 1.0 import shared.controls 1.0 +import shared.stores 1.0 import StatusQ.Core 0.1 import StatusQ.Core.Theme 0.1 @@ -263,7 +264,7 @@ SettingsContentBase { previewableSites.clear() var oneEntryIsActive = false whitelist.forEach(entry => { - entry.isWhitelisted = localAccountSensitiveSettings.whitelistedUnfurlingSites[entry.address] || false + entry.isWhitelisted = !!localAccountSensitiveSettings.whitelistedUnfurlingSites[entry.address] if (entry.isWhitelisted) { oneEntryIsActive = true } @@ -303,6 +304,11 @@ SettingsContentBase { } } + Connections { + target: localAccountSensitiveSettings + onWhitelistedUnfurlingSitesChanged: generalColumn.populatePreviewableSites() + } + // Manually add switch for the image unfurling StatusListItem { objectName: "imageUnfurlingItem" @@ -356,6 +362,7 @@ SettingsContentBase { case "medium": filename = "medium"; break; case "tenor gifs": + case "tenor gifs subdomain": filename = "tenor"; break; case "giphy gifs": case "giphy gifs shortener": @@ -375,20 +382,7 @@ SettingsContentBase { StatusSwitch { id: siteSwitch checked: !!model.isWhitelisted - onCheckedChanged: { - let settings = localAccountSensitiveSettings.whitelistedUnfurlingSites - - if (!settings) { - settings = {} - } - - if (settings[address] === this.checked) { - return - } - - settings[address] = this.checked - localAccountSensitiveSettings.whitelistedUnfurlingSites = settings - } + onCheckedChanged: RootStore.updateWhitelistedUnfurlingSites(model.address, checked) } ] onClicked: { diff --git a/ui/imports/shared/status/StatusGifPopup/ConfirmationPopup.qml b/ui/imports/shared/status/StatusGifPopup/ConfirmationPopup.qml index 0f3b23847c..390b945abb 100644 --- a/ui/imports/shared/status/StatusGifPopup/ConfirmationPopup.qml +++ b/ui/imports/shared/status/StatusGifPopup/ConfirmationPopup.qml @@ -1,5 +1,5 @@ -import QtQuick 2.13 -import QtQuick.Controls 2.13 +import QtQuick 2.14 +import QtQuick.Controls 2.14 import QtGraphicalEffects 1.0 import StatusQ.Core 0.1 @@ -80,6 +80,7 @@ Popup { onClicked: { RootStore.setIsTenorWarningAccepted(true) + RootStore.updateWhitelistedUnfurlingSites("media.tenor.com", true) RootStore.getTrendingsGifs() root.close() } diff --git a/ui/imports/shared/status/StatusGifPopup/EmptyPlaceholder.qml b/ui/imports/shared/status/StatusGifPopup/EmptyPlaceholder.qml index f0bff9522d..a673c3def0 100644 --- a/ui/imports/shared/status/StatusGifPopup/EmptyPlaceholder.qml +++ b/ui/imports/shared/status/StatusGifPopup/EmptyPlaceholder.qml @@ -14,8 +14,6 @@ Rectangle { signal doRetry() - height: parent.height - width: parent.width color: Style.current.background StatusBaseText { diff --git a/ui/imports/shared/stores/RootStore.qml b/ui/imports/shared/stores/RootStore.qml index c21fcdb4c6..9c8e1f13be 100644 --- a/ui/imports/shared/stores/RootStore.qml +++ b/ui/imports/shared/stores/RootStore.qml @@ -106,6 +106,22 @@ QtObject { chatSectionChatContentInputArea.getTrendingsGifs() } + function updateWhitelistedUnfurlingSites(hostname, whitelisted) { + // no way to send update notification for individual array entries + let settings = localAccountSensitiveSettings.whitelistedUnfurlingSites + + if (!settings) + settings = {} + + if (settings[hostname] === whitelisted) + return + + settings[hostname] = whitelisted + localAccountSensitiveSettings.whitelistedUnfurlingSites = settings + if(hostname === "media.tenor.com" && whitelisted === false) + RootStore.setIsTenorWarningAccepted(false) + } + function getRecentsGifs() { chatSectionChatContentInputArea.getRecentsGifs() } diff --git a/ui/imports/shared/views/chat/LinksMessageView.qml b/ui/imports/shared/views/chat/LinksMessageView.qml index 008aa5e17b..76aef87f80 100644 --- a/ui/imports/shared/views/chat/LinksMessageView.qml +++ b/ui/imports/shared/views/chat/LinksMessageView.qml @@ -22,6 +22,9 @@ Column { property string linkUrls: "" property bool isCurrentUser: false property bool isImageLink: false + + signal imageClicked(var image) + spacing: Style.current.halfPadding height: childrenRect.height @@ -76,12 +79,12 @@ Column { } } - Connections { - id: linkFetchConnections - enabled: false - target: root.messageStore.messageModule - onLinkPreviewDataWasReceived: { - let response + Connections { + id: linkFetchConnections + enabled: false + target: root.messageStore.messageModule + onLinkPreviewDataWasReceived: { + let response = {} try { response = JSON.parse(previewData) } catch (e) { @@ -106,8 +109,8 @@ Column { linkData.address = link return linkMessageLoader.sourceComponent = unfurledLinkComponent } - } - } + } + } Connections { id: linkCommunityFetchConnections @@ -134,37 +137,26 @@ Column { // Reset the height in case we set it to 0 below. See note below // for more information this.height = undefined - if (Utils.hasImageExtension(link)) { - if (RootStore.displayChatImages) { - linkData = { - thumbnailUrl: link - } - return unfurledImageComponent - } else { - if (RootStore.neverAskAboutUnfurlingAgain || (isImageLink && index > 0)) { - return - } - isImageLink = true - return enableLinkComponent - } - } - - let linkWhiteListed = false const linkHostname = Utils.getHostname(link) if (!localAccountSensitiveSettings.whitelistedUnfurlingSites) { localAccountSensitiveSettings.whitelistedUnfurlingSites = {} } - const linkExists = Object.keys(localAccountSensitiveSettings.whitelistedUnfurlingSites).some(function(whitelistedHostname) { - const exists = linkHostname.endsWith(whitelistedHostname) - if (exists) { - linkWhiteListed = localAccountSensitiveSettings.whitelistedUnfurlingSites[whitelistedHostname] === true - } - return exists + + const whitelistHosts = Object.keys(localAccountSensitiveSettings.whitelistedUnfurlingSites) + const linkExists = whitelistHosts.some(function(hostname) { + return linkHostname.endsWith(hostname) }) - if (!linkWhiteListed && linkExists && !RootStore.neverAskAboutUnfurlingAgain) { + + const linkWhiteListed = linkExists && whitelistHosts.some(function(hostname) { + return linkHostname.endsWith(hostname) && localAccountSensitiveSettings.whitelistedUnfurlingSites[hostname] === true + }) + + const isImage = Utils.hasImageExtension(link) + if (!linkWhiteListed && linkExists && !RootStore.neverAskAboutUnfurlingAgain && !isImage) { return enableLinkComponent } + if (linkWhiteListed) { if (fetched) { if (linkData.communityId) { @@ -193,6 +185,20 @@ Column { root.messageStore.getLinkPreviewData(link, linkMessageLoader.uuid) } + + if (isImage) { + if (RootStore.displayChatImages) { + linkData = { + thumbnailUrl: link + } + return unfurledImageComponent + } + else if (!(RootStore.neverAskAboutUnfurlingAgain || (isImageLink && index > 0))) { + isImageLink = true + return enableLinkComponent + } + } + // setting the height to 0 allows the "enable link" dialog to // disappear correctly when RootStore.neverAskAboutUnfurlingAgain // is true. The height is reset at the top of this method. diff --git a/ui/imports/shared/views/chat/MessageView.qml b/ui/imports/shared/views/chat/MessageView.qml index 9e823bf1da..2adfa12f8b 100644 --- a/ui/imports/shared/views/chat/MessageView.qml +++ b/ui/imports/shared/views/chat/MessageView.qml @@ -637,6 +637,9 @@ Loader { messageStore: root.messageStore store: root.rootStore isCurrentUser: root.amISender + onImageClicked: { + root.imageClicked(image); + } } } diff --git a/vendor/status-go b/vendor/status-go index ed4a1c46f1..bc00836df2 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit ed4a1c46f18cef446169b37ef2f34effb509e30c +Subproject commit bc00836df2c8027381977cc24a473f97290b12b8