From 07b98c3253b97d39642560cd37f9a90245a6d0f6 Mon Sep 17 00:00:00 2001 From: Keyan <34140557+huumn@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:23:06 -0500 Subject: [PATCH] Optout of display of images and video (show them as links) (#1358) * optout of display of images/video * fix disableFreebies warning in settings * preview trusted images Co-authored-by: ekzyis --------- Co-authored-by: ekzyis --- api/typeDefs/user.js | 2 + components/image.js | 50 +++++++++++-------- fragments/users.js | 2 + pages/settings/index.js | 14 +++++- .../20240903235340_hide_images/migration.sql | 2 + prisma/schema.prisma | 1 + 6 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 prisma/migrations/20240903235340_hide_images/migration.sql diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index 3b755e5f..082782bf 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -84,6 +84,7 @@ export default gql` hideIsContributor: Boolean! hideWalletBalance: Boolean! imgproxyOnly: Boolean! + showImagesAndVideos: Boolean! nostrCrossposting: Boolean! nostrPubkey: String nostrRelays: [String!] @@ -155,6 +156,7 @@ export default gql` hideIsContributor: Boolean! hideWalletBalance: Boolean! imgproxyOnly: Boolean! + showImagesAndVideos: Boolean! nostrCrossposting: Boolean! nostrPubkey: String nostrRelays: [String!] diff --git a/components/image.js b/components/image.js index 05860cb0..493f70c5 100644 --- a/components/image.js +++ b/components/image.js @@ -19,13 +19,25 @@ export function decodeOriginalUrl (imgproxyUrl) { return originalUrl } -function ImageOriginal ({ src, topLevel, rel, tab, children, onClick, ...props }) { +function LinkRaw ({ href, children, src, rel, onClick, ...props }) { + const isRawURL = /^https?:\/\//.test(children?.[0]) + return ( + // eslint-disable-next-line + {isRawURL || !children ? src : children} + + ) +} + +function ImageOriginal ({ src, topLevel, tab, onClick, ...props }) { const me = useMe() const [showImage, setShowImage] = useState(false) const [showVideo, setShowVideo] = useState(false) useEffect(() => { - if (me?.privates?.imgproxyOnly && tab !== 'preview') return // make sure it's not a false negative by trying to load URL as const img = new window.Image() img.onload = () => setShowImage(true) @@ -42,7 +54,9 @@ function ImageOriginal ({ src, topLevel, rel, tab, children, onClick, ...props } } }, [src, showImage]) - if (showImage) { + const showMedia = (tab === 'preview' || (me?.privates?.showImagesAndVideos !== false && !me?.privates?.imgproxyOnly)) + + if (showImage && showMedia) { return ( setShowImage(false)} /> ) - } else if (showVideo) { + } else if (showVideo && showMedia) { return